commit 9c69600a4c20229169f49adcd13f85dd07f667f8 Author: kuny Date: Thu Jul 18 14:44:32 2024 +0800 first diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..9cc84ea Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..b573bb5 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip diff --git a/dbinfodefine.xml b/dbinfodefine.xml new file mode 100644 index 0000000..98eeee3 --- /dev/null +++ b/dbinfodefine.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/defaultroledefine.xml b/defaultroledefine.xml new file mode 100644 index 0000000..59413ec --- /dev/null +++ b/defaultroledefine.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/equipmenttabdefine.xml b/equipmenttabdefine.xml new file mode 100644 index 0000000..b5739e1 --- /dev/null +++ b/equipmenttabdefine.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/logs/2018-10-27_jyiot.log.zip b/logs/2018-10-27_jyiot.log.zip new file mode 100644 index 0000000..91b9f11 Binary files /dev/null and b/logs/2018-10-27_jyiot.log.zip differ diff --git a/logs/2019-01-24_jyiot.log.zip b/logs/2019-01-24_jyiot.log.zip new file mode 100644 index 0000000..7c702d2 Binary files /dev/null and b/logs/2019-01-24_jyiot.log.zip differ diff --git a/logs/2019-03-14_jyiot.log.zip b/logs/2019-03-14_jyiot.log.zip new file mode 100644 index 0000000..2552519 Binary files /dev/null and b/logs/2019-03-14_jyiot.log.zip differ diff --git a/logs/2019-10-05_jyiot.log.zip b/logs/2019-10-05_jyiot.log.zip new file mode 100644 index 0000000..e21c22e Binary files /dev/null and b/logs/2019-10-05_jyiot.log.zip differ diff --git a/logs/2019-11-05_jyiot.log.zip b/logs/2019-11-05_jyiot.log.zip new file mode 100644 index 0000000..168ca54 Binary files /dev/null and b/logs/2019-11-05_jyiot.log.zip differ diff --git a/logs/2020-02-09_jyiot.log.zip b/logs/2020-02-09_jyiot.log.zip new file mode 100644 index 0000000..e1e7441 Binary files /dev/null and b/logs/2020-02-09_jyiot.log.zip differ diff --git a/logs/2020-08-08_jyiot.log.zip b/logs/2020-08-08_jyiot.log.zip new file mode 100644 index 0000000..c81c674 Binary files /dev/null and b/logs/2020-08-08_jyiot.log.zip differ diff --git a/logs/2020-08-11_jyiot.log.zip b/logs/2020-08-11_jyiot.log.zip new file mode 100644 index 0000000..558f103 Binary files /dev/null and b/logs/2020-08-11_jyiot.log.zip differ diff --git a/logs/2020-08-12_jyiot.log.zip b/logs/2020-08-12_jyiot.log.zip new file mode 100644 index 0000000..2fb3bb9 Binary files /dev/null and b/logs/2020-08-12_jyiot.log.zip differ diff --git a/logs/2020-08-14_jyiot.log.zip b/logs/2020-08-14_jyiot.log.zip new file mode 100644 index 0000000..a492488 Binary files /dev/null and b/logs/2020-08-14_jyiot.log.zip differ diff --git a/logs/2020-08-19_jyiot.log.zip b/logs/2020-08-19_jyiot.log.zip new file mode 100644 index 0000000..cf6f3da Binary files /dev/null and b/logs/2020-08-19_jyiot.log.zip differ diff --git a/logs/2020-08-21_jyiot.log.zip b/logs/2020-08-21_jyiot.log.zip new file mode 100644 index 0000000..b3d36ab Binary files /dev/null and b/logs/2020-08-21_jyiot.log.zip differ diff --git a/logs/2020-08-28_jyiot.log.zip b/logs/2020-08-28_jyiot.log.zip new file mode 100644 index 0000000..d9f47ef Binary files /dev/null and b/logs/2020-08-28_jyiot.log.zip differ diff --git a/logs/2021-03-27_jyiot.log.zip b/logs/2021-03-27_jyiot.log.zip new file mode 100644 index 0000000..ee92a84 Binary files /dev/null and b/logs/2021-03-27_jyiot.log.zip differ diff --git a/logs/2021-12-28_jyiot.log.zip b/logs/2021-12-28_jyiot.log.zip new file mode 100644 index 0000000..965e743 Binary files /dev/null and b/logs/2021-12-28_jyiot.log.zip differ diff --git a/logs/log_jyiot.log b/logs/log_jyiot.log new file mode 100644 index 0000000..f6e9abd --- /dev/null +++ b/logs/log_jyiot.log @@ -0,0 +1,3 @@ +2022-01-17 21:33:06.633 [main] INFO c.j.i.f.FirestationportApplication - Starting FirestationportApplication on DESKTOP-MEEEFKF with PID 20696 (D:\javaee\projects\microstation\target\classes started by 86709 in D:\javaee\projects\microstation) +2022-01-17 21:33:06.671 [main] DEBUG c.j.i.f.FirestationportApplication - Running with Spring Boot v2.0.3.RELEASE, Spring v5.0.7.RELEASE +2022-01-17 21:33:06.674 [main] INFO c.j.i.f.FirestationportApplication - No active profile set, falling back to default profiles: default diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/mvnw @@ -0,0 +1,225 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 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 Migwn, 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)`" + # TODO classpath? +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 + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +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 + +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 "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@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 http://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 Maven2 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 key stroke 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 enable echoing my 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 + +%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% diff --git a/out/artifacts/microstation_jar/microstation-0.0.1-SNAPSHOT.jar b/out/artifacts/microstation_jar/microstation-0.0.1-SNAPSHOT.jar new file mode 100644 index 0000000..b218240 Binary files /dev/null and b/out/artifacts/microstation_jar/microstation-0.0.1-SNAPSHOT.jar differ diff --git a/out/artifacts/microstation_jar/microstation.jar b/out/artifacts/microstation_jar/microstation.jar new file mode 100644 index 0000000..51951db Binary files /dev/null and b/out/artifacts/microstation_jar/microstation.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..09d5ab9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,237 @@ + + + 4.0.0 + + com.jingyi.iotserver + microstation + 0.0.1-SNAPSHOT + jar + + microstation + micro station system http port + + + org.springframework.boot + spring-boot-starter-parent + 2.0.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + org.springframework.boot + spring-boot-starter-web-services + + + org.springframework.boot + spring-boot-starter-websocket + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.2 + + + + com.microsoft.sqlserver + mssql-jdbc + runtime + + + + + mysql + mysql-connector-java + 8.0.13 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.alibaba + druid-spring-boot-starter + 1.1.10 + + + + + javax.xml.bind + jaxb-api + 2.3.0 + + + + + com.alibaba + dubbo + 2.6.2 + + + + + dom4j + dom4j + 1.6.1 + + + xml-apis + xml-apis + + + + + + + org.apache.httpcomponents + httpclient + 4.5.6 + + + + + io.jsonwebtoken + jjwt + 0.9.1 + + + + org.apache.commons + commons-lang3 + 3.3.2 + + + + + org.apache.shiro + shiro-spring + 1.4.0 + + + + org.apache.shiro + shiro-ehcache + 1.4.0 + + + + + org.springframework.boot + spring-boot-starter-actuator + 2.0.4.RELEASE + + + + + + org.apache.poi + poi + 4.0.0 + + + + + cn.jpush.api + jpush-client + 3.3.10 + + + + + io.netty + netty-all + 4.1.24.Final + + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + 1.2.0 + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + com.alibaba.fastjson2 + fastjson2 + 2.0.20 + + + + org.springframework.boot + spring-boot-starter-quartz + 2.7.8 + + + + com.squareup.okhttp3 + okhttp + 3.6.0 + + + + com.hikvision.ga + artemis-http-client + 1.1.3 + + + + org.gavaghan + geodesy + 1.1.3 + + + + cn.hutool + hutool-all + 5.8.25 + + + org.projectlombok + lombok + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.0.2 + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + diff --git a/resinfodfine.xml b/resinfodfine.xml new file mode 100644 index 0000000..ce78916 --- /dev/null +++ b/resinfodfine.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rollcallreport-2018-11-20-11-07-43.xls b/rollcallreport-2018-11-20-11-07-43.xls new file mode 100644 index 0000000..9dfae90 Binary files /dev/null and b/rollcallreport-2018-11-20-11-07-43.xls differ diff --git a/rollcallreport-2018-11-21-11-24-48.xls b/rollcallreport-2018-11-21-11-24-48.xls new file mode 100644 index 0000000..6463631 Binary files /dev/null and b/rollcallreport-2018-11-21-11-24-48.xls differ diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/ClientLoginController.java b/src/main/java/com/jingyi/iotserver/clientmanage/ClientLoginController.java new file mode 100644 index 0000000..e335245 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/ClientLoginController.java @@ -0,0 +1,1549 @@ +package com.jingyi.iotserver.clientmanage; + +import com.fasterxml.jackson.databind.JsonNode; + +import com.jingyi.iotserver.clientmanage.model.*; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; + +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.utils.*; + +import org.apache.http.Consts; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; + +//https://blog.csdn.net/huang906391/article/details/78376766 +//https://blog.csdn.net/likeyjs/article/details/80525042 + +//https://www.jianshu.com/p/43c97352aa1e + + +//httpsession https://www.cnblogs.com/diewufeixian/p/4221747.html +//httpsession https://www.cnblogs.com/zhaoYuQing-java2015/p/4621384.html + +@RestController +@CrossOrigin +public class ClientLoginController { + @Autowired + private DataSource dataSource; + + @Autowired + private UserService userService; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + private final Logger logger = LoggerFactory.getLogger(ClientLoginController.class); + + private ConcurrentHashMap mLoginRecords = new ConcurrentHashMap(); + @RequestMapping(value="/common/client/exit",method = RequestMethod.GET) + public RespEntity sysExit(HttpServletRequest request) { + System.exit(0); + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/common/client/user/login",method = RequestMethod.POST) + public RespEntity userLogin(HttpServletRequest request, HttpServletResponse response, @CookieValue(value = "token", required = false) String token) { + RespEntity rel = null; + try{ + String json = HttpTools.getBodyFromRequest(request); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_CMD); + } + String name = JsonHelper.getStringValue(rootnode,"name"); + String password = JsonHelper.getStringValue(rootnode,"password"); + String accounttype = JsonHelper.getStringValue(rootnode,"accounttype"); + logger.info("user "+ name + " start login"); + if(name==null){ + return new RespEntity(RespCode.USER_PWD_ERROR); + } + /* if(accounttype!=null&&accounttype.equals("firectrl")){ + return LoginToFireCtrl(name,password,request.getSession()); + } +*/ + UserInfoEntity user = UserInfoEntity.QueryUser(dataSource,name); + if(name.equals("administrator")){ + if(user==null) + user = new UserInfoEntity(); + user.setUsertype("super"); + user.setName("administrator"); + user.setScopelevel("master"); + String adminpwd = MD5Tools.md5(envConfigService.getSuperPassword()); + user.setPassword(MD5Tools.md5("firectrl"+name+adminpwd)); + } + if(user==null) + return new RespEntity(RespCode.USER_PWD_ERROR); + + String pwd = MD5Tools.md5("firectrl"+name+password); + + UserLoginRecord record = mLoginRecords.get(name); + if(record!=null){ + if(record.loginCount>=3) + { + if( record.lastLoginTime + 10*60*1000 > System.currentTimeMillis()) + { + return new RespEntity(RespCode.LOGIN_ERROR_DELAY_10MIN); + }else{ + mLoginRecords.remove(name); + record = null; + } + }else{ + if( record.lastLoginTime + 10*60*1000 <= System.currentTimeMillis()) + { + mLoginRecords.remove(name); + record = null; + } + } + } + if(!pwd.equals(user.getPassword())){ + if(record==null){ + record = new UserLoginRecord(); + record.lastLoginTime = System.currentTimeMillis(); + record.username = name; + record.loginCount = 1; + mLoginRecords.put(name,record); + }else{ + record.lastLoginTime = System.currentTimeMillis(); + record.loginCount++; + } + return new RespEntity(RespCode.USER_PWD_ERROR,"{\"count\":"+record.loginCount+"}"); + }else{ + if(record!=null){ + mLoginRecords.remove(name); + } + } + for(Map.Entry entry: mLoginRecords.entrySet()) { + UserLoginRecord r = entry.getValue(); + if(r!=null&&r.lastLoginTime+10*60*1000<=System.currentTimeMillis()) + { + mLoginRecords.remove(entry.getKey()); + } + } + String sessionid = userAuthorManager.CheckUserLoginSession(name); + if(sessionid!=null){ + WebNotifyProperty pro = new WebNotifyProperty(); + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + String scope = info.getScopelevel(); + if(scope!=null){ + if(scope.equals("brigade")) + pro.setBrigade(info.getLevelvalue()); + else if(scope.equals("borough")) + pro.setBorough(info.getLevelvalue()); + else if(scope.equals("detachment")) + pro.setDetachment(info.getLevelvalue()); + } + + clientWebsocketManager.kickOutClient(sessionid,pro); + userAuthorManager.KickOutUser(name); + sessionid = null; + } + + if(sessionid==null) + { + HttpSession session = request.getSession(); + sessionid = session.getId(); + session.setAttribute(session.getId(),name); + session.setMaxInactiveInterval(30*60); + + userAuthorManager.addNewSession(sessionid,name,user.getUsertype(),user.getUserrole(),user.getScopelevel(),user.getLevelvalue()); + } + +/* + Cookie cookie = new Cookie("session", sessionid); + cookie.setMaxAge(30 * 60);// 设置为30min + cookie.setPath("/"); + // cookie.setDomain("192.168.3.105:"); + response.addCookie(cookie); +*/ + + + LoginResultEntity result = new LoginResultEntity(); + result.setSession(sessionid); + + OrganizationInfoEntity org; + if(user.IsSuper()) { + org = new OrganizationInfoEntity(); + org.setOrgname("iotserver"); + org.setBrigade("all"); + org.setDetachment("all"); + org.setAddress("China"); + org.setCity("China"); + }else{ + org = OrganizationInfoEntity.Query(dataSource,user.getOrgname()); + } + user.setPassword(""); + result.setOrganize(org); + result.setUsertype(user.getUsertype()); + result.setScopelevel(user.getScopelevel()); + result.setLevelvalue(user.getLevelvalue()); + result.setPhone(user.getPhone()); + result.setTheme(user.getTheme()); + result.setLatitude(user.getLatitude()); + result.setLongitude(user.getLongitude()); + result.setOrgname(user.getOrgname()); + result.setHidden(user.getHidden()); + // result.setUserinfo(user); + logger.info("user "+ name + " login success"); + return new RespEntity(RespCode.SUCCESS,result); + }catch (Exception e){ + e.printStackTrace(); + } + logger.info("user login fail"); + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/common/client/user/active",method = RequestMethod.POST) + public RespEntity userHeartBeat(HttpServletRequest request) { + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/common/client/user/create",method = RequestMethod.POST) + public RespEntity userCreate(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + if(UserInfoEntity.QueryUser(dataSource,userinfo.getName())!=null){ + return new RespEntity(RespCode.EXIST); + } + userinfo.setPassword(MD5Tools.md5("firectrl"+userinfo.getName()+userinfo.getPassword())); + if(!userAuthorManager.IsSuper(request)) { + if(!userAuthorManager.IsAdmin(request)) + return new RespEntity(RespCode.NOAUTHOR); + if(userinfo.getUsertype()!=null&&!userinfo.getUsertype().equals("common")) + return new RespEntity(RespCode.NOAUTHOR); + userinfo.setUsertype("common"); + } + if(userinfo.getUsertype()==null||userinfo.getUsertype().length()<=0) + userinfo.setUsertype("common"); + + if(userinfo.Insert(dataSource)) { + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "USER", + "创建用户", JsonHelper.convertObjectToStr(userinfo), 0); + return new RespEntity(RespCode.SUCCESS); + }else{ + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "USER", + "创建用户", JsonHelper.convertObjectToStr(userinfo), -1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/createwithlocate",method = RequestMethod.POST) + public RespEntity userCreateWithLocate(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + if(UserInfoEntity.QueryUser(dataSource,userinfo.getName())!=null){ + return new RespEntity(RespCode.EXIST); + } + userinfo.setPassword(MD5Tools.md5("firectrl"+userinfo.getName()+userinfo.getPassword())); + if(!userAuthorManager.IsSuper(request)) { + if(!userAuthorManager.IsAdmin(request)) + return new RespEntity(RespCode.NOAUTHOR); + if(userinfo.getUsertype()!=null&&!userinfo.getUsertype().equals("common")) + return new RespEntity(RespCode.NOAUTHOR); + userinfo.setUsertype("common"); + } + if(userinfo.getUsertype()==null||userinfo.getUsertype().length()<=0) + userinfo.setUsertype("common"); + + JsonNode rootnode = (JsonNode)param; + if(rootnode!=null){ + try { + double longitude = JsonHelper.getDoubleValue(rootnode, "longitude"); + double latitude = JsonHelper.getDoubleValue(rootnode, "latitude"); + + OrganizationInfoEntity org = OrganizationInfoEntity.Query(dataSource, userinfo.getName()); + if (org == null) { + org = new OrganizationInfoEntity(); + org.setOrgname(userinfo.getName()); + org.setLongitude(longitude); + org.setLatitude(latitude); + org.Insert(dataSource); + } else { + org.setLongitude(longitude); + org.setLatitude(latitude); + org.Update(dataSource); + } + }catch (Exception e){ + + } + } + userinfo.setOrgname(userinfo.getName()); + if(userinfo.Insert(dataSource)) { + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "USER", + "创建用户", JsonHelper.convertObjectToStr(userinfo), 0); + return new RespEntity(RespCode.SUCCESS); + }else{ + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "USER", + "创建用户", JsonHelper.convertObjectToStr(userinfo), -1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/delete",method = RequestMethod.POST) + public RespEntity userDelete(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + if(UserInfoEntity.QueryUser(dataSource,userinfo.getName())==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(!userAuthorManager.IsSuper(request)) { + if (userinfo.IsAdmin() || userinfo.IsSuper()) + return new RespEntity(RespCode.NOAUTHOR); + }else{ + if (userinfo.IsSuper()) + return new RespEntity(RespCode.NOAUTHOR); + } + if(userinfo.Delete(dataSource)) { + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_DELETE, "USER", + "删除用户", JsonHelper.convertObjectToStr(userinfo), 0); + return new RespEntity(RespCode.SUCCESS); + }else{ + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_DELETE, "USER", + "删除用户", JsonHelper.convertObjectToStr(userinfo), -1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getuserlist",method = RequestMethod.POST) + public RespEntity queryUserList(HttpServletRequest request) { + try { + UserInfoEntity admin = null; + UserInfoEntity qu = new UserInfoEntity(); + List list = qu.queryList(dataSource,null,null); + for (SQLDataObject ob : list) { + UserInfoEntity user = (UserInfoEntity)ob; + if (user != null) { + user.setPassword(""); + user.setAuthority(""); + if(admin==null) { + + if(user.getName().equals("administrator")) + admin = user; + } + } + + } + list.remove(admin); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/resetpwd",method = RequestMethod.POST) + public RespEntity resetPassword(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + if(UserInfoEntity.QueryUser(dataSource,userinfo.getName())==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(!userAuthorManager.IsSuper(request)) { + if (userinfo.IsAdmin() || userinfo.IsSuper()) + return new RespEntity(RespCode.NOAUTHOR); + }else{ + if (userinfo.IsSuper()) + return new RespEntity(RespCode.NOAUTHOR); + } + + String password = MD5Tools.md5("123456"); + String pwd = MD5Tools.md5("firectrl"+userinfo.getName()+password); + userinfo.setPassword(pwd); + userinfo.setAuthority(null); + userinfo.setOrgname(null); + if(userinfo.Update(dataSource)) { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_RESET_PWD,"USER", + "重置密码",JsonHelper.convertObjectToStr(userinfo),0); + return new RespEntity(RespCode.SUCCESS); + }else{ + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_RESET_PWD,"USER", + "重置密码",JsonHelper.convertObjectToStr(userinfo),-1); + return new RespEntity(RespCode.FAIL); + } + + } + + + }); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/changepwd",method = RequestMethod.POST) + public RespEntity changePassword(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + if(UserInfoEntity.QueryUser(dataSource,userinfo.getName())==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(!userAuthorManager.IsSelf(request,userinfo.getName())) + return new RespEntity(RespCode.NOAUTHOR); + + JsonNode rootnode=(JsonNode)param; + if(rootnode==null) + return new RespEntity(RespCode.USER_PWD_ERROR); + UserInfoEntity oldinfo = UserInfoEntity.QueryUser(dataSource,userinfo.getName()); + String inputoldpwd = JsonHelper.getStringValue(rootnode,"oldpassword"); + if(oldinfo==null) + return new RespEntity(RespCode.NOTEXIST); + String oldpwd = MD5Tools.md5("firectrl"+userinfo.getName()+inputoldpwd); + if(!oldpwd.equals(oldinfo.getPassword())) + return new RespEntity(RespCode.USER_PWD_ERROR); + + String password = userinfo.getPassword(); + if(password==null) + password = ""; + String pwd = MD5Tools.md5("firectrl"+userinfo.getName()+password); + userinfo.setPassword(pwd); + userinfo.setAuthority(null); + userinfo.setOrgname(null); + if(userinfo.Update(dataSource)) { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CHANGE_PWD,"USER", + "修改密码",JsonHelper.convertObjectToStr(userinfo),0); + return new RespEntity(RespCode.SUCCESS); + }else{ + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CHANGE_PWD,"USER", + "修改密码",JsonHelper.convertObjectToStr(userinfo),-1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/update",method = RequestMethod.POST) + public RespEntity updateUserInfo(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + if(UserInfoEntity.QueryUser(dataSource,userinfo.getName())==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + userinfo.setPassword(null); + if(userinfo.Update(dataSource)) { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CHANGE_PWD,"USER", + "更新用户信息",JsonHelper.convertObjectToStr(userinfo),0); + return new RespEntity(RespCode.SUCCESS, userinfo); + }else{ + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CHANGE_PWD,"USER", + "更新用户信息",JsonHelper.convertObjectToStr(userinfo),-1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getuserinfo",method = RequestMethod.POST) + public RespEntity getUserInfo(HttpServletRequest request) { + RespEntity rel = executeOperateOnUser(request, new IUserOperate() { + @Override + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param) { + UserInfoEntity userDB = UserInfoEntity.QueryUser(dataSource,userinfo.getName()); + if(userDB == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + userDB.setPassword(null); + return new RespEntity(RespCode.SUCCESS, userDB); + } + }); + return rel; + } + + private RespEntity executeOperateOnUser(HttpServletRequest request,IUserOperate op) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + UserInfoEntity userinfo = (UserInfoEntity)SQLTools.getEntityFromJson(rootnode,UserInfoEntity.class); + if(userinfo==null||userinfo.getName()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + return op.ExecuteOperate(userinfo,rootnode); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/authordes/set",method = RequestMethod.POST) + public RespEntity setUserAuthordes(HttpServletRequest request) { + RespEntity rel; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + UserAuthorDesEntity author = (UserAuthorDesEntity)SQLTools.getEntityFromJson(rootnode,UserAuthorDesEntity.class); + if(author==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(author.QueryIt(dataSource)!=null){ + if(author.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + }else{ + if(author.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/authordes/get",method = RequestMethod.POST) + public RespEntity getUserAuthordes(HttpServletRequest request) { + RespEntity rel; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + UserAuthorDesEntity author = (UserAuthorDesEntity)SQLTools.getEntityFromJson(rootnode,UserAuthorDesEntity.class); + if(author==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + author = (UserAuthorDesEntity)author.QueryIt(dataSource); + return new RespEntity(RespCode.SUCCESS,author); + + } + + @ResponseBody + @RequestMapping(value="/common/client/user/addorganization",method = RequestMethod.POST) + public RespEntity addOrganization(HttpServletRequest request) { + RespEntity rel = executeOperateOnOrg(request, new IOrganizationOperate() { + @Override + public RespEntity ExecuteOperate(OrganizationInfoEntity org, Object param) { + OrganizationInfoEntity orginfo = OrganizationInfoEntity.Query(dataSource,org.getOrgname()); + if(orginfo!=null) + return new RespEntity(RespCode.EXIST); + + if(org.Insert(dataSource)) + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"ORGANIZATION", + "添加组织",JsonHelper.convertObjectToStr(org),0); + return new RespEntity(RespCode.SUCCESS); + } + else + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"ORGANIZATION", + "添加组织",JsonHelper.convertObjectToStr(org),-1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/deleteorganization",method = RequestMethod.POST) + public RespEntity deleteOrganization(HttpServletRequest request) { + RespEntity rel = executeOperateOnOrg(request, new IOrganizationOperate() { + @Override + public RespEntity ExecuteOperate(OrganizationInfoEntity org, Object param) { + UserInfoEntity user = new UserInfoEntity(); + user.setOrgname(org.getOrgname()); + List list = user.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + return new RespEntity(RespCode.NOTEMPTY); + if(org.Delete(dataSource)) + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"ORGANIZATION", + "删除组织",JsonHelper.convertObjectToStr(org),0); + return new RespEntity(RespCode.SUCCESS); + } + else + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"ORGANIZATION", + "删除组织",JsonHelper.convertObjectToStr(org),-1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/updateorganization",method = RequestMethod.POST) + public RespEntity updateOrganization(HttpServletRequest request) { + RespEntity rel = executeOperateOnOrg(request, new IOrganizationOperate() { + @Override + public RespEntity ExecuteOperate(OrganizationInfoEntity org, Object param) { + OrganizationInfoEntity orginfo = OrganizationInfoEntity.Query(dataSource,org.getOrgname()); + if(orginfo==null) + return new RespEntity(RespCode.NOTEXIST); + InfoChange chg = new InfoChange(); + chg.setOldinfo(orginfo); + chg.setNewinfo(org); + if(org.Update(dataSource)) + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ORGANIZATION", + "更新组织信息",JsonHelper.convertObjectToStr(chg),0); + return new RespEntity(RespCode.SUCCESS); + } + else + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ORGANIZATION", + "更新组织信息",JsonHelper.convertObjectToStr(chg),-1); + return new RespEntity(RespCode.FAIL); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getorganization",method = RequestMethod.POST) + public RespEntity getOrganization(HttpServletRequest request) { + RespEntity rel = executeOperateOnOrg(request, new IOrganizationOperate() { + @Override + public RespEntity ExecuteOperate(OrganizationInfoEntity org, Object param) { + OrganizationInfoEntity orginfo = OrganizationInfoEntity.Query(dataSource,org.getOrgname()); + if(orginfo!=null) + return new RespEntity(RespCode.SUCCESS,orginfo); + else + { + return new RespEntity(RespCode.NOTEXIST); + } + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getorganizationlist",method = RequestMethod.POST) + public RespEntity getOrganizationList(HttpServletRequest request) { + + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + OrganizationInfoEntity org = (OrganizationInfoEntity)SQLTools.getEntityFromJson(rootnode,OrganizationInfoEntity.class); + if(org==null) + { + org = new OrganizationInfoEntity(); + } + + OrganizationInfoEntity or = new OrganizationInfoEntity(); + List list = or.queryList(dataSource,null,null); + + if(org.getBrigade()==null&&org.getBorough()==null&&org.getDetachment()==null) + return new RespEntity(RespCode.SUCCESS,list); + + ArrayList rellist = new ArrayList(); + for(SQLDataObject ob:list){ + OrganizationInfoEntity to = (OrganizationInfoEntity)ob; + if(to==null) + continue; + + if(to.getDetachment()!=null){ + DetachmentEntity d = new DetachmentEntity(); + d.setDetachment(to.getDetachment()); + d = (DetachmentEntity)d.QueryIt(dataSource); + if(d!=null){ + if(d.getBrigade()!=null) + to.setBrigade(d.getBrigade()); + if(d.getBorough()!=null) + to.setBorough(d.getBorough()); + } + }else if(to.getBorough()!=null){ + BoroughEntity b = new BoroughEntity(); + b.setBorough(to.getBorough()); + b = (BoroughEntity)b.QueryIt(dataSource); + if(b!=null){ + if(b.getBrigade()!=null) + to.setBrigade(b.getBrigade()); + } + + } + + if(org.getBrigade()!=null&&!org.getBrigade().equals(to.getBrigade())) + continue; + + if(org.getBorough()!=null&&!org.getBorough().equals(to.getBorough())) + continue; + + if(org.getDetachment()!=null&&!org.getDetachment().equals(to.getDetachment())) + continue; + + rellist.add(to); + } + + return new RespEntity(RespCode.SUCCESS,rellist); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + private RespEntity executeOperateOnOrg(HttpServletRequest request,IOrganizationOperate op) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + OrganizationInfoEntity org = (OrganizationInfoEntity)SQLTools.getEntityFromJson(rootnode,OrganizationInfoEntity.class); + if(org==null||org.getOrgname()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + return op.ExecuteOperate(org,rootnode); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/createrole",method = RequestMethod.POST) + public RespEntity createRole(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RoleEntity role = (RoleEntity)SQLTools.getEntityFromJson(rootnode,RoleEntity.class); + + if(role==null||role.getRolename()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + JsonNode authjson = JsonHelper.getLevel2(rootnode,"data"); + List list = SQLTools.getEntityListFromJsonArray(authjson, AuthorityEntity.class); + + if(userService.createRole(role,list)){ + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"ROLE", + "创建角色",JsonHelper.convertObjectToStr(role),0); + return new RespEntity(RespCode.SUCCESS); + }else + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"ROLE", + "创建角色",JsonHelper.convertObjectToStr(role),-1); + return new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/deleterole",method = RequestMethod.POST) + public RespEntity deleteRole(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RoleEntity role = (RoleEntity)SQLTools.getEntityFromJson(rootnode,RoleEntity.class); + if(role==null||role.getRolename()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + rel = userService.deleteRole(role); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"ROLE", + "删除角色",JsonHelper.convertObjectToStr(role),rel.getCode()); + return rel; + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getroles",method = RequestMethod.POST) + public RespEntity queryRole(HttpServletRequest request) { + RespEntity rel = null; + try { + RoleEntity role = new RoleEntity(); + List list = role.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getroleauthority",method = RequestMethod.POST) + public RespEntity queryRoleAuthotity(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String role = JsonHelper.getStringValue(rootnode,"rolename"); + if(role==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + RoleEntity r = RoleEntity.Query(dataSource,role); + if(r!=null){ + AuthorityEntity ath = new AuthorityEntity(); + ath.extendName("" + r.getId()); + List list = ath.queryList(dataSource,null,null); + if(list!=null){ + return new RespEntity(RespCode.SUCCESS,list); + }else + return new RespEntity(RespCode.FAIL); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getallauthority",method = RequestMethod.POST) + public RespEntity queryAllAuthotity(HttpServletRequest request) { + RespEntity rel = null; + try { + List list = userService.queryAllAuthoriy(); + + if(list!=null){ + return new RespEntity(RespCode.SUCCESS,list); + }else + return new RespEntity(RespCode.FAIL); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/common/client/user/updateroleauthority",method = RequestMethod.POST) + public RespEntity updateRoleAuthotity(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String role = JsonHelper.getStringValue(rootnode,"rolename"); + if(role==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + JsonNode authjson = JsonHelper.getLevel2(rootnode,"data"); + List list = SQLTools.getEntityListFromJsonArray(authjson,AuthorityEntity.class); + PropertyChange chg = new PropertyChange(); + chg.setOwner(role); + chg.setNewpro(list); + if(userService.updateRoleAuthoriy(role,list)){ + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ROLE-AUTHORITY", + "更新角色权限",JsonHelper.convertObjectToStr(chg),0); + return new RespEntity(RespCode.SUCCESS); + }else + { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ROLE-AUTHORITY", + "更新角色权限",JsonHelper.convertObjectToStr(chg),-1); + return new RespEntity(RespCode.FAIL); + } + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value = "/common/client/user/saveoperate", method = RequestMethod.POST) + public RespEntity saveUserOperate(HttpServletRequest request) { + + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String username = JsonHelper.getStringValue(rootnode,"username"); + String operate = JsonHelper.getStringValue(rootnode,"operate"); + String objective = JsonHelper.getStringValue(rootnode,"objective"); + String content = JsonHelper.getStringValue(rootnode,"content"); + String detail = JsonHelper.getStringValue(rootnode,"detail"); + int result = JsonHelper.getIntValue(rootnode,"result"); + + + try { + if(username==null||username.length()<=0) { + userAuthorManager.AddUserOperate(request,operate, objective, + content, detail, result); + }else{ + userAuthorManager.AddUserOperate(username,operate, objective, + content, detail, result); + } + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value = "/common/client/user/getoperatecount", method = RequestMethod.POST) + public RespEntity getUserOperateCount(HttpServletRequest request) { + + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + OperatingRecordEntity operate = (OperatingRecordEntity)SQLTools.getEntityFromJson(rootnode,OperatingRecordEntity.class); + if(operate==null) + return new RespEntity(RespCode.ERROR_CMD); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + try { + int count = operate.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value = "/common/client/user/getoperatelist", method = RequestMethod.POST) + public RespEntity getUserOperateList(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + OperatingRecordEntity operate = (OperatingRecordEntity)SQLTools.getEntityFromJson(rootnode,OperatingRecordEntity.class); + if(operate==null) + return new RespEntity(RespCode.ERROR_CMD); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + try { + List list = operate.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/adddetachment",method = RequestMethod.POST) + public RespEntity addDetachment(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + DetachmentEntity detachment = (DetachmentEntity)SQLTools.getEntityFromJson(rootnode,DetachmentEntity.class); + if(detachment==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if(detachment.QueryIt(dataSource)!=null) + rel = new RespEntity(RespCode.EXIST); + else{ + if(detachment.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"DETACHMENT", + "添加中队",JsonHelper.convertObjectToStr(detachment),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getdetachment",method = RequestMethod.POST) + public RespEntity queryDetachment(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + DetachmentEntity detachment = (DetachmentEntity)SQLTools.getEntityFromJson(rootnode,DetachmentEntity.class); + List list = detachment.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + rel = new RespEntity(RespCode.SUCCESS,list); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getdetachmentofmultiborough",method = RequestMethod.POST) + public RespEntity queryDetachmentOfMultiBorough(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + if(rootnode==null||!rootnode.isArray()||rootnode.size()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + List result = new ArrayList(); + DetachmentEntity detachment = new DetachmentEntity(); + for(int i=0;i list = detachment.queryList(dataSource,null,null); + if(list!=null) + result.addAll(list); + }catch (Exception e){ + + } + } + + if(result!=null&&result.size()>0) + rel = new RespEntity(RespCode.SUCCESS,result); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/deletedetachment",method = RequestMethod.POST) + public RespEntity deleteDetachment(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + DetachmentEntity detachment = (DetachmentEntity)SQLTools.getEntityFromJson(rootnode,DetachmentEntity.class); + if(detachment==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(detachment.QueryIt(dataSource)==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(detachment.Delete(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"DETACHMENT", + "删除中队",JsonHelper.convertObjectToStr(detachment),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/updatedetachment",method = RequestMethod.POST) + public RespEntity updateDetachment(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + DetachmentEntity detachment = (DetachmentEntity)SQLTools.getEntityFromJson(rootnode,DetachmentEntity.class); + if(detachment==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if(detachment.QueryIt(dataSource)==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(detachment.Update(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"DETACHMENT", + "更新中队信息",JsonHelper.convertObjectToStr(detachment),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/addborough",method = RequestMethod.POST) + public RespEntity addBorough(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + BoroughEntity borough = (BoroughEntity)SQLTools.getEntityFromJson(rootnode,BoroughEntity.class); + if(borough==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if(borough.QueryIt(dataSource)!=null) + rel = new RespEntity(RespCode.EXIST); + else{ + if(borough.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"BOROUGH", + "添加大队",JsonHelper.convertObjectToStr(borough),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getborough",method = RequestMethod.POST) + public RespEntity queryBorough(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughEntity borough = (BoroughEntity)SQLTools.getEntityFromJson(rootnode,BoroughEntity.class); + List list = borough.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + rel = new RespEntity(RespCode.SUCCESS,list); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getboroughofmultibrigade",method = RequestMethod.POST) + public RespEntity queryBoroughOfMultiBrigade(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + if(rootnode==null||!rootnode.isArray()||rootnode.size()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + List result = new ArrayList(); + for(int i=0;i list = borough.queryList(dataSource,null,null); + if(list!=null) + result.addAll(list); + }catch (Exception e){ + + } + } + + if(result!=null&&result.size()>0) + rel = new RespEntity(RespCode.SUCCESS,result); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/deleteborough",method = RequestMethod.POST) + public RespEntity deleteBorough(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + BoroughEntity borough = (BoroughEntity)SQLTools.getEntityFromJson(rootnode,BoroughEntity.class); + if(borough==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if(borough.QueryIt(dataSource)==null) + rel = new RespEntity(RespCode.NOTEXIST); + else { + if(borough.Delete(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"BOROUGH", + "删除大队",JsonHelper.convertObjectToStr(borough),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/updateborough",method = RequestMethod.POST) + public RespEntity updateBorough(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + BoroughEntity borough = (BoroughEntity)SQLTools.getEntityFromJson(rootnode,BoroughEntity.class); + if(borough==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if( borough.QueryIt(dataSource)==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(borough.Update(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"BOROUGH", + "更新大队信息",JsonHelper.convertObjectToStr(borough),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/addbrigade",method = RequestMethod.POST) + public RespEntity addBrigade(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + BrigadeEntity brigade = (BrigadeEntity)SQLTools.getEntityFromJson(rootnode,BrigadeEntity.class); + if(brigade==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else { + if(brigade.QueryIt(dataSource)!=null){ + rel = new RespEntity(RespCode.EXIST); + }else { + if (brigade.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + } else { + rel = new RespEntity(RespCode.FAIL); + } + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"BRIGADE", + "添加支队",JsonHelper.convertObjectToStr(brigade),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/getbrigade",method = RequestMethod.POST) + public RespEntity queryBrigade(HttpServletRequest request) { + RespEntity rel = null; + try { + BrigadeEntity brigade = null; + try{ + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + brigade = (BrigadeEntity) SQLTools.getEntityFromJson(rootnode, BrigadeEntity.class); + } + }catch (Exception ee) { + + } + if(brigade==null) + brigade = new BrigadeEntity(); + List list = brigade.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + rel = new RespEntity(RespCode.SUCCESS,list); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/user/deletebrigade",method = RequestMethod.POST) + public RespEntity deleteBrigade(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + BrigadeEntity brigade = (BrigadeEntity)SQLTools.getEntityFromJson(rootnode,BrigadeEntity.class); + if(brigade==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else { + if(brigade.QueryIt(dataSource)==null){ + rel = new RespEntity(RespCode.NOTEXIST); + }else { + if (brigade.Delete(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"BRIGADE", + "删除支队",JsonHelper.convertObjectToStr(brigade),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/common/client/user/updatebrigade",method = RequestMethod.POST) + public RespEntity updateBrigade(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + BrigadeEntity brigade = (BrigadeEntity)SQLTools.getEntityFromJson(rootnode,BrigadeEntity.class); + if(brigade==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else { + if(brigade.Update(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"BRIGADE", + "更新支队信息",JsonHelper.convertObjectToStr(brigade),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/common/client/user/getuser",method = RequestMethod.POST) + public RespEntity getUserList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + OrganiztionUri orguri = (OrganiztionUri)SQLTools.getEntityFromJson(rootnode,OrganiztionUri.class); + if(orguri==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else + rel = new RespEntity(RespCode.SUCCESS,userService.queryUserList(orguri)); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/common/client/partner/create",method = RequestMethod.POST) + public RespEntity partnerCreate(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + ThirdPlatformInfoEntity partner = (ThirdPlatformInfoEntity)SQLTools.getEntityFromJson(rootnode,ThirdPlatformInfoEntity.class); + if(partner==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + + partner.setAppkey(GUIDUtil.GenreralScerect(GUIDUtil.GeneralAppkey())); + partner.setCreatetime(new Date()); + if(partner.Insert(dataSource)){ + rel = new RespEntity(RespCode.SUCCESS,partner); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/partner/getlist",method = RequestMethod.POST) + public RespEntity getPartnerList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + ThirdPlatformInfoEntity partner = (ThirdPlatformInfoEntity)SQLTools.getEntityFromJson(rootnode,ThirdPlatformInfoEntity.class); + if(partner==null) + partner = new ThirdPlatformInfoEntity(); + + List list = partner.queryPage(dataSource,null,null,0,1000); + rel = new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/common/client/partner/update",method = RequestMethod.POST) + public RespEntity partnerUpdate(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + ThirdPlatformInfoEntity partner = (ThirdPlatformInfoEntity)SQLTools.getEntityFromJson(rootnode,ThirdPlatformInfoEntity.class); + if(partner==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + + if(ThirdPlatformInfoEntity.Query(dataSource,partner.getAppkey())==null) + return new RespEntity(RespCode.NOTEXIST); + + + if(partner.Update(dataSource)){ + rel = new RespEntity(RespCode.SUCCESS,partner); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/ClientRuningInfo.java b/src/main/java/com/jingyi/iotserver/clientmanage/ClientRuningInfo.java new file mode 100644 index 0000000..eb33a3c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/ClientRuningInfo.java @@ -0,0 +1,90 @@ +package com.jingyi.iotserver.clientmanage; + +import java.util.ArrayList; +import java.util.List; + +public class ClientRuningInfo { + private String name; + private String usertype; + private long mLastActTime; + private long mTimeOut; + private String sessionid; + private String scopelevel; + private String levelvalue; + private List roles = new ArrayList(); + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setUsertype(String usertype) { + this.usertype = usertype; + } + + public String getUsertype() { + return usertype; + } + + public long getmLastActTime() { + return mLastActTime; + } + + public void setmLastActTime(long mLastActTime) { + this.mLastActTime = mLastActTime; + } + + public String getSessionid() { + return sessionid; + } + + public void setSessionid(String sessionid) { + this.sessionid = sessionid; + } + + public void setmTimeOut(long mTimeOut) { + this.mTimeOut = mTimeOut; + } + + public long getmTimeOut() { + return mTimeOut; + } + + public void setScopelevel(String scopelevel) { + this.scopelevel = scopelevel; + } + + public String getScopelevel() { + return scopelevel; + } + + public void setLevelvalue(String levelvalue) { + this.levelvalue = levelvalue; + } + + public String getLevelvalue() { + return levelvalue; + } + + public void addRole(String rolename){ + roles.add(rolename); + } + + + public ListgetRoles(){ + return roles; + } + public boolean CheckActive(){ + long cur = System.currentTimeMillis(); + if(cur-mLastActTime>=mTimeOut) + return false; + return true; + } + + public void UpdateActive(){ + mLastActTime = System.currentTimeMillis(); + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/IOTCommonCallAppInf.java b/src/main/java/com/jingyi/iotserver/clientmanage/IOTCommonCallAppInf.java new file mode 100644 index 0000000..a713f2e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/IOTCommonCallAppInf.java @@ -0,0 +1,11 @@ +package com.jingyi.iotserver.clientmanage; + +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.clientmanage.model.BrigadeEntity; +import com.jingyi.iotserver.clientmanage.model.DetachmentEntity; + +public interface IOTCommonCallAppInf { + public boolean PrepareDeleteBrigade(BrigadeEntity brigade); + public boolean PrepareDeleteBorough(BoroughEntity borough); + public boolean PrepareDeleteDetachment(DetachmentEntity detachment); +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/IOrganizationOperate.java b/src/main/java/com/jingyi/iotserver/clientmanage/IOrganizationOperate.java new file mode 100644 index 0000000..65adacd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/IOrganizationOperate.java @@ -0,0 +1,8 @@ +package com.jingyi.iotserver.clientmanage; + +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.clientmanage.model.OrganizationInfoEntity; + +public interface IOrganizationOperate { + public RespEntity ExecuteOperate(OrganizationInfoEntity org, Object param); +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/IUserOperate.java b/src/main/java/com/jingyi/iotserver/clientmanage/IUserOperate.java new file mode 100644 index 0000000..4ef79b1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/IUserOperate.java @@ -0,0 +1,8 @@ +package com.jingyi.iotserver.clientmanage; + +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.clientmanage.model.UserInfoEntity; + +public interface IUserOperate { + public RespEntity ExecuteOperate(UserInfoEntity userinfo, Object param); +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/InterceptorConfig.java b/src/main/java/com/jingyi/iotserver/clientmanage/InterceptorConfig.java new file mode 100644 index 0000000..2a5bb2f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/InterceptorConfig.java @@ -0,0 +1,65 @@ +package com.jingyi.iotserver.clientmanage; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class InterceptorConfig implements WebMvcConfigurer { + @Autowired + LoginInterceptor loginInterceptor; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + InterceptorRegistration registration = registry.addInterceptor(loginInterceptor); + //addPathPatterns 用于添加拦截规则 + //excludePathPatterns用于排除拦截规则 + + registration.addPathPatterns("/common/client/**"); + registration.addPathPatterns("/firectrl/client/**"); + registration.addPathPatterns("/firectrl/partner/**"); + registration.addPathPatterns("/user/**"); + registration.excludePathPatterns("/common/client/user/login"); + registration.excludePathPatterns("/common/client/exit"); + registration.excludePathPatterns("/common/client/user/saveoperate"); + + registration.excludePathPatterns("/firectrl/file/**"); + registration.excludePathPatterns("/firectrl/partner/assign"); + registration.excludePathPatterns("/firectrl/partner/getsensorcount"); + registration.excludePathPatterns("/firectrl/partner/getsensorpage"); + registration.excludePathPatterns("/firectrl/client/isactive"); + registration.excludePathPatterns("/firectrl/client/user/login"); + registration.excludePathPatterns("/firectrl/client/user/agentlogin"); + registration.excludePathPatterns("/firectrl/client/test/db"); + registration.excludePathPatterns("/iotserver/sensor/huaxtent/earthinductor"); + registration.excludePathPatterns("/iotserver/sensor/**"); + registration.excludePathPatterns("/iotserver/alarmtask/**"); + registration.excludePathPatterns("/iotserver/pluginfo/**"); + registration.excludePathPatterns("/firectrl/client/notice/sendmqtt"); + registration.excludePathPatterns("/firectrl/client/map/**"); + +// registration.excludePathPatterns("/firectrl/client/getstationcount"); + // registration.excludePathPatterns("/firectrl/client/user/create"); + /* */ + } + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("GET", "POST", "OPTION", "PUT") + .allowedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method", + "Access-Control-Request-Headers","Authorization") + .allowCredentials(true) + .maxAge(3600); + /* +.exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials") + .allowedHeaders("*") + .exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials","sessionjy") + */ + } + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/LoginInterceptor.java b/src/main/java/com/jingyi/iotserver/clientmanage/LoginInterceptor.java new file mode 100644 index 0000000..d3855f6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/LoginInterceptor.java @@ -0,0 +1,175 @@ +package com.jingyi.iotserver.clientmanage; + + +import com.jingyi.iotserver.clientmanage.model.ThirdPlatformInfoEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import java.io.IOException; +import java.io.PrintWriter; + + +//https://www.tianmaying.com/tutorial/spring-mvc-interceptor +//https://www.jianshu.com/p/43c97352aa1e + +@Service +public class LoginInterceptor implements HandlerInterceptor { + @Autowired + UserAuthorManager userAuthorManager; + + @Autowired + private DataSource dataSource; + + private final Logger logger = LoggerFactory.getLogger(LoginInterceptor.class); + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + // System.out.println("preHandler"); + + // HttpSession session = request.getSession(); + Cookie[] cookies = request.getCookies(); + /* if(cookies==null) + { + return false; + }else{ + for(Cookie cookie : cookies){ + if(cookie.getName().equals("session")){ + String val = cookie.getValue(); + String username = (String)session.getAttribute(val); + return true; + } + } + return false; + } */ + try{ + // Thread.sleep(20); + }catch (Exception e){ + + } + String methodstr = request.getMethod(); + String uri = request.getRequestURI(); + if(methodstr.equals("OPTIONS")) + return true; + String sessionid = request.getHeader("authorization"); + + // String json = HttpTools.getBodyFromRequest(request); + // JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + /* if(rootnode==null){ + //error request + return false; + } + String sessionid = JsonHelper.getStringValue(rootnode,"session");*/ + // sessionid = MD5Tools.md5("firectrl"+"administrator"+sessionid) + + if(uri.startsWith("/firectrl/partner/")){ + String appkey = request.getHeader("appkey"); + ThirdPlatformInfoEntity platform = null; + if(appkey!=null) + platform = ThirdPlatformInfoEntity.Query(dataSource,appkey); + if(platform==null){ + platform = ThirdPlatformInfoEntity.Query(dataSource,sessionid); + }else + request.setAttribute("authorization",appkey); + if(platform==null){ + responseOutWithJson(response,"{\"code\":-301,\"msg\":\"无权限\",\"request\":0}",request.getHeader("origin")); + return false; + }else + return true; + } + + if(sessionid==null||!userAuthorManager.checkSessionActiveUpdate(sessionid)){ + responseOutWithJson(response,"{\"code\":-101,\"msg\":\"未登录\",\"request\":0}",request.getHeader("origin")); + return false; + } + + if(userAuthorManager.IsAdmin(request)||userAuthorManager.IsSuper(request)) { + logger.info(userAuthorManager.getUserName(sessionid)); + logger.info("==>"+uri); + return true; + } + if(!userAuthorManager.checkUserAuthor(sessionid,uri)){ + responseOutWithJson(response,"{\"code\":-100,\"msg\":\"无权限\",\"request\":0}",request.getHeader("origin")); + return false; + } + + logger.info(userAuthorManager.getUserName(sessionid)); + logger.info("==>"+uri); + // request.setAttribute("req-json-str",json); + // request.setAttribute("req-json-obj", rootnode); + +/* + HandlerMethod handlerMethod = (HandlerMethod) handler; + Method method = handlerMethod.getMethod(); + UserAccess access = method.getAnnotation(UserAccess.class); + if(access!=null&&access.roles().length>0){ + String username = userAuthorManager.getUserName(sessionid); + if(username==null) + return false; + boolean pass = false; + String[] roles = access.roles(); + Set roleSet = new HashSet<>(); + for (String role : roles) { + // 将角色加入一个set集合中 + roleSet.add(role); + } + + + if(roleSet.contains("administrator")){ + if(username.equals("administrator")) + pass = true; + } + + if(!pass) + return false; + } + */ + return true;//true next handler process, false + + } + + @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) + throws Exception { + // System.out.println("postHandler"); + } + + @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) + throws Exception { + // System.out.println("afterCompletion"); + } + + protected void responseOutWithJson(HttpServletResponse response, + String responseObject,String origin) { + // JsonNode rootnode = null; + // ObjectMapper mapper = new ObjectMapper(); + // mapper. + //将实体对象转换为JSON Object转换 + // JSONObject responseJSONObject = JSONObject.fromObject(responseObject); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json; charset=utf-8"); + response.setStatus(200); + response.setHeader("Access-Control-Allow-Credentials","true"); + response.setHeader("Access-Control-Allow-Origin",origin); + // response.setHeader("Transfer-Encoding","chunked"); + response.setHeader("Vary","Origin, Access-Control-Request-Method, Access-Control-Request-Headers"); + PrintWriter out = null; + try { + out = response.getWriter(); + // out.append(responseJSONObject.toString()); + out.append(responseObject); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (out != null) { + out.close(); + } + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/UserAuthorManager.java b/src/main/java/com/jingyi/iotserver/clientmanage/UserAuthorManager.java new file mode 100644 index 0000000..4453a5f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/UserAuthorManager.java @@ -0,0 +1,489 @@ +package com.jingyi.iotserver.clientmanage; + +import com.jingyi.iotserver.clientmanage.model.AuthorityEntity; +import com.jingyi.iotserver.clientmanage.model.OperatingRecordEntity; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.clientmanage.model.RoleEntity; +import com.jingyi.iotserver.utils.SQLDataObject; + +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class UserAuthorManager { + public static final String USER_OPERATE_TYPE_CREATE = "create"; + public static final String USER_OPERATE_TYPE_DELETE = "delete"; + public static final String USER_OPERATE_TYPE_UPDATE = "update"; + public static final String USER_OPERATE_TYPE_RESET_PWD = "reset_password"; + public static final String USER_OPERATE_TYPE_CHANGE_PWD = "change_password"; + public static final String USER_OPERATE_TYPE_PATCH = "patch"; + public static final String USER_OPERATE_TYPE_RUN = "run"; + public static final String USER_OPERATE_TYPE_STOP = "stop"; + public static final String USER_OPERATE_TYPE_SET = "set"; + public static final String USER_OPERATE_TYPE_VERIFY = "verify"; + + @Autowired + private DataSource dataSource; + + private Object locker = new Object(); + private HashMap mClientsMap = new HashMap(); + private HashMap mSessionsMap = new HashMap(); + private HashMap mRoleAuthorMap = new HashMap(); + private HashMap mAnyRoleResMap = new HashMap(); + + private Thread scanservice = null; + public void Init(){ + try { + // Resource resource = new ClassPathResource("static\\dbinfodefine.xml"); + // File file = resource.getFile(); + InputStream stream = getClass().getClassLoader().getResourceAsStream("static/defaultroledefine.xml"); + File targetFile = new File("defaultroledefine.xml"); + // FileUtils.copyInputStreamToFile(stream, targetFile); + + // BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(targetFile))); + + SAXReader reader = new SAXReader(); + Document document = reader.read(new InputStreamReader(stream,"utf8")); + Element root = document.getRootElement(); + if("defaultroledefine".equals(root.getName())) { + List list = root.elements(); + for(Element el:list){ + if(el==null) + continue; + if(!"role".equals(el.getName())) + continue; + Attribute atr = el.attribute("name"); + String role = atr.getStringValue(); + RoleEntity roleEntity = new RoleEntity(); + roleEntity.setRolename(role); + try{ + roleEntity = (RoleEntity)roleEntity.QueryIt(dataSource); + }catch(Exception e){ + + } + + if(roleEntity==null){ + roleEntity = new RoleEntity(); + roleEntity.setRolename(role); + roleEntity.Insert(dataSource); + + } + + List authors = null; + try{ + AuthorityEntity aut = new AuthorityEntity(); + aut.extendName(""+roleEntity.getId()); + authors = aut.queryList(dataSource,null,null); + }catch (Exception e){ + + } + + List reses = el.elements(); + HashMap defautauth = new HashMap(); + for(Element res:reses){ + if(!"res".equals(res.getName())) + continue; + Attribute attr = res.attribute("type"); + String type = attr.getStringValue(); + attr = res.attribute("descript"); + String discript = attr.getStringValue(); + attr = res.attribute("path"); + String path = attr.getStringValue(); + if(type==null||type.length()<=0||path==null||path.length()<=0) + continue; + AuthorityEntity auth = new AuthorityEntity(); + auth.setDiscript(discript); + auth.setPath(path); + auth.setType(type); + defautauth.put(path,auth); + } + if(authors!=null){ + for(SQLDataObject ob:authors) { + AuthorityEntity auth = (AuthorityEntity) ob; + if (defautauth.get(auth.getPath()) != null) { + defautauth.remove(auth.getPath()); + } else { + auth.extendName("" + roleEntity.getId()); + auth.Delete(dataSource); + } + } + } + for(Map.Entry entry: defautauth.entrySet()){ + AuthorityEntity auth = entry.getValue(); + try { + auth.extendName("" + roleEntity.getId()); + auth.Insert(dataSource); + }catch (Exception e){ + + } + } + + } + } + }catch (Exception e){ + e.printStackTrace(); + } + LoadRoleAuthority(); + LoadAnyRoleRes(); + scanservice = new Thread(){ + public void run(){ + while(true){ + try { + CheckSessionTimeOut(); + }catch (Exception e){ + + } + try{ + Thread.sleep(5*60*1000); + }catch (Exception e){ + + } + } + } + }; + + scanservice.start(); + } + + private void LoadAnyRoleRes(){ + try { + // Resource resource = new ClassPathResource("static\\dbinfodefine.xml"); + // File file = resource.getFile(); + InputStream stream = getClass().getClassLoader().getResourceAsStream("static/resinfodefine.xml"); + File targetFile = new File("resinfodfine.xml"); + // FileUtils.copyInputStreamToFile(stream, targetFile); + + // BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(targetFile))); + + SAXReader reader = new SAXReader(); + Document document = reader.read(new InputStreamReader(stream,"utf8")); + Element root = document.getRootElement(); + if("resinfodefine".equals(root.getName())) { + List list = root.elements(); + for(Element el:list){ + if(el==null) + continue; + if(!"res".equals(el.getName())) + continue; + Attribute atr = el.attribute("scope"); + String scope = atr.getStringValue(); + + if(scope==null||!scope.equals("all")) + continue; + + atr = el.attribute("path"); + String path = atr.getStringValue(); + + atr = el.attribute("descript"); + String descript = atr.getStringValue(); + + atr = el.attribute("type"); + String type = atr.getStringValue(); + + AuthorityEntity authorityEntity = new AuthorityEntity(); + + authorityEntity.setType(type); + authorityEntity.setPath(path); + authorityEntity.setDiscript(descript); + + mAnyRoleResMap.put(path,authorityEntity); + + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + private void CheckSessionTimeOut(){ + synchronized (locker) { + for (Map.Entry entry : mSessionsMap.entrySet()) { + ClientRuningInfo info = entry.getValue(); + if (info!=null&&!info.CheckActive()) { + mClientsMap.remove(info.getName()); + mSessionsMap.remove(info.getSessionid()); + } + } + } + } + + private void LoadRoleAuthority(){ + try{ + RoleEntity r = new RoleEntity(); + List rolelist = r.queryList(dataSource,null,null); + for(SQLDataObject ob:rolelist){ + RoleEntity role = (RoleEntity)ob; + if(role!=null){ + mRoleAuthorMap.put(role.getRolename(),role); + AuthorityEntity aut = new AuthorityEntity(); + aut.extendName(""+role.getId()); + List authors = aut.queryList(dataSource,null,null); + if(authors!=null){ + for(SQLDataObject auth:authors){ + role.addAuthor((AuthorityEntity)auth); + } + } + } + } + }catch (Exception e) { + + } + } + public String CheckUserLoginSession(String username){ + synchronized (locker) { + ClientRuningInfo info = mClientsMap.get(username); + if (info == null) + return null; + if(!info.CheckActive()){ + mClientsMap.remove(info.getName()); + mSessionsMap.remove(info.getSessionid()); + return null; + }else{ + info.UpdateActive(); + return info.getSessionid(); + } + } + } + + public void KickOutUser(String username){ + synchronized (locker) { + ClientRuningInfo info = mClientsMap.get(username); + if (info == null) + return ; + mClientsMap.remove(info.getName()); + mSessionsMap.remove(info.getSessionid()); + + } + } + public boolean checkSessionActiveUpdate(String sessionid){ + synchronized (locker) { + ClientRuningInfo info = mSessionsMap.get(sessionid); + if(info==null) + return false; + if(!info.CheckActive()){ + mClientsMap.remove(info.getName()); + mSessionsMap.remove(sessionid); + return false; + }else{ + info.UpdateActive(); + } + + } + return true; + } + + public void addNewSession(String session,String username,String usertype,String role,String scopelevel ,String levelvalue){ + synchronized (locker) { + ClientRuningInfo info = new ClientRuningInfo(); + info.setName(username); + info.setUsertype(usertype); + info.setSessionid(session); + info.setScopelevel(scopelevel); + info.setLevelvalue(levelvalue); + info.setmLastActTime(System.currentTimeMillis()); + info.setmTimeOut(15*60*1000+2000); + if(role!=null){ + String[] roles = role.split("#"); + if(roles!=null&&roles.length>0){ + for(int i=0;i0){ + info.addRole(roles[i]); + } + } + } + } + mClientsMap.put(username,info); + mSessionsMap.put(session,info); + } + } + + public String getUserName(String session){ + String name = null; + synchronized (locker) { + ClientRuningInfo info = mSessionsMap.get(session); + name = info.getName(); + } + return name; + } + + public ClientRuningInfo getUserInfo(String session){ + ClientRuningInfo info = null; + synchronized (locker) { + info = mSessionsMap.get(session); + + } + return info; + } + + + public boolean checkUserAuthor(String session,String uri){ + + synchronized (locker) { + + if(mAnyRoleResMap.get(uri)!=null) + return true; + + ClientRuningInfo info = mSessionsMap.get(session); + List roles = info.getRoles(); + for(String rolename:roles){ + RoleEntity role = mRoleAuthorMap.get(rolename); + if(role.getAuthorlist().get(uri)!=null) + return true; + } + + return false; + } + } + + public boolean IsAdmin(HttpServletRequest request){ + synchronized (locker) { + String type = null; + String session = request.getHeader("authorization"); + ClientRuningInfo info = mSessionsMap.get(session); + type = info.getUsertype(); + if(type==null) + return false; + if(type.equals("admin")) + return true; + else + return false; + } + } + + public boolean IsSuper(HttpServletRequest request){ + synchronized (locker) { + String type = null; + String session = request.getHeader("authorization"); + ClientRuningInfo info = mSessionsMap.get(session); + type = info.getUsertype(); + if(type==null) + return false; + if(info.getName().equals("administrator")) + return true; + else + return false; + } + } + + public boolean IsSelf(HttpServletRequest request,String name){ + if(name==null) + return false; + synchronized (locker) { + String session = request.getHeader("authorization"); + ClientRuningInfo info = mSessionsMap.get(session); + + if(info.getName().equals(name)) + return true; + else + return false; + } + } + + public void NotifyDeleteRole(RoleEntity role){ + if(role==null) + return; + synchronized (locker) { + mRoleAuthorMap.remove(role.getRolename()); + } + } + + public void NotifyUpdateRoleAuthority(RoleEntity role){ + if(role==null) + return; + RoleEntity ra = (RoleEntity)role.QueryIt(dataSource); + if(ra==null) + return; + AuthorityEntity aut = new AuthorityEntity(); + aut.extendName(""+ra.getId()); + List authors = aut.queryList(dataSource,null,null); + if(authors!=null){ + for(SQLDataObject ob:authors){ + AuthorityEntity auth = (AuthorityEntity)ob; + role.addAuthor(auth); + } + } + + synchronized (locker) { + mRoleAuthorMap.remove(role.getRolename()); + mRoleAuthorMap.put(ra.getRolename(),ra); + } + } + + public void AddUserOperate(HttpServletRequest request,String operate,String objective,String conttent,String detail,int result){ + try { + String sessionid = request.getHeader("authorization"); + + ClientRuningInfo info = mSessionsMap.get(sessionid); + OperatingRecordEntity op = new OperatingRecordEntity(); + + op.setUsername(info.getName()); + op.setTimestamp(new Date()); + op.setOperate(operate); + op.setObjective(objective); + op.setContent(conttent); + op.setDetail(detail); + op.setResult(result); + op.Insert(dataSource); + }catch (Exception e){ + e.printStackTrace(); + } + + } + + public void AddUserOperate(String username,String operate,String objective,String content,String detail,int result){ + try { + OperatingRecordEntity op = new OperatingRecordEntity(); + + op.setUsername(username); + op.setTimestamp(new Date()); + op.setOperate(operate); + op.setObjective(objective); + op.setContent(content); + op.setDetail(detail); + op.setResult(result); + op.Insert(dataSource); + }catch (Exception e){ + e.printStackTrace(); + } + } + + public OrganiztionUri getUserScope(String sessionid){ + ClientRuningInfo info = mSessionsMap.get(sessionid); + String type = info.getUsertype(); + if(type==null) + return null; + if(info.getName().equals("administrator")) + return new OrganiztionUri(); + + OrganiztionUri uri = new OrganiztionUri(); + String level = info.getScopelevel(); + if(level==null) + return null; + if(level.equals("brigade")) + uri.setBrigade(info.getLevelvalue()); + else if(level.equals("borough")) + uri.setBorough(info.getLevelvalue()); + else if(level.equals("detachment")) + uri.setDetachment(info.getLevelvalue()); + else if(level.equals("station")) + uri.setStation(info.getLevelvalue()); + else + return null; + return uri; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/UserService.java b/src/main/java/com/jingyi/iotserver/clientmanage/UserService.java new file mode 100644 index 0000000..e0338ab --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/UserService.java @@ -0,0 +1,272 @@ +package com.jingyi.iotserver.clientmanage; + +import com.jingyi.iotserver.clientmanage.model.*; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.utils.MD5Tools; +import com.jingyi.iotserver.utils.SQLDataObject; + +import org.apache.http.util.TextUtils; +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.jingyi.iotserver.common.service.EnvConfigService; +import javax.sql.DataSource; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class UserService { + @Autowired + private DataSource dataSource; + + @Autowired + UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + private ArrayList appinfs = new ArrayList(); + public void InitService(){ + + try{ + UserInfoEntity user = new UserInfoEntity(); + user.setName("administrator"); + user = (UserInfoEntity)user.QueryIt(dataSource); + if(user==null){ + user = new UserInfoEntity(); + user.setName("administrator"); + user.setUsertype("super"); + user.setScopelevel("master"); + user.setLevelvalue(""); + String adminpwd = MD5Tools.md5(envConfigService.getSuperPassword()); + String pwd = MD5Tools.md5("firectrl"+"administrator"+adminpwd); + user.setPassword(pwd); + user.Insert(dataSource); + } + }catch (Exception e){ + + } + } + + public void RegisterAppInf(IOTCommonCallAppInf inf){ + + if(appinfs!=null) + appinfs.add(inf); + } + + public UserInfoEntity queryUserInfo(String name){ + try { + UserInfoEntity user = new UserInfoEntity(); + user.setName(name); + return (UserInfoEntity)user.QueryIt(dataSource); + }catch (Exception e){ + + } + return null; + } + + + public boolean createRole(RoleEntity role,Listlist){ + try { + if(role==null||role.QueryIt(dataSource)!=null) + return false; + if(!role.Insert(dataSource)) + return false; + if(list!=null&&list.size()>0) + { + for(AuthorityEntity auth:list){ + auth.extendName(""+role.getId()); + auth.Insert(dataSource); + } + } + userAuthorManager.NotifyUpdateRoleAuthority(role); + return true; + }catch (Exception e){ + + } + return false; + } + + public RespEntity deleteRole(RoleEntity role){ + try { + UserInfoEntity user = new UserInfoEntity(); + user.setUserrole(role.getRolename()); + List users = user.queryList(dataSource,null,null); + if(users!=null&&users.size()>0) + return new RespEntity(RespCode.NOTEMPTY); + RoleEntity r = (RoleEntity)role.QueryIt(dataSource); + if(r!=null&&r.getId()>0) { + r.Delete(dataSource); + AuthorityEntity aut = new AuthorityEntity(); + aut.extendName("" + r.getId()); + aut.dropTableSql(dataSource); + userAuthorManager.NotifyDeleteRole(role); + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + + } + return new RespEntity(RespCode.FAIL); + } + + + public boolean updateRoleAuthoriy(String rolename, List authors){ + RoleEntity role = new RoleEntity(); + role.setRolename(rolename); + role = (RoleEntity)role.QueryIt(dataSource); + try { + AuthorityEntity aut = new AuthorityEntity(); + aut.extendName("" + role.getId()); + aut.DeleteAll(dataSource); + for (AuthorityEntity auth : authors) { + auth.extendName("" + role.getId()); + auth.Insert(dataSource); + } + userAuthorManager.NotifyUpdateRoleAuthority(role); + }catch (Exception e){ + return false; + } + return true; + + } + public List queryAllAuthoriy( ){ + + List authlist = new ArrayList(); + InputStream stream = null; + try { + // Resource resource = new ClassPathResource("static\\dbinfodefine.xml"); + // File file = resource.getFile(); + stream = getClass().getClassLoader().getResourceAsStream("static/resinfodefine.xml"); + File targetFile = new File("resinfodefine.xml"); + //FileUtils.copyInputStreamToFile(stream, targetFile); + + // BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(targetFile))); + + SAXReader reader = new SAXReader(); + Document document = reader.read(new InputStreamReader(stream,"utf8")); + Element root = document.getRootElement(); + if("resinfodefine".equals(root.getName())) { + List list = root.elements(); + for(Element res:list){ + if(!"res".equals(res.getName())) + continue; + try { + Attribute attr = res.attribute("type"); + String type = attr.getStringValue(); + attr = res.attribute("scope"); + if (attr != null) { + String useflag = attr.getStringValue(); + if (useflag != null && !useflag.equals("optional")) + continue; + } + attr = res.attribute("descript"); + String discript = attr.getStringValue(); + attr = res.attribute("path"); + String path = attr.getStringValue(); + if (type == null || type.length() <= 0 || path == null || path.length() <= 0) + continue; + AuthorityEntity auth = new AuthorityEntity(); + auth.setDiscript(discript); + auth.setPath(path); + auth.setType(type); + authlist.add(auth); + }catch (Exception e){ + + } + } + } + }catch (Exception e){ + e.printStackTrace(); + }finally { + try { + if (stream != null) + stream.close(); + }catch (Exception e){ + + } + } + return authlist; + + } + + + public List queryUserList(OrganiztionUri orguri) { + ArrayList rel = new ArrayList(); + UserInfoEntity u = new UserInfoEntity(); + List users = u.queryList(dataSource,null,null); + for(SQLDataObject ob:users){ + UserInfoEntity user = (UserInfoEntity)ob; + user.setPassword(null); + if(user.getLevelvalue() != null){ + if(user.getLevelvalue().equals("master")){ + rel.add(user); + continue; + } + } + OrganiztionUri userorg = new OrganiztionUri(); + + if(user.getScopelevel().equals("brigade")){ + userorg.setBrigade(user.getLevelvalue()); + }else if(user.getScopelevel().equals("borough")){ + userorg.setBorough(user.getLevelvalue()); + BoroughEntity b = new BoroughEntity(); + b.setBorough(user.getLevelvalue()); + b = (BoroughEntity)b.QueryIt(dataSource); + if(b!=null) + userorg.setBrigade(b.getBrigade()); + + }else if(user.getScopelevel().equals("detachment")){ + userorg.setDetachment(user.getLevelvalue()); + + DetachmentEntity d = new DetachmentEntity(); + d.setDetachment(user.getLevelvalue()); + d = (DetachmentEntity)d.QueryIt(dataSource); + if(d!=null){ + userorg.setBorough(d.getBorough()); + userorg.setBrigade(d.getBrigade()); + + } + } + else if(user.getScopelevel().equals("station")){ + userorg.setStation(user.getLevelvalue()); + FireStationBaseInfoEntity s = new FireStationBaseInfoEntity(); + s.setName(user.getLevelvalue()); + s = (FireStationBaseInfoEntity)s.QueryIt(dataSource); + if(s!=null){ + userorg.setBorough(s.getBorough()); + userorg.setBrigade(s.getBrigade()); + userorg.setDetachment(s.getDetachment()); + + } + } + + if(orguri.brigade!=null&&!orguri.brigade.equals(userorg.getBrigade())) + continue; + + if(orguri.borough!=null&&!orguri.borough.equals(userorg.getBorough())) + continue; + + if(orguri.detachment!=null&&!orguri.detachment.equals(userorg.getDetachment())) + continue; + + if(orguri.station!=null&&!orguri.station.equals(userorg.getStation())) + continue; + + rel.add(user); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/AuthorityEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/AuthorityEntity.java new file mode 100644 index 0000000..f026407 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/AuthorityEntity.java @@ -0,0 +1,71 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class AuthorityEntity extends SQLDataObject { + @JPos(index=1,primary = true,filter = true,orderkey = true) + private String path; + @JPos(index=2,filter = true) + private String type; + @JPos(index=3) + private String discript; + + public void setPath(String path) { + this.path = path; + } + + public String getPath() { + return path; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setDiscript(String discript) { + this.discript = discript; + } + + public String getDiscript() { + return discript; + } + + public String tableName(){ + return "firectrl_role_"+tableExtName+"_authority_table"; + } + + public boolean dropTableSql(DataSource dataSource){ + String sql = "DROP TABLE "; + sql += tableName(); + try{ + if(SQLTools.ExecuteSQL(dataSource, sql)) + return true; + else + return false; + }catch (Exception e){ + + } + return false; + } + + + public boolean DeleteAll(DataSource dataSource){ + String sql = "DELETE FROM "+tableName(); + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/BoroughEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/BoroughEntity.java new file mode 100644 index 0000000..5752173 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/BoroughEntity.java @@ -0,0 +1,104 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class BoroughEntity extends SQLDataObject{ + @JPos(index=0,primary = true,filter = true,orderkey = true) + private String borough; + @JPos(index=1,primary = true,filter = true) + private String brigade; + @JPos(index=2) + private String address; + @JPos(index=3) + private double longitude; + @JPos(index=4) + private double latitude; + @JPos(index=5,filter = true) + private String level; + @JPos(index=6,filter = true) + private String legal_person; + @JPos(index=7,filter = true) + private String phone; + @JPos(index=8,strlen = 512) + private String remark; + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLegal_person(String legal_person) { + this.legal_person = legal_person; + } + + public String getLegal_person() { + return legal_person; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getLevel() { + return level; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getRemark() { + return remark; + } + + public String tableName( ){ + return "iotserver_borough_list_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/BrigadeEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/BrigadeEntity.java new file mode 100644 index 0000000..7aed558 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/BrigadeEntity.java @@ -0,0 +1,97 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.firestationport.model.sensor.ACBEventEntity; +import com.jingyi.iotserver.firestationport.model.todev.AssignmentEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class BrigadeEntity extends SQLDataObject{ + @JPos(index=0,primary = true,filter = true,orderkey = true) + private String brigade; + @JPos(index=1) + private String address; + @JPos(index=2) + private double longitude; + @JPos(index=3) + private double latitude; + @JPos(index=4,filter = true) + private String level; + @JPos(index=5,filter = true) + private String legal_person; + @JPos(index=6,filter = true) + private String phone; + @JPos(index=7,strlen = 512) + private String remark; + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLegal_person(String legal_person) { + this.legal_person = legal_person; + } + + public String getLegal_person() { + return legal_person; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getLevel() { + return level; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getRemark() { + return remark; + } + + public String tableName(){ + return "iotserver_brigade_list_table"; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/DetachmentEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/DetachmentEntity.java new file mode 100644 index 0000000..62e7440 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/DetachmentEntity.java @@ -0,0 +1,114 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class DetachmentEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true,orderkey = true) + private String detachment; + @JPos(index=1,primary = true,filter = true) + private String borough; + @JPos(index=2,primary = true,filter = true) + private String brigade; + @JPos(index=3) + private String address; + @JPos(index=4) + private double longitude; + @JPos(index=5) + private double latitude; + @JPos(index=6,filter = true) + private String level; + @JPos(index=7,filter = true) + private String legal_person; + @JPos(index=8,filter = true) + private String phone; + @JPos(index=9,strlen = 512) + private String remark; + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLegal_person(String legal_person) { + this.legal_person = legal_person; + } + + public String getLegal_person() { + return legal_person; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getLevel() { + return level; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getRemark() { + return remark; + } + + public String tableName( ){ + return "iotserver_detachment_list_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/InfoChange.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/InfoChange.java new file mode 100644 index 0000000..1ddcb05 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/InfoChange.java @@ -0,0 +1,23 @@ +package com.jingyi.iotserver.clientmanage.model; + +public class InfoChange { + private Object oldinfo; + private Object newinfo; + + public void setOldinfo(Object oldinfo) { + this.oldinfo = oldinfo; + } + + public Object getOldinfo() { + return oldinfo; + } + + public void setNewinfo(Object newinfo) { + this.newinfo = newinfo; + } + + public Object getNewinfo() { + return newinfo; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/LoginResultEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/LoginResultEntity.java new file mode 100644 index 0000000..f1173c5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/LoginResultEntity.java @@ -0,0 +1,102 @@ +package com.jingyi.iotserver.clientmanage.model; + +public class LoginResultEntity { + private OrganizationInfoEntity organize; + private String session; + private String usertype; + private String scopelevel; + private String levelvalue; + private double longitude; + private double latitude; + private String phone; + private String theme; + private String orgname; + private String hidden; + public void setOrganize(OrganizationInfoEntity organize) { + this.organize = organize; + } + + public OrganizationInfoEntity getOrganize() { + return organize; + } + + public void setSession(String session) { + this.session = session; + } + + public String getSession() { + return session; + } + + public void setUsertype(String usertype) { + this.usertype = usertype; + } + + public String getUsertype() { + return usertype; + } + + public void setScopelevel(String scopelevel) { + this.scopelevel = scopelevel; + } + + public String getScopelevel() { + return scopelevel; + } + + public void setLevelvalue(String levelvalue) { + this.levelvalue = levelvalue; + } + + public String getLevelvalue() { + return levelvalue; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setTheme(String theme) { + this.theme = theme; + } + + public String getTheme() { + return theme; + } + + public String getOrgname() { + return orgname; + } + + public void setOrgname(String orgname) { + this.orgname = orgname; + } + + public String getHidden() { + return hidden; + } + + public void setHidden(String hidden) { + this.hidden = hidden; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/OperatingRecordEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/OperatingRecordEntity.java new file mode 100644 index 0000000..215f3a0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/OperatingRecordEntity.java @@ -0,0 +1,86 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.firestationport.model.station.FireMediaInfoEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class OperatingRecordEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String username; + @JPos(index=1,filter = true) + private String operate; + @JPos(index=2,filter = true) + private String objective; + @JPos(index=3,primary = true,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index=4,strlen = 512) + private String content; + @JPos(index=5,strlen = 4096) + private String detail; + @JPos(index=7) + private int result; + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setOperate(String operate) { + this.operate = operate; + } + + public String getOperate() { + return operate; + } + + public void setObjective(String objective) { + this.objective = objective; + } + + public String getObjective() { + return objective; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setDetail(String detail) { + this.detail = detail; + } + + public String getDetail() { + return detail; + } + + public void setResult(int result) { + this.result = result; + } + + public int getResult() { + return result; + } + + public String tableName(){ + return "iotserver_operate_record_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/OrganizationInfoEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/OrganizationInfoEntity.java new file mode 100644 index 0000000..8030c9c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/OrganizationInfoEntity.java @@ -0,0 +1,119 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class OrganizationInfoEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true,orderkey = true) + private String orgname; + @JPos(index=1,filter = true) + private String brigade; + @JPos(index=2,filter = true) + private String borough; + @JPos(index=3,filter = true) + private String detachment; + @JPos(index=4) + private double longitude; + @JPos(index=5) + private double latitude; + @JPos(index=6,filter = true) + private String city; + @JPos(index=7) + private String address; + @JPos(index=8) + private String theme; + @JPos(index=9) + private String logo; + + public void setOrgname(String orgname) { + this.orgname = orgname; + } + + public String getOrgname() { + return orgname; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setCity(String city) { + this.city = city; + } + + public String getCity() { + return city; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public String tableName(){ + return "firectrl_organization_info_table"; + } + + public static OrganizationInfoEntity Query(DataSource dataSource,String name){ + OrganizationInfoEntity org = new OrganizationInfoEntity(); + org.setOrgname(name); + return (OrganizationInfoEntity)org.QueryIt(dataSource); + } + + public String getTheme() { + return theme; + } + + public void setTheme(String theme) { + this.theme = theme; + } + + public String getLogo() { + return logo; + } + + public void setLogo(String logo) { + this.logo = logo; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/OrganiztionUri.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/OrganiztionUri.java new file mode 100644 index 0000000..3358ab0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/OrganiztionUri.java @@ -0,0 +1,40 @@ +package com.jingyi.iotserver.clientmanage.model; + +public class OrganiztionUri { + public String brigade; + public String borough; + public String detachment; + public String station; + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/PropertyChange.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/PropertyChange.java new file mode 100644 index 0000000..0a1acaf --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/PropertyChange.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.clientmanage.model; + +public class PropertyChange { + private Object owner; + private Object oldpro; + private Object newpro; + + public void setOwner(Object owner) { + this.owner = owner; + } + + public Object getOwner() { + return owner; + } + + public void setOldpro(Object oldpro) { + this.oldpro = oldpro; + } + + public Object getOldpro() { + return oldpro; + } + + public void setNewpro(Object newpro) { + this.newpro = newpro; + } + + public Object getNewpro() { + return newpro; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/RoleEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/RoleEntity.java new file mode 100644 index 0000000..997104e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/RoleEntity.java @@ -0,0 +1,61 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.List; + +public class RoleEntity extends SQLDataObject { + @JPos(index=0,identify = true,orderkey = true) + private int id; + @JPos(index=1,primary = true,filter = true) + private String rolename; + private HashMap authorlist; + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setRolename(String rolename) { + this.rolename = rolename; + } + + public String getRolename() { + return rolename; + } + + public void setAuthorlist(HashMap authorlist) { + this.authorlist = authorlist; + } + + public HashMap getAuthorlist() { + return authorlist; + } + + public void addAuthor(AuthorityEntity auth){ + if(authorlist==null) + authorlist = new HashMap(); + authorlist.put(auth.getPath(),auth); + } + + public boolean hasAuthor(String path){ + if(authorlist==null) + return false; + if(authorlist.get(path)!=null) + return true; + return false; + } + public String tableName( ){ + return "firectrl_user_role_table"; + } + + public static RoleEntity Query(DataSource dataSource,String role){ + RoleEntity r = new RoleEntity(); + r.setRolename(role); + return (RoleEntity)r.QueryIt(dataSource); + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/ThirdPlatformInfoEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/ThirdPlatformInfoEntity.java new file mode 100644 index 0000000..493997a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/ThirdPlatformInfoEntity.java @@ -0,0 +1,122 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class ThirdPlatformInfoEntity extends SQLDataObject { + @JPos(index=0,identify = true,orderkey = true) + private int id; + @JPos(index=1,filter = true) + private String platform; + @JPos(index=2,filter = true) + private String company; + @JPos(index=3,primary = true,filter = true) + private String appkey; + @JPos(index=4,timekey = true) + private Date createtime; + + @JPos(index=5,filter = true) + public String brigade; + @JPos(index=6,filter = true) + public String borough; + @JPos(index=7,filter = true) + public String detachment; + @JPos(index=8,filter = true) + public String station; + + @JPos(index=9,filter = true,strlen = 1024) + private String msgurl; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getPlatform() { + return platform; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getCompany() { + return company; + } + + public void setAppkey(String appkey) { + this.appkey = appkey; + } + + public String getAppkey() { + return appkey; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public String getMsgurl() { + return msgurl; + } + + public void setMsgurl(String msgurl) { + this.msgurl = msgurl; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "firectrl_third_platform_info_table"; + } + + public static ThirdPlatformInfoEntity Query(DataSource dataSource,String appkey){ + ThirdPlatformInfoEntity r = new ThirdPlatformInfoEntity(); + r.setAppkey(appkey); + return (ThirdPlatformInfoEntity)r.QueryIt(dataSource); + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/UserAuthorDesEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserAuthorDesEntity.java new file mode 100644 index 0000000..8295655 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserAuthorDesEntity.java @@ -0,0 +1,32 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class UserAuthorDesEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true,orderkey = true) + private String name; + @JPos(index=1,strlen=4096) + private String authordes; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setAuthordes(String authordes) { + this.authordes = authordes; + } + + public String getAuthordes() { + return authordes; + } + + @Override + public String tableName() { + return "firectrl_user_authordes_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/UserHelper.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserHelper.java new file mode 100644 index 0000000..5c25f48 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserHelper.java @@ -0,0 +1,29 @@ +package com.jingyi.iotserver.clientmanage.model; + +public class UserHelper { + private UserInfoEntity userinfo; + public UserHelper(UserInfoEntity userinfo){ + this.userinfo = userinfo; + } + + public UserHelper(){ + userinfo = null; + } + + public void setUserinfo(UserInfoEntity userinfo){ + this.userinfo = userinfo; + } + + boolean isAdministrator(){ + if(userinfo==null) + return false; + try { + if (userinfo.getName().toLowerCase().equals("administrator")) { + return true; + } + }catch (Exception e){ + + } + return false; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/UserInfoEntity.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserInfoEntity.java new file mode 100644 index 0000000..826cf54 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserInfoEntity.java @@ -0,0 +1,174 @@ +package com.jingyi.iotserver.clientmanage.model; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class UserInfoEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true,orderkey = true) + private String name; + @JPos(index=1) + private String password; + @JPos(index=2) + private String authority; + @JPos(index=3,filter = true) + private String orgname; + @JPos(index=4,filter = true) + private String usertype; + @JPos(index=5,filter = true) + private String userrole; + + @JPos(index=6,filter = true) + private String scopelevel;//master brigade borough detachment station + @JPos(index=7,filter = true) + private String levelvalue; + @JPos(index=8,filter = true) + private String phone; + @JPos(index=9,filter = true) + private String theme; + @JPos(index=10) + private double longitude; + @JPos(index=11) + private double latitude; + @JPos(index=12) + private String hidden; + + public boolean IsSuper(){ + if(name!=null&&name.toLowerCase().equals("administrator")){ + return true; + } + return false; + } + public boolean IsAdmin(){ + if(usertype!=null&&usertype.equals("admin")) + return true; + return false; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPassword() { + return password; + } + + public void setAuthority(String authority) { + this.authority = authority; + } + + public String getAuthority() { + return authority; + } + + public void setOrgname(String orgname) { + this.orgname = orgname; + } + + public String getOrgname() { + return orgname; + } + + public void setUsertype(String usertype) { + this.usertype = usertype; + } + + public String getUsertype() { + return usertype; + } + + public void setUserrole(String userrole){ + this.userrole = userrole; + } + + public String getUserrole() { + return userrole; + } + + public void setScopelevel(String scopelevel) { + this.scopelevel = scopelevel; + } + + public String getScopelevel() { + return scopelevel; + } + + public void setLevelvalue(String levelvalue) { + this.levelvalue = levelvalue; + } + + public String getLevelvalue() { + return levelvalue; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void addRole(String role){ + if(role==null||role.length()<=0) + return ; + if(userrole==null||userrole.length()<=0) + userrole = role; + else { + userrole += "#"; + userrole += role; + } + + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setTheme(String theme) { + this.theme = theme; + } + + public String getTheme() { + return theme; + } + + public String tableName(){ + return "firectrl_user_info_table"; + } + + public static UserInfoEntity QueryUser(DataSource dataSource,String name){ + UserInfoEntity user = new UserInfoEntity(); + user.setName(name); + return (UserInfoEntity)user.QueryIt(dataSource); + } + + public String getHidden() { + return hidden; + } + + public void setHidden(String hidden) { + this.hidden = hidden; + } +} diff --git a/src/main/java/com/jingyi/iotserver/clientmanage/model/UserLoginRecord.java b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserLoginRecord.java new file mode 100644 index 0000000..b320601 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/clientmanage/model/UserLoginRecord.java @@ -0,0 +1,7 @@ +package com.jingyi.iotserver.clientmanage.model; + +public class UserLoginRecord { + public String username; + public long lastLoginTime; + public int loginCount; +} diff --git a/src/main/java/com/jingyi/iotserver/common/configuration/DruidDataSourceConfig.java b/src/main/java/com/jingyi/iotserver/common/configuration/DruidDataSourceConfig.java new file mode 100644 index 0000000..d9d9390 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/common/configuration/DruidDataSourceConfig.java @@ -0,0 +1,176 @@ +package com.jingyi.iotserver.common.configuration; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.support.http.StatViewServlet; +import com.alibaba.druid.support.http.WebStatFilter; +import com.alibaba.druid.support.spring.stat.DruidStatInterceptor; +import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +/** + * Druid的DataResource配置类 + * 凡是被Spring管理的类,实现接口 EnvironmentAware 重写方法 setEnvironment 可以在工程启动时, + * 获取到系统环境变量和application配置文件中的变量。 还有一种方式是采用注解的方式获取 @value("${变量的key值}") + * 获取application配置文件中的变量。 这里采用第一种要方便些 + * Created by sun on 2017-1-20. + */ +@Configuration +@EnableTransactionManagement +public class DruidDataSourceConfig implements EnvironmentAware { + // private RelaxedPropertyResolver propertyResolver; + private Environment gEnv; + private DruidDataSource gSqlServerData = null; + private DruidDataSource gMySqlData = null; + + private DruidDataSource gMDevData = null; + public void setEnvironment(Environment env) { + gEnv = env; + // gEnv.acceptsProfiles(); + // this.propertyResolver = new RelaxedPropertyResolver(env, "spring.datasource."); + } + + public Environment getEnviroment(){ + return gEnv; + } + + @Bean + public DataSource dataSource() { + DruidDataSource datasource = new DruidDataSource(); + + datasource.setUrl(gEnv.getProperty("spring.datasource.url")); + datasource.setDriverClassName(gEnv.getProperty("spring.datasource.driver-class-name")); + datasource.setUsername(gEnv.getProperty("spring.datasource.username")); + datasource.setPassword(gEnv.getProperty("spring.datasource.password")); + datasource.setInitialSize(Integer.valueOf(gEnv.getProperty("spring.datasource.initialSize"))); + datasource.setMinIdle(Integer.valueOf(gEnv.getProperty("spring.datasource.minIdle"))); + datasource.setMaxWait(Long.valueOf(gEnv.getProperty("spring.datasource.maxWait"))); + datasource.setMaxActive(Integer.valueOf(gEnv.getProperty("spring.datasource.maxActive"))); + datasource.setMinEvictableIdleTimeMillis( + Long.valueOf(gEnv.getProperty("spring.datasource.minEvictableIdleTimeMillis"))); + try { + datasource.setFilters("stat,wall"); + } catch (SQLException e) { + e.printStackTrace(); + } + return datasource; + } + + @Bean + public ServletRegistrationBean druidServlet() { + ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(); + servletRegistrationBean.setServlet(new StatViewServlet()); + servletRegistrationBean.addUrlMappings("/druid/*"); + Map initParameters = new HashMap(); + // initParameters.put("loginUsername", "druid");// 用户名 + // initParameters.put("loginPassword", "druid");// 密码 + initParameters.put("resetEnable", "false");// 禁用HTML页面上的“Reset All”功能 + initParameters.put("allow", "127.0.0.1"); // IP白名单 (没有配置或者为空,则允许所有访问) + // initParameters.put("deny", "192.168.20.38");// IP黑名单 + // (存在共同时,deny优先于allow) + servletRegistrationBean.setInitParameters(initParameters); + return servletRegistrationBean; + } + + @Bean + public FilterRegistrationBean filterRegistrationBean() { + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); + filterRegistrationBean.setFilter(new WebStatFilter()); + filterRegistrationBean.addUrlPatterns("/*"); + filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"); + return filterRegistrationBean; + } + + // 按照BeanId来拦截配置 用来bean的监控 + @Bean(value = "druid-stat-interceptor") + public DruidStatInterceptor DruidStatInterceptor() { + DruidStatInterceptor druidStatInterceptor = new DruidStatInterceptor(); + return druidStatInterceptor; + } + + @Bean + public BeanNameAutoProxyCreator beanNameAutoProxyCreator() { + BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator(); + beanNameAutoProxyCreator.setProxyTargetClass(true); + // 设置要监控的bean的id + //beanNameAutoProxyCreator.setBeanNames("sysRoleMapper","loginController"); + beanNameAutoProxyCreator.setInterceptorNames("druid-stat-interceptor"); + return beanNameAutoProxyCreator; + } + + public DataSource getSqlServerDataSource() { + if (gSqlServerData == null) { + gSqlServerData = new DruidDataSource(); + + gSqlServerData.setUrl("jdbc:sqlserver://localhost:1433;database=firectrl_station;characterEncoding=UTF-8"); + gSqlServerData.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); + gSqlServerData.setUsername("sa"); + gSqlServerData.setPassword("?> filterChainDefinitionMap = new LinkedHashMap<>(); + filterChainDefinitionMap.put("/firectrl/client/user/login","anon"); + // filterChainDefinitionMap.put("/firectrl/client/getstationcount","anon"); + filterChainDefinitionMap.put("/logout","logout"); + filterChainDefinitionMap.put("/firectrl/client/*","authc"); + + shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); + return shiroFilterFactoryBean; + } + + @Bean + public FilterRegistrationBean filterRegistrationBean(){ + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); + filterRegistrationBean.setFilter(new DelegatingFilterProxy("shiroFilter")); + filterRegistrationBean.addInitParameter("targetFilterLifecycle","true"); + filterRegistrationBean.addUrlPatterns("/*"); + return filterRegistrationBean; + } +} diff --git a/src/main/java/com/jingyi/iotserver/common/service/CountResult.java b/src/main/java/com/jingyi/iotserver/common/service/CountResult.java new file mode 100644 index 0000000..e7da9a1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/common/service/CountResult.java @@ -0,0 +1,20 @@ +package com.jingyi.iotserver.common.service; + +public class CountResult { + private int count; + + public CountResult(){ + + } + + public CountResult(int c) { + count = c; + } + public void setCount(int count) { + this.count = count; + } + + public int getCount() { + return count; + } +} diff --git a/src/main/java/com/jingyi/iotserver/common/service/EnvConfigService.java b/src/main/java/com/jingyi/iotserver/common/service/EnvConfigService.java new file mode 100644 index 0000000..fc50bea --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/common/service/EnvConfigService.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.common.service; + +import com.jingyi.iotserver.common.configuration.DruidDataSourceConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class EnvConfigService { + @Autowired + private DruidDataSourceConfig sourceConfig ; + + private boolean blDataPortServer = false; + + private String reportFilePath = null; + public String getDataBaseName(){ + return sourceConfig.getEnviroment().getProperty("jy.database.name"); + } + public String getSuperPassword(){return sourceConfig.getEnviroment().getProperty("jy.user.super.password");} + + public String getDataBaseType(){return sourceConfig.getEnviroment().getProperty("spring.datasource.sqltype");} + + public void LoadConfig(){ + String str = sourceConfig.getEnviroment().getProperty("jy.server.config.dataport"); + if(str!=null&&str.equals("true")) + blDataPortServer = true; + else + blDataPortServer = false; + + reportFilePath = sourceConfig.getEnviroment().getProperty("jy.station.report.html.path"); + + } + + public boolean IsDataPortServer(){ + return blDataPortServer; + } + + public String getStationReportFilePath(){ + if(reportFilePath==null) + return "e:\\web\\https\\fireStationEmePlan\\php\\html"; + return reportFilePath; + } +} diff --git a/src/main/java/com/jingyi/iotserver/common/service/RespCode.java b/src/main/java/com/jingyi/iotserver/common/service/RespCode.java new file mode 100644 index 0000000..111a012 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/common/service/RespCode.java @@ -0,0 +1,66 @@ +package com.jingyi.iotserver.common.service; + +public enum RespCode { + SUCCESS(0, "请求成功"), + FAIL(-1,"请求失败"), + WARN(-2, "网络异常,请稍后重试"), + ERROR_CMD(-3,"错误的请求命令"), + NOTEXIST(-4,"信息不存在"), + ERROR_REQUEST(-5,"错误的请求"), + EXCEPTION(-6,"请求异常"), + EXIST(-7,"信息已存在"), + DEVICE_BOUND(-8,"设备已绑定"), + NOTEMPTY(-9,"列表不为空"), + USER_PWD_ERROR(-10,"用户名或密码错误"), + EMPTY(-11,"列表为空"), + NOAUTHOR(-12,"无权限"), + COMPLETED(-13,"已完成"), + LOGIN_ERROR_DELAY_10MIN(-14,"请10分钟后重试登录"); + private int code; + private String msg; + + RespCode(int code, String msg) { + this.msg = msg; + this.code = code; + } + + public int getCode() { + return code; + } + public String getMsg() { + return msg; + } + + static public RespCode getResp(int code){ + switch(code){ + case 0: + return SUCCESS; + case -1: + return FAIL; + case -2: + return WARN; + case -3: + return ERROR_CMD; + case -4: + return NOTEXIST; + case -5: + return ERROR_REQUEST; + case -6: + return EXCEPTION; + case -7: + return EXIST; + case -8: + return DEVICE_BOUND; + case -9: + return NOTEMPTY; + case -10: + return USER_PWD_ERROR; + case -11: + return EMPTY; + case -12: + return NOAUTHOR; + + } + return FAIL; + } +} diff --git a/src/main/java/com/jingyi/iotserver/common/service/RespEntity.java b/src/main/java/com/jingyi/iotserver/common/service/RespEntity.java new file mode 100644 index 0000000..a3c0e0d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/common/service/RespEntity.java @@ -0,0 +1,66 @@ +package com.jingyi.iotserver.common.service; + +public class RespEntity { + private int code; + private String msg; + private int request; + private Object data; + + public RespEntity(){ + + } + + public RespEntity(RespCode respCode) { + this.code = respCode.getCode(); + this.msg = respCode.getMsg(); + this.request = 0; + } + + public RespEntity(RespCode respCode, Object data) { + this(respCode); + this.data = data; + this.request = 0; + } + + public RespEntity(RespCode respCode,int request){ + this(respCode); + this.request = request; + } + + public RespEntity(RespCode respCode, Object data,int request) { + this(respCode,data); + this.request = request; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public void setRequest(int request) { + this.request = request; + } + + public int getRequest() { + return request; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/FireCtrlSystemInit.java b/src/main/java/com/jingyi/iotserver/firestationport/FireCtrlSystemInit.java new file mode 100644 index 0000000..a126b98 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/FireCtrlSystemInit.java @@ -0,0 +1,135 @@ +package com.jingyi.iotserver.firestationport; + +import com.jingyi.iotserver.clientmanage.UserService; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.firestationport.model.update.SoftwareUpdateTaskEntity; +import com.jingyi.iotserver.firestationport.services.*; +import com.jingyi.iotserver.firestationport.services.eyeapp.SensorEventPusher; +import com.jingyi.iotserver.firestationport.services.netease.NeteaseVideoManager; +import com.jingyi.iotserver.firestationport.services.netease.NeteaseVideoService; +import com.jingyi.iotserver.firestationport.services.sensor.ACBSystemAgent; +import com.jingyi.iotserver.firestationport.services.sensor.DeShanAnService; +import com.jingyi.iotserver.firestationport.services.sensor.SensorRunInfoManager; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.HttpTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; +import java.util.Date; + +@Order(value=1) +@Component +public class FireCtrlSystemInit implements CommandLineRunner { + + public static final int netMode = 1; //0 内网,1外网 + @Autowired + DatabaseDesInfoService dbinfoService; + + @Autowired + StationServices stationService; + + @Autowired + NeteaseVideoService neteaseVideoService; + + @Autowired + UserService userService; + + @Autowired + FireStationLiveManager fireStationLiveManager; + + @Autowired + UserAuthorManager userAuthorManager; + + @Autowired + ClientWebsocketManager clientWebsocketManager; + + @Autowired + TimingJobManager timingJobManager; + + @Autowired + SensorService sensorService; + + @Autowired + DataStatisticsService dataStatisticsService; + + @Autowired + NeteaseVideoManager neteaseVideoManager; + + @Autowired + SensorRunInfoManager sensorRunInfoManager; + + @Autowired + SensorEventPusher sensorEventPusher; + + @Autowired + EnvConfigService envConfigService; + + @Autowired + DatabaseTransfer databaseTransfer; + + @Autowired + private DeShanAnService deShanAnTCPService; + + @Autowired + private DataSource dataSource; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Autowired + private ACBSystemAgent acbSystemAgent; + + @Autowired + private MessagePublisher msgPublish; + private final Logger logger = LoggerFactory.getLogger(FireCtrlSystemInit.class); + @Override + public void run(String... args) { + try{ + + logger.info("FireCtrlSystemInit "); + envConfigService.LoadConfig(); + HttpTools.allowAllSSL(); + dbinfoService.LoadInfo(); + + userService.InitService(); + + fireStationLiveManager.Init(); + userAuthorManager.Init(); + sensorService.Init(); + + clientWebsocketManager.init(); + // timingJobManager.Init(); + + neteaseVideoManager.Init(); + + sensorRunInfoManager.Init(); + + sensorEventPusher.init(); + + databaseTransfer.Init(); + + ioTCtrlServer.startServer(6015); + + if(netMode == 1){ + deShanAnTCPService.startServer(); + } + + //acbSystemAgent.Init(); + + msgPublish.init(); + + dataStatisticsService.Init(); + }catch (Exception e){ + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/FirestationportApplication.java b/src/main/java/com/jingyi/iotserver/firestationport/FirestationportApplication.java new file mode 100644 index 0000000..8132170 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/FirestationportApplication.java @@ -0,0 +1,40 @@ +package com.jingyi.iotserver.firestationport; + +import org.apache.catalina.connector.Connector; +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.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.web.bind.annotation.RestController; + +@ComponentScan("com.jingyi.iotserver") +@RestController +@MapperScan("com.jingyi.iotserver") +@EnableScheduling +//@EnableAutoConfiguration +@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) +public class FirestationportApplication { + + @Bean + public ServletWebServerFactory servletContainer() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); + tomcat.addAdditionalTomcatConnectors(createStandardConnector()); + return tomcat; + } + + private Connector createStandardConnector() { + Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); + connector.setPort(8082); + return connector; + } + + public static void main(String[] args) { + SpringApplication.run(FirestationportApplication.class, args); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/AiIPCController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/AiIPCController.java new file mode 100644 index 0000000..513ebb1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/AiIPCController.java @@ -0,0 +1,1625 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.ClientLoginController; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.complexquery.AIIPCConfig; +import com.jingyi.iotserver.firestationport.model.mdev.MDevPictureEntity; + +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.*; +import com.jingyi.iotserver.firestationport.model.sensor.ys.*; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; + +import com.jingyi.iotserver.firestationport.services.sensor.SensorRunInfoManager; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.AISophgoNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentMQTTMessage; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.*; +import org.apache.commons.codec.binary.Base64; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URLEncoder; +import java.util.*; + +@RestController +@CrossOrigin +public class AiIPCController { + private final Logger logger = LoggerFactory.getLogger(ClientLoginController.class); + @Autowired + private DataSource dataSource; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Autowired + private SensorRunInfoManager sensorRunInfoManager; + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private MessagePublisher messagePublisher; + + @ResponseBody + @RequestMapping(value="/aiipc/config/query",method = RequestMethod.POST) + public RespEntity queryConfigInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String deviceid = JsonHelper.getStringValue(rootnode, "deviceid"); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,deviceid); + if(sensor == null) + return new RespEntity(RespCode.NOTEXIST); + + AIIPCConfig config = new AIIPCConfig(); + config.setDeviceid(deviceid); + + AIIPCSettingEntity setting = new AIIPCSettingEntity(); + setting.setDeviceid(deviceid); + setting = (AIIPCSettingEntity)setting.QueryIt(dataSource); + if(setting==null){ + setting = new AIIPCSettingEntity(); + setting.setDeviceid(deviceid); + setting.setHeartbeat(180); + setting.setServeraddr("118.190.86.237"); + setting.setPort(9019); + setting.setImageuploadaddr("https://www.genetek.cc:8083/firectrl/file/aiipc/upload"); + } + config.setSetting(setting); + + AIIPCEventSettingEntity eventset = new AIIPCEventSettingEntity(); + eventset.setDeviceid(deviceid); + List list = eventset.queryList(dataSource,null,null); + config.setEventsetting(list); + + AIIPCPictureMatchSettingEntity picset = new AIIPCPictureMatchSettingEntity(); + picset.setDeviceid(deviceid); + list = picset.queryList(dataSource,null,null); + config.setPicturematchsetting(list); + + AIIPCTextMatchSettingEntity txtset = new AIIPCTextMatchSettingEntity(); + txtset.setDeviceid(deviceid); + list = txtset.queryList(dataSource,null,null); + config.setTextmatchsetting(list); + + return new RespEntity(RespCode.SUCCESS,config); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + /* + yingshi ipc + */ + @ResponseBody + @RequestMapping(value="/firectrl/ai/ys_ipc/getlist",method = RequestMethod.POST) + public RespEntity getYsIPCList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + YsIPCEntity ysIPC = (YsIPCEntity)SQLTools.getEntityFromJson(rootnode,YsIPCEntity.class); + + if(ysIPC==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(ysIPC.getBrigade()==null && ysIPC.getBorough() == null && ysIPC.getDetachment() == null ) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = ysIPC.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/ys_ipc/add",method = RequestMethod.POST) + public RespEntity addYsIPCInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + YsIPCEntity ysIPC = (YsIPCEntity) SQLTools.getEntityFromJson(rootnode, YsIPCEntity.class); + if (ysIPC == null) + return new RespEntity(RespCode.ERROR_CMD); + if (ysIPC.getDeviceId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(ysIPC.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (ysIPC.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/ys_alarm/getlist",method = RequestMethod.POST) + public RespEntity getYsAlarmList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + YsAlarmEntity ysAlarm = (YsAlarmEntity)SQLTools.getEntityFromJson(rootnode,YsAlarmEntity.class); + + if(ysAlarm==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(ysAlarm.getBrigade()==null && ysAlarm.getBorough() == null && ysAlarm.getDetachment() == null && ysAlarm.getStation() == null && ysAlarm.getDeviceId() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = ysAlarm.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/ys_alarm/read",method = RequestMethod.POST) + public RespEntity readYsAlarmState(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + YsAlarmEntity ysAlarm = (YsAlarmEntity) SQLTools.getEntityFromJson(rootnode, YsAlarmEntity.class); + if (ysAlarm == null) + return new RespEntity(RespCode.ERROR_CMD); + if (ysAlarm.getMessageId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(ysAlarm.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + ysAlarm.setReadState("readed"); + ysAlarm.setReadTime(new Date()); + if (ysAlarm.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/ai/ys_cutout/getlist",method = RequestMethod.POST) + public RespEntity getYsCutoutList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + YsAlarmCutoutEntity ysAlarm = (YsAlarmCutoutEntity)SQLTools.getEntityFromJson(rootnode,YsAlarmCutoutEntity.class); + + if(ysAlarm==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(ysAlarm.getBrigade()==null && ysAlarm.getBorough() == null && ysAlarm.getDetachment() == null && ysAlarm.getStation() == null && ysAlarm.getDeviceId() == null && ysAlarm.getRoomInfo() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = ysAlarm.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/ys_key/token",method = RequestMethod.POST) + public RespEntity getYsToken(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + YsTokenEntity ysAccout = (YsTokenEntity)SQLTools.getEntityFromJson(rootnode,YsTokenEntity.class); + + if(ysAccout==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(ysAccout.getAppKey()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + YsTokenEntity ysToken = (YsTokenEntity)ysAccout.QueryIt(dataSource); + + if(ysToken != null){ + Date nowTimestamp = new Date(); + long ts = ysToken.getExpireTime() - nowTimestamp.getTime(); + if(ts > 43200000){ + ysToken.setAppSecret(""); + return new RespEntity(RespCode.SUCCESS, ysToken); + } + }else{ + ysToken = new YsTokenEntity(); + ysToken.setAppKey("5a152882b3774f90848b20d9c0ca9abc"); + ysToken.setAppSecret("13e6cb6d8a8eeabac84e31baa1551438"); + } + + try { + JSONObject loginInfo = new JSONObject(); + loginInfo.put("appKey", ysToken.getAppKey()); + loginInfo.put("appSecret", ysToken.getAppSecret()); + String loginStr = JSONObject.toJSONString(loginInfo); + loginStr = "appKey="+ysToken.getAppKey()+"&appSecret="+ysToken.getAppSecret(); + HttpURLConnection connLogin = HttpTools.createHttpConnection( "https://open.ys7.com/api/lapp/token/get"); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(loginStr); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("loginYS: fail = " + responseCode); + return new RespEntity(RespCode.FAIL); + } + String loginResult = HttpTools.getBodyFromRespone(connLogin); + JSONObject resJson = JSONObject.parseObject(loginResult); + + System.out.println("loginYS: " + resJson); + + String retCode = resJson.getString("code"); + if("200".equalsIgnoreCase(retCode)){ + JSONObject dataJson = resJson.getJSONObject("data"); + String accessToken = dataJson.getString("accessToken"); + long expireTime = dataJson.getLongValue("expireTime"); + + ysToken.setAccessToken(accessToken); + ysToken.setExpireTime(expireTime); + ysToken.setAppState("ok"); + + ysToken.Update(dataSource); + ysToken.setAppSecret(""); + return new RespEntity(RespCode.SUCCESS, ysToken); + }else{ + return new RespEntity(RespCode.EXCEPTION, retCode ); + } + + }catch (Exception e){ + e.printStackTrace(); + } + + rel = new RespEntity(RespCode.EXCEPTION); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/picture/agent",method = RequestMethod.GET) + public void getPictureAgent(String pictureUrl,HttpServletRequest request, HttpServletResponse response) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + pictureUrl = new String(Base64.decodeBase64(pictureUrl),"UTF-8"); + // pictureUrl = "https://alipicdeco.ys7.com:8089/ezviz/pic/down?url=aHR0cDovL2hpay1hbGljbG91ZC5vc3MtY24taGFuZ3pob3UtaW50ZXJuYWwuYWxpeXVuY3MuY29tLzcvQkEwMDE1NTg4XzFfMjAyMzA2MTkxMDI0MTUtQkEwMDE1NTg4LTEtMTUwMTAtMi0xP0V4cGlyZXM9MTY4Nzc0NjI2MiZPU1NBY2Nlc3NLZXlJZD1MVEFJNEdHcnExYTlrRndVNEJtR1pkblQmU2lnbmF0dXJlPW5JQmNEcUhTRXdkMlZtRzNOYndxeUtFN2NiOCUzRA==&crypt=2&time=2023-06-19T10:24:15&key=ac223d7340c886ebabe5ee8b35425327"; + InputStream inputStream = null; + ServletOutputStream outputStream = null; + HttpURLConnection connLogin = null; + try { + connLogin = HttpTools.createHttpConnection( pictureUrl); + connLogin.setRequestMethod("GET"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + int responseCode = connLogin.getResponseCode(); + + inputStream = connLogin.getInputStream(); + response.setContentType("multipart/form-data"); + // response.setContentType(request.getSession().getServletContext().getMimeType("jpg")); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode("agent.jpg","UTF-8")); + + outputStream = response.getOutputStream(); + + byte[] buffer = new byte[1024]; + int len = 0; + while ((len = inputStream.read(buffer)) != -1){ + outputStream.write(buffer, 0, len); + } + }catch (Exception e){ + e.printStackTrace(); + }finally { + if(inputStream != null){ + inputStream.close(); + } + if(outputStream != null){ + outputStream.flush(); + outputStream.close(); + } + if(connLogin != null){ + connLogin.disconnect(); + } + } + + }catch (Exception e){ + e.printStackTrace(); + + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/hik/device/sync",method = RequestMethod.POST) + public RespEntity syncHikDeviceList(HttpServletRequest request) { + RespEntity rel = null; + try { + String hikDevices = HikvisionAPI.GetDeviceList(dataSource); + return new RespEntity(RespCode.SUCCESS, hikDevices); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/hik/device/preview",method = RequestMethod.POST) + public RespEntity getHikDeviceVideoUrl(HttpServletRequest request) { + RespEntity rel = null; + try { + String ysData = HttpTools.getBodyFromRequest(request); + JSONObject jsonObject = JSON.parseObject(ysData); + if(!jsonObject.containsKey("cameraIndexCode")){ + rel = new RespEntity(RespCode.EXCEPTION); + return rel; + } + String cameraCode = jsonObject.getString("cameraIndexCode"); + String hikDevices = HikvisionAPI.GetCameraPreviewURL(cameraCode); + return new RespEntity(RespCode.SUCCESS, hikDevices); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/hik/device/getlist",method = RequestMethod.POST) + public RespEntity getHikIPCList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikvisionIPCEntity hikvisionIPC = (HikvisionIPCEntity)SQLTools.getEntityFromJson(rootnode, HikvisionIPCEntity.class); + + if(hikvisionIPC==null) + hikvisionIPC = new HikvisionIPCEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = hikvisionIPC.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/hik/device/getinfo",method = RequestMethod.POST) + public RespEntity getHikIPCInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikvisionIPCEntity hikvisionIPC = (HikvisionIPCEntity)SQLTools.getEntityFromJson(rootnode, HikvisionIPCEntity.class); + + if(hikvisionIPC==null) + hikvisionIPC = new HikvisionIPCEntity(); + + if(hikvisionIPC.getCameraIndexCode()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + HikvisionIPCEntity orgtask = (HikvisionIPCEntity)hikvisionIPC.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + return new RespEntity(RespCode.SUCCESS, orgtask); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/hik/device/update",method = RequestMethod.POST) + public RespEntity modifyHikIPCList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikvisionIPCEntity hikvisionIPC = (HikvisionIPCEntity)SQLTools.getEntityFromJson(rootnode, HikvisionIPCEntity.class); + + if(hikvisionIPC==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(hikvisionIPC.getCameraIndexCode()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + HikvisionIPCEntity orgtask = (HikvisionIPCEntity)hikvisionIPC.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if (hikvisionIPC.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + skynet face alarm + */ + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/read",method = RequestMethod.POST) + public RespEntity readSkynetFaceAlarm(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikFaceAlarmRecordEntity hikvisionIPC = (HikFaceAlarmRecordEntity)SQLTools.getEntityFromJson(rootnode, HikFaceAlarmRecordEntity.class); + + if(hikvisionIPC==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(hikvisionIPC.getAlarmId()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + HikFaceAlarmRecordEntity oldRecord = (HikFaceAlarmRecordEntity)hikvisionIPC.QueryIt(dataSource); + if(oldRecord==null){ + return new RespEntity(RespCode.NOTEXIST); + } + oldRecord.setReadState(HikFaceAlarmRecordEntity.STATE_Read); + if (oldRecord.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/getlist",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikFaceAlarmRecordEntity hikvisionIPC = (HikFaceAlarmRecordEntity)SQLTools.getEntityFromJson(rootnode, HikFaceAlarmRecordEntity.class); + + if(hikvisionIPC==null) + hikvisionIPC = new HikFaceAlarmRecordEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = hikvisionIPC.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/getlist_ex",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmListEx(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikFaceAlarmRecordEntity hikvisionIPC = (HikFaceAlarmRecordEntity)SQLTools.getEntityFromJson(rootnode, HikFaceAlarmRecordEntity.class); + + if(hikvisionIPC==null) + hikvisionIPC = new HikFaceAlarmRecordEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = hikvisionIPC.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + + HashMap personHash = new HashMap<>(); + for(int iRec = 0; iRec < list.size(); iRec++){ + HikFaceAlarmRecordEntity alarmRecord = (HikFaceAlarmRecordEntity)list.get(iRec); + if(personHash.containsKey(alarmRecord.getCertificateNumber())){ + personHash.get(alarmRecord.getCertificateNumber()).addCount(); + }else{ + HikFaceAlarmRecordSetInfo newPerson = new HikFaceAlarmRecordSetInfo(); + newPerson.setPersonId(alarmRecord.getCertificateNumber()); + newPerson.setGroupType(alarmRecord.getGroupType()); + newPerson.setPersonName(alarmRecord.getPersonName()); + newPerson.setCount(1); + personHash.put(alarmRecord.getCertificateNumber(), newPerson); + } + } + + HashMap groupHash = new HashMap<>(); + for(Map.Entry entry: personHash.entrySet()){ + HikFaceAlarmRecordSetInfo personInfo = entry.getValue(); + if(groupHash.containsKey(personInfo.getGroupType())){ + groupHash.get(personInfo.getGroupType()).addPersonInfo(personInfo); + }else{ + HikFaceAlarmGroupSetInfo newGroup = new HikFaceAlarmGroupSetInfo(); + newGroup.setGroupName(personInfo.getGroupType()); + newGroup.addPersonInfo(personInfo); + groupHash.put(personInfo.getGroupType(), newGroup); + } + } + + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/getlast",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmLast(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikFaceAlarmRecordEntity alarmRecordEntity = (HikFaceAlarmRecordEntity)SQLTools.getEntityFromJson(rootnode,HikFaceAlarmRecordEntity.class); + + if(alarmRecordEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmRecordEntity.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int limitCount = JsonHelper.getIntValue(rootnode, "limit"); + if(limitCount <= 0){ + limitCount = 2; + } + + List list = alarmRecordEntity.QueryLasts(dataSource, limitCount); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/broadcast",method = RequestMethod.POST) + public RespEntity broadcastSkynetFaceAlarm(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + HikFaceAlarmRecordEntity hikvisionIPC = (HikFaceAlarmRecordEntity)SQLTools.getEntityFromJson(rootnode, HikFaceAlarmRecordEntity.class); + + if(hikvisionIPC==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(hikvisionIPC.getAlarmId()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + HikFaceAlarmRecordEntity oldRecord = (HikFaceAlarmRecordEntity)hikvisionIPC.QueryIt(dataSource); + if(oldRecord==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + oldRecord.setBkgPicUrl(""); + oldRecord.setBkgPicUrlBak(""); + oldRecord.setRefrencePicUrl(""); + MessageToStation msg = new MessageToStation(); + msg.setMessage("skynet_face"); + msg.setData(JSON.toJSONString(oldRecord)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + + System.out.println("broadcast skynet alarm: " + str); + + if(FireCtrlSystemInit.netMode == 0) { + UDPAgentMQTTMessage agentMQTTMessage = new UDPAgentMQTTMessage(); + agentMQTTMessage.setMessage(str); + agentMQTTMessage.setTopic(oldRecord.getStation()); + System.out.println("broadcast skynet alarm to gate: " + oldRecord.getStation()); + try { + ioTCtrlServer.translateHttp2InternetUdp(UDPAgentPackage.TYPE_MDEV_MQTT, JSON.toJSONString(agentMQTTMessage)); + } catch (Exception e) { + e.printStackTrace(); + } + }else{ + System.out.println("broadcast skynet alarm to: " + oldRecord.getStation()); + messagePublisher.sendMessage(oldRecord.getStation(), str); + } + rel = new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/station/summary",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmSummary(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FaceAlarmStationSummary alarmFilter = (FaceAlarmStationSummary)SQLTools.getEntityFromJson(rootnode, FaceAlarmStationSummary.class); + + if(alarmFilter==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmFilter.getBrigade()==null|| alarmFilter.getYear() == null || alarmFilter.getMonth() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List listStations = alarmFilter.queryList(dataSource, null,null); + if(listStations == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(listStations.isEmpty()){ + return new RespEntity(RespCode.NOTEXIST); + } + + listStations.sort(new Comparator() { + @Override + public int compare(SQLDataObject param1, SQLDataObject param2) { + return Integer.compare(((FaceAlarmStationSummary)param1).getAlarmCount(), ((FaceAlarmStationSummary)param2).getAlarmCount()); + } + }); + + return new RespEntity(RespCode.SUCCESS, listStations); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/blacklist/summary",method = RequestMethod.POST) + public RespEntity getBlacklistFaceAlarmSummary(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FaceAlarmPersonSummary alarmFilter = (FaceAlarmPersonSummary)SQLTools.getEntityFromJson(rootnode, FaceAlarmPersonSummary.class); + + if(alarmFilter==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmFilter.getYear() == null || alarmFilter.getMonth() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List personList = alarmFilter.queryList(dataSource, null,null); + if(personList == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(personList.isEmpty()){ + return new RespEntity(RespCode.NOTEXIST); + } + + personList.sort(new Comparator() { + @Override + public int compare(SQLDataObject param1, SQLDataObject param2) { + return Integer.compare(((FaceAlarmPersonSummary)param1).getAlarmCount(), ((FaceAlarmPersonSummary)param2).getAlarmCount()); + } + }); + + return new RespEntity(RespCode.SUCCESS, personList); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/station/summary_agent",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmSummaryAgent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FaceAlarmStationSummary alarmFilter = (FaceAlarmStationSummary)SQLTools.getEntityFromJson(rootnode, FaceAlarmStationSummary.class); + + if(alarmFilter==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmFilter.getBrigade()==null|| alarmFilter.getYear() == null || alarmFilter.getMonth() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://10.8.0.2:8083/firectrl/skynet/facealarm/station/summary" ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(JSON.toJSONString(alarmFilter)); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("httpAgentIntoSkynet: fail = " + responseCode); + return new RespEntity(RespCode.EXCEPTION); + }else{ + System.out.println("httpAgentIntoSkynet: ok = " + responseCode); + + String loginResult = HttpTools.getBodyFromRespone(connLogin); + RespEntity retObj = JSON.parseObject(loginResult, RespEntity.class); + return new RespEntity(RespCode.SUCCESS, retObj.getData()); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("httpAgentIntoSkynet: fail = " + e.getMessage()); + }finally { + + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/blacklist/summary_agent",method = RequestMethod.POST) + public RespEntity getBlacklistFaceAlarmSummaryAgent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FaceAlarmPersonSummary alarmFilter = (FaceAlarmPersonSummary)SQLTools.getEntityFromJson(rootnode, FaceAlarmPersonSummary.class); + + if(alarmFilter==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmFilter.getYear() == null || alarmFilter.getMonth() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://10.8.0.2:8083/firectrl/skynet/facealarm/blacklist/summary" ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(JSON.toJSONString(alarmFilter)); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("httpAgentIntoSkynet: fail = " + responseCode); + return new RespEntity(RespCode.EXCEPTION); + }else{ + System.out.println("httpAgentIntoSkynet: ok = " + responseCode); + + String loginResult = HttpTools.getBodyFromRespone(connLogin); + RespEntity retObj = JSON.parseObject(loginResult, RespEntity.class); + return new RespEntity(RespCode.SUCCESS, retObj.getData()); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("httpAgentIntoSkynet: fail = " + e.getMessage()); + }finally { + + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/getlist_agent",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmListAgent(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://10.8.0.2:8083/firectrl/skynet/facealarm/getlist" ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(bodyData); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("httpAgentIntoSkynet: fail = " + responseCode); + return new RespEntity(RespCode.EXCEPTION); + }else{ + System.out.println("httpAgentIntoSkynet: ok = " + responseCode); + + String loginResult = HttpTools.getBodyFromRespone(connLogin); + RespEntity retObj = JSON.parseObject(loginResult, RespEntity.class); + return new RespEntity(RespCode.SUCCESS, retObj.getData()); + } + }catch (Exception e){ + System.out.println("httpAgentIntoSkynet: fail = " + e.getMessage()); + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/skynet/facealarm/getlist_agent_ex",method = RequestMethod.POST) + public RespEntity getSkynetFaceAlarmListAgentEx(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://10.8.0.2:8083/firectrl/skynet/facealarm/getlist" ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(bodyData); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("httpAgentIntoSkynet: fail = " + responseCode); + return new RespEntity(RespCode.EXCEPTION); + }else{ + System.out.println("httpAgentIntoSkynet: ok = " + responseCode); + + String loginResult = HttpTools.getBodyFromRespone(connLogin); + RespEntity retObj = JSON.parseObject(loginResult, RespEntity.class); + + if(retObj == null){ + return new RespEntity(RespCode.SUCCESS); + } + // List list = (List)retObj.getData(); + List list = JSON.parseArray(JSON.toJSONString(retObj.getData()), HikFaceAlarmRecordEntity.class); + HashMap personHash = new HashMap<>(); + for(int iRec = 0; iRec < list.size(); iRec++){ + HikFaceAlarmRecordEntity alarmRecord = (HikFaceAlarmRecordEntity)list.get(iRec); + if(personHash.containsKey(alarmRecord.getCertificateNumber())){ + personHash.get(alarmRecord.getCertificateNumber()).addCount(); + }else{ + HikFaceAlarmRecordSetInfo newPerson = new HikFaceAlarmRecordSetInfo(); + newPerson.setPersonId(alarmRecord.getCertificateNumber()); + newPerson.setGroupType(alarmRecord.getGroupType()); + newPerson.setPersonName(alarmRecord.getPersonName()); + newPerson.setCount(1); + personHash.put(alarmRecord.getCertificateNumber(), newPerson); + } + } + List personList = new ArrayList<>(); + HashMap groupHash = new HashMap<>(); + for(Map.Entry entry: personHash.entrySet()){ + HikFaceAlarmRecordSetInfo personInfo = entry.getValue(); + personList.add(personInfo); + if(groupHash.containsKey(personInfo.getGroupType())){ + groupHash.get(personInfo.getGroupType()).addPersonInfo(personInfo); + }else{ + HikFaceAlarmGroupSetInfo newGroup = new HikFaceAlarmGroupSetInfo(); + newGroup.setGroupName(personInfo.getGroupType()); + newGroup.addPersonInfo(personInfo); + groupHash.put(personInfo.getGroupType(), newGroup); + } + } + + List groupList = new ArrayList<>(); + for(Map.Entry entry: groupHash.entrySet()){ + groupList.add(entry.getValue()); + } + + + FaceAlarmRecordSum retSum = new FaceAlarmRecordSum(); + retSum.setData(retObj.getData()); + retSum.setGroupInfo(groupList); + retSum.setPersonInfo(personList); + return new RespEntity(RespCode.SUCCESS, retSum); + } + }catch (Exception e){ + System.out.println("httpAgentIntoSkynet: fail = " + e.getMessage()); + } + + return new RespEntity(RespCode.EXCEPTION); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/ai/sophgo/report",method = RequestMethod.POST) + public RespEntity reportSophgoEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + String sophgoData = HttpTools.getBodyFromRequest(request); + if(sophgoData == null){ + return new RespEntity(RespCode.SUCCESS); + } + if(sophgoData.length() < 100){ + // System.out.println("sophgo receive new heartbeat: " + sophgoData); + return new RespEntity(RespCode.SUCCESS); + } + + String dataHeader = sophgoData.substring(0, 100); + // System.out.println("sophgo receive new data: " + sophgoData); + + if(FireCtrlSystemInit.netMode == 1){ + // ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, sophgoData, "/ai/sophgo/report"); + } + + SophgoWarn sophgoWarn = new SophgoWarn(); + SophgoMetaData metaData1 = new SophgoMetaData(); + String warnId = null; + String deviceId = ""; + + JSONObject jo = JSON.parseObject(sophgoData); + if(jo.containsKey("WarnName")){ + sophgoWarn.setWarnName(jo.getString("WarnName")); + } + if(jo.containsKey("WarnType")){ + sophgoWarn.setWarnType(jo.getIntValue("WarnType")); + } + + if(jo.containsKey("WarnDesc")){ + sophgoWarn.setWarnDesc(jo.getString("WarnDesc")); + } + String targetId = ""; + String targetName = ""; + if(jo.containsKey("WarnInfo")){ + JSONObject jsWarnInfo = jo.getJSONObject("WarnInfo"); + if(jsWarnInfo != null){ + if(jsWarnInfo.containsKey("IdNumber")){ + targetId = jsWarnInfo.getString("IdNumber"); + sophgoWarn.setWarnInfo(targetId); + } + if(jsWarnInfo.containsKey("Name")){ + targetName = jsWarnInfo.getString("Name"); + } + } + } + + if(jo.containsKey("Metadata")){ + String metaData = jo.getString("Metadata"); + + JSONObject jMeta = JSON.parseObject(metaData); + if(jMeta.containsKey("ID")){ + warnId = "SOPHGO_" + jMeta.getString("ID"); + sophgoWarn.setWarnId(warnId); + } + + metaData1.setWarnId(warnId); + + if(jMeta.containsKey("ChannelName")){ + sophgoWarn.setChannelName(jMeta.getString("ChannelName")); + } + if(jMeta.containsKey("DeviceID")){ + deviceId = jMeta.getString("DeviceID"); + sophgoWarn.setDeviceId(deviceId); + + System.out.println("sophgo receive new event deviceId: " + deviceId); + } + if(jMeta.containsKey("Channel")){ + sophgoWarn.setChannelNo(jMeta.getIntValue("Channel")); + } + if(jMeta.containsKey("Timestamp")){ + sophgoWarn.setTimestamp(jMeta.getLongValue("Timestamp")); + } + + if(jMeta.containsKey("Image")){ + metaData1.setImage(jMeta.getString("Image")); + // System.out.println("sophgo receive new event: " + metaData1.getImage().length() ); + } + if(jMeta.containsKey("FullImage")){ + metaData1.setFullImage(jMeta.getString("FullImage")); + } + if(jMeta.containsKey("ExtraImage")){ + metaData1.setExtraImage(jMeta.getString("ExtraImage")); + } + + if(jMeta.containsKey("MetaType")){ + metaData1.setMetaType(jo.getIntValue("MetaType")); + System.out.println("sophgo receive new event 2: " + jo.getIntValue("MetaType")); + } + + } + + if(deviceId == null){ + return new RespEntity(RespCode.SUCCESS); + } + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, deviceId); + if(sensor == null) + return new RespEntity(RespCode.SUCCESS); + + sensorRunInfoManager.setSensorActive(sensor); + + sophgoWarn.setBrigade(sensor.getBrigade()); + sophgoWarn.setBorough(sensor.getBorough()); + sophgoWarn.setDetachment(sensor.getDetachment()); + sophgoWarn.setStation(sensor.getOwner()); + sophgoWarn.setLatitude(sensor.getLatitude()); + sophgoWarn.setLongitude(sensor.getLongitude()); + + if(warnId != null){ + String jpgUrl = saveSophgoImage(metaData1.getImage(), sophgoWarn ); + sophgoWarn.setImageUrl(jpgUrl); + sophgoWarn.setReadState(SophgoWarn.STATE_Unread); + sophgoWarn.setReceiveTime(new Date()); + sophgoWarn.setPersonId(targetId); + sophgoWarn.setPersonName(targetName); + sophgoWarn.Insert(dataSource); + + AISophgoNotify sophgoNotify = new AISophgoNotify(); + sophgoNotify.setWarnData(sophgoWarn, metaData1); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, sophgoNotify.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(sophgoNotify.getDeviceId()); + pro.setDevice_type("AI"); + sophgoNotify.attachProperty(pro); + clientWebsocketManager.addWebNotify(sophgoNotify); + } + + if(sophgoWarn.getWarnType() == 2){ + AiSearchAlarmEntity newAiAlarm = new AiSearchAlarmEntity(); + newAiAlarm.setAlarmType(AiSearchAlarmEntity.TYPE_FACE); + newAiAlarm.setAlarmId(sophgoWarn.getWarnId()); + newAiAlarm.setCity("长沙市"); + newAiAlarm.setDistrict("芙蓉区"); + newAiAlarm.setTown("马王堆"); + newAiAlarm.setTargetValue(targetId); + newAiAlarm.setTargetType(AiSearchAlarmEntity.TYPE_FACE); + newAiAlarm.setTargetName(targetName); + newAiAlarm.setStorageType("plat"); + newAiAlarm.setUrl("https://www.lonsungsh.com:8083/" + sophgoWarn.getImageUrl()); + newAiAlarm.setLatitude(sophgoWarn.getLatitude()); + newAiAlarm.setLongitude(sophgoWarn.getLongitude()); + newAiAlarm.setAddress(sensor.getAddress()); + newAiAlarm.setAlarmName(sophgoWarn.getWarnName()); + newAiAlarm.setDeviceId(sophgoWarn.getDeviceId()); + AiSearchAlarmEntity.reportToMultiPlat(newAiAlarm); + } + + } + // System.out.println("sophgo receive new event: " + JSON.toJSONString(sophgoWarn) ); + + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/ai/brvison/report",method = RequestMethod.POST) + public RespEntity reportBRVisionEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + String brvisonData = HttpTools.getBodyFromRequest(request); + if(brvisonData == null){ + new RespEntity(RespCode.SUCCESS); ; + } + BRVisonEvent brVisonEvent = JSON.parseObject(brvisonData, BRVisonEvent.class); + + if(brVisonEvent==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(brVisonEvent.getBranchesId()==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, brVisonEvent.getBranchesId()); + if(sensor == null) + return new RespEntity(RespCode.SUCCESS); + + sensorRunInfoManager.setSensorActive(sensor); + SophgoWarn sophgoWarn = new SophgoWarn(); + // SophgoMetaData metaData1 = new SophgoMetaData(); + + sophgoWarn.setWarnName(brVisonEvent.getEventName()); + try { + sophgoWarn.setWarnType(Integer.parseInt(brVisonEvent.getEventType())); + }catch (Exception e){ + sophgoWarn.setWarnType(0); + } + + sophgoWarn.setWarnDesc(brVisonEvent.getEventName()); + sophgoWarn.setImageUrl(brVisonEvent.getImg1()); + sophgoWarn.setTimestamp(new Date().getTime()); + sophgoWarn.setBrigade(sensor.getBrigade()); + sophgoWarn.setBorough(sensor.getBorough()); + sophgoWarn.setDetachment(sensor.getDetachment()); + sophgoWarn.setStation(sensor.getOwner()); + sophgoWarn.setLatitude(sensor.getLatitude()); + sophgoWarn.setLongitude(sensor.getLongitude()); + sophgoWarn.setDeviceId(sensor.getDeviceid()); + sophgoWarn.setWarnId(brVisonEvent.getAlarmId()); + sophgoWarn.setReadState(SophgoWarn.STATE_Unread); + sophgoWarn.setReceiveTime(new Date()); + + sophgoWarn.Insert(dataSource); + + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/behavioral/event/getlist",method = RequestMethod.POST) + public RespEntity getAIBehavioralEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SophgoWarn sophgoWarn = (SophgoWarn)SQLTools.getEntityFromJson(rootnode, SophgoWarn.class); + + if(sophgoWarn==null) + sophgoWarn = new SophgoWarn(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = sophgoWarn.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/behavioral/event/getlast",method = RequestMethod.POST) + public RespEntity getAIBehavioralEventLast(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SophgoWarn sophgoWarn = (SophgoWarn)SQLTools.getEntityFromJson(rootnode,SophgoWarn.class); + + if(sophgoWarn==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(sophgoWarn.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int limitCount = JsonHelper.getIntValue(rootnode, "limit"); + if(limitCount <= 0){ + limitCount = 2; + } + + List list = sophgoWarn.QueryLasts(dataSource, limitCount); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + private String saveSophgoImage(String base64JPG, SophgoWarn sophgoWarn){ + String path = "./pic"; + String filename = null ; + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + + // SophgoMetaData metaData1 = new SophgoMetaData(); + + MDevPictureEntity pJpgFile = new MDevPictureEntity(); + pJpgFile.setCreator(sophgoWarn.getDeviceId()); + pJpgFile.setBusiness("AI"); + + try { + String uri = "/mdev/pic/download?creator="; + + uri += pJpgFile.getCreator(); + path += "/"+pJpgFile.getCreator(); + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + + pJpgFile.setId(UUID.randomUUID().toString()); + + + pJpgFile.setUploadtime(new Date()); + pJpgFile.Insert(dataSource); + + MDevPictureEntity pupdate = new MDevPictureEntity(); + pupdate.setId(pJpgFile.getId()); + filename = pJpgFile.getId()+".jpg"; + pupdate.setFilename(filename); + uri += "&file="+filename; + pupdate.setUri(uri); + pJpgFile.setFilename(filename); + pJpgFile.setUri(uri); + pupdate.Update(dataSource); + } catch (Exception ee) { + } + + if (base64JPG != null) { + try { + java.util.Base64.Decoder decoder = java.util.Base64.getMimeDecoder(); + byte[] bJpg = decoder.decode(base64JPG); + BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(path + File.separator + filename))); + + out.write(bJpg); + out.flush(); + out.close(); + }catch (IOException e) { + throw new RuntimeException(e); + }finally { + } + } else { + + } + + return pJpgFile.getUri(); + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/behavioral/event/read",method = RequestMethod.POST) + public RespEntity readAIBehavioralEventInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SophgoWarn sophgoWarn = (SophgoWarn)SQLTools.getEntityFromJson(rootnode, SophgoWarn.class); + + if(sophgoWarn==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sophgoWarn.getWarnId()==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + sophgoWarn = (SophgoWarn)sophgoWarn.QueryIt(dataSource); + if(sophgoWarn == null){ + return new RespEntity(RespCode.NOTEXIST); + } + sophgoWarn.setReadState(SophgoWarn.STATE_Read); + sophgoWarn.Update(dataSource); + return new RespEntity(RespCode.SUCCESS, sophgoWarn); + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/ai/behavioral/event/getinfo",method = RequestMethod.POST) + public RespEntity getAIBehavioralEventInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SophgoWarn sophgoWarn = (SophgoWarn)SQLTools.getEntityFromJson(rootnode, SophgoWarn.class); + + if(sophgoWarn==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sophgoWarn.getWarnId()==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + sophgoWarn = (SophgoWarn)sophgoWarn.QueryIt(dataSource); + if(sophgoWarn == null){ + return new RespEntity(RespCode.NOTEXIST); + } +/* + SophgoMetaData metaData = new SophgoMetaData(); + metaData.setWarnId(sophgoWarn.getWarnId()); + metaData = (SophgoMetaData)metaData.QueryIt(dataSource); + + */ + + AISophgoNotify sophgoNotify = new AISophgoNotify(); + sophgoNotify.setWarnData(sophgoWarn, null); + + return new RespEntity(RespCode.SUCCESS, sophgoNotify); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value = "/ai/h5s/getDeviceSummary") + public H5SDeviceSummaryEntity getIpc(HttpServletRequest request) { + String json = HttpTools.getBodyFromRequest(request); + Map map = JSONObject.parseObject(json, Map.class); + String user = map.get("user"); + String password = map.get("password"); + String url = map.get("url"); + if ("".equals(user) || "".equals(password) || null == user || null == password) { + user = "admin"; + password = MD5Tools.md5("?> map1 = JSONObject.parseObject(content1, Map.class); + strSession = map1.get("strSession"); + //System.out.println("strSession=" + strSession); + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (response1 != null) { + // 关闭资源 + response1.close(); + } + // 关闭浏览器 + httpclient1.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + // 创建Httpclient对象,相当于打开了浏览器 + CloseableHttpClient httpclient2 = HttpClients.createDefault(); + String url2 = url+"/api/v1/GetDeviceSummary?session=" + strSession; + + // 创建HttpGet请求,相当于在浏览器输入地址 + HttpGet httpGet2 = new HttpGet(url2); + CloseableHttpResponse response2 = null; + H5SDeviceSummaryEntity deviceSummaryEntity = null; + try { + // 执行请求,相当于敲完地址后按下回车。获取响应 + response2 = httpclient2.execute(httpGet2); + // 判断返回状态是否为200 + if (response2.getStatusLine().getStatusCode() == 200) { + // 解析响应,获取数据 + String content2 = EntityUtils.toString(response2.getEntity(), "UTF-8"); + //System.out.println(content2); + deviceSummaryEntity = JSON.parseObject(String.valueOf(content2), H5SDeviceSummaryEntity.class); + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (response2 != null) { + // 关闭资源 + response2.close(); + } + // 关闭浏览器 + httpclient2.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + return deviceSummaryEntity; + + } + + + @ResponseBody + @RequestMapping(value = "/ai/h5s/devices/state") + public String getH5SDevicesState(HttpServletRequest request) { + String json = HttpTools.getBodyFromRequest(request); + Map map = JSONObject.parseObject(json, Map.class); + String user = map.get("user"); + String password = map.get("password"); + String url = map.get("url"); + if ("".equals(user) || "".equals(password) || null == user || null == password) { + user = "webrtc"; + password = MD5Tools.md5("rtc@139"); + url = "http://101.89.199.154:8080"; + } + password = MD5Tools.md5(password); + + // 创建Httpclient对象,相当于打开了浏览器 + CloseableHttpClient httpclient1 = HttpClients.createDefault(); + + String url1 = url + "/api/v1/Login?user=" + user + "&password=" + password; + String strSession = null; + + // 创建HttpGet请求,相当于在浏览器输入地址 + HttpGet httpGet1 = new HttpGet(url1); + + CloseableHttpResponse response1 = null; + try { + // 执行请求,相当于敲完地址后按下回车。获取响应 + response1 = httpclient1.execute(httpGet1); + // 判断返回状态是否为200 + if (response1.getStatusLine().getStatusCode() == 200) { + // 解析响应,获取数据 + String content1 = EntityUtils.toString(response1.getEntity(), "UTF-8"); + //System.out.println(content1); + Map map1 = JSONObject.parseObject(content1, Map.class); + strSession = map1.get("strSession"); + //System.out.println("strSession=" + strSession); + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (response1 != null) { + // 关闭资源 + response1.close(); + } + // 关闭浏览器 + httpclient1.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + // 创建Httpclient对象,相当于打开了浏览器 + CloseableHttpClient httpclient2 = HttpClients.createDefault(); + + String url2 = url + "/api/v1/GetSrc?session=" + strSession; + + // 创建HttpGet请求,相当于在浏览器输入地址 + HttpGet httpGet2 = new HttpGet(url2); + + CloseableHttpResponse response2 = null; + + String content2 = null; + try { + // 执行请求,相当于敲完地址后按下回车。获取响应 + response2 = httpclient2.execute(httpGet2); + // 判断返回状态是否为200 + if (response2.getStatusLine().getStatusCode() == 200) { + // 解析响应,获取数据 + content2 = EntityUtils.toString(response2.getEntity(), "UTF-8"); + //System.out.println(content2); + + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (response2 != null) { + // 关闭资源 + response2.close(); + } + // 关闭浏览器 + httpclient2.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + return content2; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/AiVoiceController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/AiVoiceController.java new file mode 100644 index 0000000..322cd95 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/AiVoiceController.java @@ -0,0 +1,76 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.complexquery.RFIDResp; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeAlarmEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeRoomEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.voice.AiVoiceReport; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.EChargeAlarmNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +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.sql.DataSource; + +@RestController +@CrossOrigin +public class AiVoiceController { + @Autowired + private DataSource dataSource; + @Autowired + private SensorService sensorService; + @Autowired + private ClientWebsocketManager clientWebsocketManager; + @Autowired + private MessagePublisher messagePublisher; + @Autowired + private IoTCtrlServer ioTCtrlServer; + @ResponseBody + @RequestMapping(value="/school/ai/asr/receiveEvent") + public RFIDResp addEChargeReport(HttpServletRequest request) { + RFIDResp res = new RFIDResp(); + res.setCode(0); + res.setMsg("ok"); + try { + String eventData = HttpTools.getBodyFromRequest(request); + System.out.println("receiveEvent asr: "+ eventData); + AiVoiceReport eChargeAlarm = JSON.parseObject(eventData, AiVoiceReport.class); + + if(eChargeAlarm == null){ + return res; + } + if(eChargeAlarm.getTaskCode() == null || eChargeAlarm.getDeviceId() == null){ + return res; + } + // SensorDeviceEntity roomEntity = SensorDeviceEntity.Query(dataSource, eChargeAlarm.getDeviceId()); + + if(AiVoiceReport.ReportIndicate_Create.equalsIgnoreCase(eChargeAlarm.getReportIndicate())){ + SensorAlarmEventEntity alarmEvent = sensorService.addAlarmPointEvent(eChargeAlarm.getDeviceId()); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(alarmEvent), "/iotserver/sensor/alarm_event/agent"); + } + } + + }catch (Exception e){ + res.setCode(20); + res.setMsg("fail"); + } + return res; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/CitySensorController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/CitySensorController.java new file mode 100644 index 0000000..fa842eb --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/CitySensorController.java @@ -0,0 +1,84 @@ +package com.jingyi.iotserver.firestationport.controller; + + +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.utils.HttpTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +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.sql.DataSource; + +@RestController +@CrossOrigin +public class CitySensorController { + + @Autowired + private DataSource dataSource; + @Autowired + private SensorService sensorService; + + @Autowired + private StationServices stationServices; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + + @ResponseBody + @RequestMapping(value="/citymgr/sensor/uav/state") + public RespEntity addUAVStateInfo(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + System.out.println("UAV rec:" + json); + + /* + CityTruckOrderEntity info = (CityTruckOrderEntity) SQLTools.getEntityFromJson(rootnode, CityTruckOrderEntity.class); + if(info==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(info.getTaskid() == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(info.QueryIt(dataSource)!=null) { + return new RespEntity(RespCode.EXIST); + } + info.setReadstate("unread"); + info.setDeviceid("shpd12345"); + if(!info.Insert(dataSource)){ + return new RespEntity(RespCode.FAIL); + } + + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, info.getDeviceid()); + if (sensor == null) + return new RespEntity(RespCode.NOTEXIST); + + CityTruckOrderNofity notify = new CityTruckOrderNofity(info); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, sensor.getOwner()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(sensor.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + + */ + } catch (Exception e) { + new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/EChargeController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/EChargeController.java new file mode 100644 index 0000000..e6c614d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/EChargeController.java @@ -0,0 +1,693 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.complexquery.RFIDResp; +import com.jingyi.iotserver.firestationport.model.person.PersonLogEntity; +import com.jingyi.iotserver.firestationport.model.person.SecurityPersonEntity; +import com.jingyi.iotserver.firestationport.model.school.PendingProcessItem; +import com.jingyi.iotserver.firestationport.model.school.SchoolColorPoliceCheck; +import com.jingyi.iotserver.firestationport.model.school.SchoolPendingItem; +import com.jingyi.iotserver.firestationport.model.school.SchoolPendingProcessRecordEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.CommunityInfo; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeAlarmEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeBuildingEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeRoomEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.EChargeAlarmNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@RestController +@CrossOrigin +public class EChargeController { + @Autowired + private DataSource dataSource; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + @Autowired + private MessagePublisher messagePublisher; + + @ResponseBody + @RequestMapping(value="/houseDeviceEvent/receiveEvent") + public RFIDResp addEChargeReport(HttpServletRequest request) { + RFIDResp res = new RFIDResp(); + res.setCode(0); + res.setMsg("ok"); + try { + String eventData = HttpTools.getBodyFromRequest(request); + + EChargeAlarmEntity eChargeAlarm = JSON.parseObject(eventData, EChargeAlarmEntity.class); + + if(eChargeAlarm == null){ + return res; + } + if(eChargeAlarm.getSensorId() == null){ + return res; + } + + SensorDeviceEntity sensorDevice = new SensorDeviceEntity(); + sensorDevice.setDeviceid(eChargeAlarm.getSensorId()); + sensorDevice = (SensorDeviceEntity)sensorDevice.QueryIt(dataSource); + if(sensorDevice == null){ + return res; + } + sensorDevice.setStatus(eChargeAlarm.getAlarm()); + sensorDevice.Update(dataSource); + + EChargeRoomEntity roomEntity = new EChargeRoomEntity(); + roomEntity.setRoomId(sensorDevice.getHouseowner()); + roomEntity = (EChargeRoomEntity)roomEntity.QueryIt(dataSource); + if(roomEntity==null){ + return res; + } + + if(EChargeAlarmEntity.ALARM_CHARGE_IN.equalsIgnoreCase(eChargeAlarm.getAlarm())){ + roomEntity.setChargeInCount(roomEntity.getChargeInCount()+1); + roomEntity.setChargeStatus(eChargeAlarm.getAlarm()); + roomEntity.setChargeStatusTime(eChargeAlarm.getTimestamp()); + }else{ + SensorDeviceEntity sensorHouse = new SensorDeviceEntity(); + sensorHouse.setHouseowner(roomEntity.getRoomId()); + List sensorList = sensorHouse.queryList(dataSource, null, null); + boolean roomCharge= false; + for(int iSen = 0; iSen < sensorList.size(); iSen++){ + SensorDeviceEntity chargeObj = (SensorDeviceEntity)sensorList.get(iSen); + if(EChargeAlarmEntity.ALARM_CHARGE_IN.equalsIgnoreCase(chargeObj.getStatus())){ + roomCharge = true; + break; + } + } + if(roomCharge == false){ + roomEntity.setChargeStatus(EChargeAlarmEntity.ALARM_CHARGE_OUT); + roomEntity.setChargeStatusTime(eChargeAlarm.getTimestamp()); + } + } + + roomEntity.Update(dataSource); + + eChargeAlarm.setStation(roomEntity.getStation()); + eChargeAlarm.setDetachment(roomEntity.getDetachment()); + eChargeAlarm.setBorough(roomEntity.getBorough()); + eChargeAlarm.setBrigade(roomEntity.getBrigade()); + eChargeAlarm.setBuildingId(roomEntity.getBuildingId()); + eChargeAlarm.setBuildingName(roomEntity.getBuildingName()); + eChargeAlarm.setRoomId(roomEntity.getRoomId()); + eChargeAlarm.setRoomName(roomEntity.getRoomName()); + eChargeAlarm.setLatitude(roomEntity.getLatitude()); + eChargeAlarm.setLongitude(roomEntity.getLongitude()); + + eChargeAlarm.Insert(dataSource); + + EChargeAlarmNotify notify = new EChargeAlarmNotify(eChargeAlarm); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(eChargeAlarm.getBrigade()); + pro.setBorough(eChargeAlarm.getBorough()); + pro.setDetachment(eChargeAlarm.getDetachment()); + pro.setStation(eChargeAlarm.getStation()); + pro.setDevice_id(eChargeAlarm.getSensorId()); + pro.setDevice_type("tpson"); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("charge_event"); + msg.setData(JSON.toJSONString(eChargeAlarm)); + msg.setTitle("charge"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(eChargeAlarm.getStation(),str); + }catch (Exception e){ + res.setCode(20); + res.setMsg("fail"); + } + return res; + } + + @ResponseBody + @RequestMapping(value="/firectrl/chargeEvent/getlist") + public RespEntity getEChargeEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeAlarmEntity eChargeAlarm = (EChargeAlarmEntity) SQLTools.getEntityFromJson(rootnode,EChargeAlarmEntity.class); + + if(eChargeAlarm==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(eChargeAlarm.getBrigade() == null && eChargeAlarm.getBorough() == null && eChargeAlarm.getDetachment() == null && eChargeAlarm.getStation() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = eChargeAlarm.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/chargeEvent/count") + public RespEntity countEChargeEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeAlarmEntity eChargeAlarm = (EChargeAlarmEntity) SQLTools.getEntityFromJson(rootnode,EChargeAlarmEntity.class); + + if(eChargeAlarm==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(eChargeAlarm.getBrigade() == null && eChargeAlarm.getBorough() == null && eChargeAlarm.getDetachment() == null && eChargeAlarm.getStation() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + int count = eChargeAlarm.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/chargeEvent/read") + public RespEntity readEChargeEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeAlarmEntity eChargeAlarm = (EChargeAlarmEntity) SQLTools.getEntityFromJson(rootnode,EChargeAlarmEntity.class); + + if(eChargeAlarm==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(eChargeAlarm.getAlarmId() == null ){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeAlarmEntity tgtAlarm = (EChargeAlarmEntity)eChargeAlarm.QueryIt(dataSource); + if(tgtAlarm == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(!EChargeAlarmEntity.ALARM_STATE_CLOSED.equalsIgnoreCase(tgtAlarm.getState())){ + tgtAlarm.setState(EChargeAlarmEntity.ALARM_STATE_READ); + tgtAlarm.setReadTime(new Date()); + tgtAlarm.Update(dataSource); + } + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/chargeEvent/close") + public RespEntity closeEChargeEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeAlarmEntity eChargeAlarm = (EChargeAlarmEntity) SQLTools.getEntityFromJson(rootnode,EChargeAlarmEntity.class); + + if(eChargeAlarm==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(eChargeAlarm.getAlarmId() == null ){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeAlarmEntity tgtAlarm = (EChargeAlarmEntity)eChargeAlarm.QueryIt(dataSource); + if(tgtAlarm == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(!EChargeAlarmEntity.ALARM_STATE_CLOSED.equalsIgnoreCase(tgtAlarm.getState())){ + tgtAlarm.setState(EChargeAlarmEntity.ALARM_STATE_CLOSED); + tgtAlarm.setCloseTime(new Date()); + tgtAlarm.Update(dataSource); + } + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + *community api + */ + @ResponseBody + @RequestMapping(value="/firectrl/community/add",method = RequestMethod.POST) + public RespEntity addCommunity(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + CommunityInfo communityInfo = (CommunityInfo) SQLTools.getEntityFromJson(rootnode, CommunityInfo.class); + + if(communityInfo==null||communityInfo.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(communityInfo.getCommunityName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(communityInfo.getCommunityId() == null){ + communityInfo.setCommunityId(UUID.randomUUID().toString()); + } + if(communityInfo.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (!communityInfo.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/update",method = RequestMethod.POST) + public RespEntity updateCommunity(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + CommunityInfo communityInfo = (CommunityInfo) SQLTools.getEntityFromJson(rootnode, CommunityInfo.class); + if(communityInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + CommunityInfo orgtask = (CommunityInfo)communityInfo.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (communityInfo.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/delete",method = RequestMethod.POST) + public RespEntity deleteCommunity(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + CommunityInfo communityInfo = (CommunityInfo) SQLTools.getEntityFromJson(rootnode,CommunityInfo.class); + if(communityInfo==null||communityInfo.getCommunityId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + CommunityInfo tgtCommunity = (CommunityInfo)communityInfo.QueryIt(dataSource); + if(tgtCommunity == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(tgtCommunity.Delete(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/count",method = RequestMethod.POST) + public RespEntity getCommunityCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + CommunityInfo communityInfo = (CommunityInfo) SQLTools.getEntityFromJson(rootnode,CommunityInfo.class); + + if(communityInfo==null) + communityInfo = new CommunityInfo(); + int count = communityInfo.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS, reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/getlist",method = RequestMethod.POST) + public RespEntity getCommunityList(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + CommunityInfo communityInfo = (CommunityInfo) SQLTools.getEntityFromJson(rootnode,CommunityInfo.class); + + if(communityInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(communityInfo.getBrigade()==null && communityInfo.getBorough()== null && communityInfo.getDetachment() == null && communityInfo.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = communityInfo.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + //building api + @ResponseBody + @RequestMapping(value="/firectrl/community/building/add",method = RequestMethod.POST) + public RespEntity addCommunityBuilding(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeBuildingEntity buildingEntity = (EChargeBuildingEntity) SQLTools.getEntityFromJson(rootnode, EChargeBuildingEntity.class); + + if(buildingEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(buildingEntity.getBuildingName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(buildingEntity.getBuildingId() == null){ + buildingEntity.setBuildingId(UUID.randomUUID().toString()); + } + if(buildingEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + + if(buildingEntity.getCommunityId() != null){ + CommunityInfo tgtCommunity = new CommunityInfo(); + tgtCommunity.setCommunityId(buildingEntity.getCommunityId()); + tgtCommunity = (CommunityInfo)tgtCommunity.QueryIt(dataSource); + if(tgtCommunity != null){ + buildingEntity.setCommunityName(tgtCommunity.getCommunityName()); + buildingEntity.setStation(tgtCommunity.getStation()); + buildingEntity.setDetachment(tgtCommunity.getDetachment()); + buildingEntity.setBorough(tgtCommunity.getBorough()); + buildingEntity.setBrigade(tgtCommunity.getBrigade()); + } + } + + if (!buildingEntity.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/building/update",method = RequestMethod.POST) + public RespEntity updateCommunityBuilding(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeBuildingEntity buildingEntity = (EChargeBuildingEntity) SQLTools.getEntityFromJson(rootnode, EChargeBuildingEntity.class); + if(buildingEntity==null||buildingEntity.getBuildingId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeBuildingEntity oldBuilding = (EChargeBuildingEntity)buildingEntity.QueryIt(dataSource); + if(oldBuilding==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(buildingEntity.getCommunityId() != null){ + CommunityInfo tgtCommunity = new CommunityInfo(); + tgtCommunity.setCommunityId(buildingEntity.getCommunityId()); + tgtCommunity = (CommunityInfo)tgtCommunity.QueryIt(dataSource); + if(tgtCommunity != null){ + buildingEntity.setCommunityName(tgtCommunity.getCommunityName()); + buildingEntity.setStation(tgtCommunity.getStation()); + buildingEntity.setDetachment(tgtCommunity.getDetachment()); + buildingEntity.setBorough(tgtCommunity.getBorough()); + buildingEntity.setBrigade(tgtCommunity.getBrigade()); + } + } + if (buildingEntity.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/building/delete",method = RequestMethod.POST) + public RespEntity deleteCommunityBuilding(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeBuildingEntity buildingEntity = (EChargeBuildingEntity) SQLTools.getEntityFromJson(rootnode,EChargeBuildingEntity.class); + if(buildingEntity==null||buildingEntity.getBuildingId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeBuildingEntity oldBuilding = (EChargeBuildingEntity)buildingEntity.QueryIt(dataSource); + if(oldBuilding == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(oldBuilding.Delete(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/building/count",method = RequestMethod.POST) + public RespEntity getCommunityBuildingCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeBuildingEntity buildingEntity = (EChargeBuildingEntity) SQLTools.getEntityFromJson(rootnode,EChargeBuildingEntity.class); + + if(buildingEntity==null) + buildingEntity = new EChargeBuildingEntity(); + int count = buildingEntity.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS, reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/building/getlist",method = RequestMethod.POST) + public RespEntity getCommunityBuildingList(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeBuildingEntity buildingEntity = (EChargeBuildingEntity) SQLTools.getEntityFromJson(rootnode,EChargeBuildingEntity.class); + + if(buildingEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(buildingEntity.getBrigade()==null && buildingEntity.getBorough()== null && buildingEntity.getDetachment() == null && buildingEntity.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = buildingEntity.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + //room api + @ResponseBody + @RequestMapping(value="/firectrl/community/room/add",method = RequestMethod.POST) + public RespEntity addCommunityRoom(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeRoomEntity roomEntity = (EChargeRoomEntity) SQLTools.getEntityFromJson(rootnode, EChargeRoomEntity.class); + + if(roomEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(roomEntity.getRoomName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(roomEntity.getRoomId() == null){ + roomEntity.setRoomId(UUID.randomUUID().toString()); + } + if(roomEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + + if(roomEntity.getBuildingId() != null){ + EChargeBuildingEntity tgtBuilding = new EChargeBuildingEntity(); + tgtBuilding.setBuildingId(roomEntity.getBuildingId()); + tgtBuilding = (EChargeBuildingEntity)tgtBuilding.QueryIt(dataSource); + if(tgtBuilding != null){ + roomEntity.setCommunityName(tgtBuilding.getCommunityName()); + roomEntity.setCommunityId(tgtBuilding.getCommunityId()); + roomEntity.setBuildingName(tgtBuilding.getBuildingName()); + roomEntity.setStation(tgtBuilding.getStation()); + roomEntity.setDetachment(tgtBuilding.getDetachment()); + roomEntity.setBorough(tgtBuilding.getBorough()); + roomEntity.setBrigade(tgtBuilding.getBrigade()); + + if(roomEntity.getLatitude() == 0){ + roomEntity.setLatitude(tgtBuilding.getLatitude()); + } + if(roomEntity.getLongitude() == 0){ + roomEntity.setLongitude(tgtBuilding.getLongitude()); + } + } + } + + if (!roomEntity.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/room/update",method = RequestMethod.POST) + public RespEntity updateCommunityRoom(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeRoomEntity roomEntity = (EChargeRoomEntity) SQLTools.getEntityFromJson(rootnode, EChargeRoomEntity.class); + if(roomEntity==null||roomEntity.getRoomId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeRoomEntity oldRoom = (EChargeRoomEntity)roomEntity.QueryIt(dataSource); + if(oldRoom==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(roomEntity.getBuildingId() != null){ + CommunityInfo tgtCommunity = new CommunityInfo(); + tgtCommunity.setCommunityId(roomEntity.getCommunityId()); + tgtCommunity = (CommunityInfo)tgtCommunity.QueryIt(dataSource); + if(tgtCommunity != null){ + roomEntity.setCommunityName(tgtCommunity.getCommunityName()); + roomEntity.setStation(tgtCommunity.getStation()); + roomEntity.setDetachment(tgtCommunity.getDetachment()); + roomEntity.setBorough(tgtCommunity.getBorough()); + roomEntity.setBrigade(tgtCommunity.getBrigade()); + } + } + roomEntity.setChargeStatus(null); + roomEntity.setChargeStatusTime(null); + if (roomEntity.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/room/delete",method = RequestMethod.POST) + public RespEntity deleteCommunityRoom(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeRoomEntity roomEntity = (EChargeRoomEntity) SQLTools.getEntityFromJson(rootnode,EChargeRoomEntity.class); + if(roomEntity==null||roomEntity.getRoomId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeRoomEntity oldRoom = (EChargeRoomEntity)roomEntity.QueryIt(dataSource); + if(oldRoom == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(oldRoom.Delete(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/room/count",method = RequestMethod.POST) + public RespEntity getCommunityRoomCount(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + EChargeRoomEntity roomEntity = (EChargeRoomEntity) SQLTools.getEntityFromJson(rootnode,EChargeRoomEntity.class); + + if(roomEntity==null) + roomEntity = new EChargeRoomEntity(); + int count = roomEntity.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS, reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/room/getlist",method = RequestMethod.POST) + public RespEntity getCommunityRoomList(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeRoomEntity roomEntity = (EChargeRoomEntity) SQLTools.getEntityFromJson(rootnode,EChargeRoomEntity.class); + + if(roomEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(roomEntity.getBrigade()==null && roomEntity.getBorough()== null && roomEntity.getDetachment() == null && roomEntity.getStation()==null && roomEntity.getRoomId()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = roomEntity.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/firectrl/community/room/reset",method = RequestMethod.POST) + public RespEntity resetRoomChargeState(HttpServletRequest request) { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + EChargeRoomEntity roomEntity = (EChargeRoomEntity) SQLTools.getEntityFromJson(rootnode, EChargeRoomEntity.class); + if(roomEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(roomEntity.getRoomId()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + EChargeRoomEntity oldRoom = (EChargeRoomEntity)roomEntity.QueryIt(dataSource); + if(oldRoom==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + roomEntity.setChargeStatus("charge.out"); + roomEntity.setChargeStatusTime(new Date()); + if (roomEntity.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlAIIPCClientController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlAIIPCClientController.java new file mode 100644 index 0000000..21f3a34 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlAIIPCClientController.java @@ -0,0 +1,306 @@ +package com.jingyi.iotserver.firestationport.controller; + + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.AIIPCConfig; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.*; +import com.jingyi.iotserver.iotctrl.IoTCtrlMessage; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.List; + +@RestController +@CrossOrigin +public class FireCtrlAIIPCClientController { + @Autowired + private DataSource dataSource; + @Autowired + private IoTCtrlServer ioTCtrlServer; + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getmatchfaceeventcount",method = RequestMethod.POST) + public RespEntity getAIIPCMatchFaceEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + AIIPCMatchFaceEventEntity event = (AIIPCMatchFaceEventEntity) SQLTools.getEntityFromJson(rootnode, AIIPCMatchFaceEventEntity.class); + if(event==null) + event = new AIIPCMatchFaceEventEntity(); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getmatchfaceeventlist",method = RequestMethod.POST) + public RespEntity getAIIPCMatchFaceEventPage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + AIIPCMatchFaceEventEntity event = (AIIPCMatchFaceEventEntity) SQLTools.getEntityFromJson(rootnode, AIIPCMatchFaceEventEntity.class); + if(event==null) + event = new AIIPCMatchFaceEventEntity(); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getmatchcarplateeventcount",method = RequestMethod.POST) + public RespEntity getAIIPCMatchCarplateEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + + AIIPCMatchCarPlateEventEntity event = (AIIPCMatchCarPlateEventEntity) SQLTools.getEntityFromJson(rootnode, AIIPCMatchCarPlateEventEntity.class); + if(event==null) + event = new AIIPCMatchCarPlateEventEntity(); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getmatchcarplateeventlist",method = RequestMethod.POST) + public RespEntity getAIIPCMatchCarplateEventPage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + AIIPCMatchCarPlateEventEntity event = (AIIPCMatchCarPlateEventEntity) SQLTools.getEntityFromJson(rootnode, AIIPCMatchCarPlateEventEntity.class); + if(event==null) + event = new AIIPCMatchCarPlateEventEntity(); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getstatuscount",method = RequestMethod.POST) + public RespEntity getAIIPCStatusCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + + AIIPCStatusEntity event = (AIIPCStatusEntity) SQLTools.getEntityFromJson(rootnode, AIIPCStatusEntity.class); + if(event==null) + event = new AIIPCStatusEntity(); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getstatuslist",method = RequestMethod.POST) + public RespEntity getAIIPCStatusPage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + AIIPCStatusEntity event = (AIIPCStatusEntity) SQLTools.getEntityFromJson(rootnode, AIIPCStatusEntity.class); + if(event==null) + event = new AIIPCStatusEntity(); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/config",method = RequestMethod.POST) + public RespEntity AIIPCConfig(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + AIIPCSettingEntity setting = (AIIPCSettingEntity) SQLTools.getEntityFromJson(rootnode, AIIPCSettingEntity.class); + if(setting==null) + return new RespEntity(RespCode.ERROR_REQUEST); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,setting.getDeviceid()); + if(sensor == null) + return new RespEntity(RespCode.NOTEXIST); + + JsonNode subobj = JsonHelper.getLevel2(rootnode,"eventsetting"); + if(subobj!=null&&subobj.isArray()){ + List list = SQLTools.getEntityListFromJsonArray(subobj,AIIPCEventSettingEntity.class); + if(list!=null&&list.size()>0) { + for (AIIPCEventSettingEntity set : list) { + if(set.QueryIt(dataSource)==null){ + set.Insert(dataSource); + }else{ + set.Update(dataSource); + } + } + } + } + + subobj = JsonHelper.getLevel2(rootnode,"textmatchsetting"); + if(subobj!=null&&subobj.isArray()){ + List list = SQLTools.getEntityListFromJsonArray(subobj,AIIPCTextMatchSettingEntity.class); + if(list!=null&&list.size()>0) { + for (AIIPCTextMatchSettingEntity set : list) { + if(set.QueryIt(dataSource)==null){ + set.Insert(dataSource); + }else{ + set.Update(dataSource); + } + } + } + } + + IoTCtrlMessage iotmsg = new IoTCtrlMessage(); + iotmsg.setDeviceid(setting.getDeviceid()); + iotmsg.setDevicetype(sensor.getDevicetype()); + iotmsg.setTimestamp(System.currentTimeMillis()/1000); + iotmsg.setMsgname("congfig-change"); + iotmsg.setMsgtype("request"); + iotmsg.setMessage(""); + String cmd = JsonHelper.convertObjectToStr(iotmsg); + byte [] data = cmd.getBytes(); + + if(ioTCtrlServer.SendDataToIotCtrl(data)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/getconfig",method = RequestMethod.POST) + public RespEntity getAIIPCConfig(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String deviceid = JsonHelper.getStringValue(rootnode, "deviceid"); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,deviceid); + if(sensor == null) + return new RespEntity(RespCode.NOTEXIST); + + AIIPCConfig config = new AIIPCConfig(); + config.setDeviceid(deviceid); + + AIIPCSettingEntity setting = new AIIPCSettingEntity(); + setting.setDeviceid(deviceid); + setting = (AIIPCSettingEntity)setting.QueryIt(dataSource); + if(setting==null){ + setting = new AIIPCSettingEntity(); + setting.setDeviceid(deviceid); + setting.setHeartbeat(180); + setting.setServeraddr("118.190.86.237"); + setting.setPort(9019); + setting.setImageuploadaddr("https://www.genetek.cc:8083/firectrl/file/aiipc/upload"); + } + config.setSetting(setting); + + AIIPCEventSettingEntity eventset = new AIIPCEventSettingEntity(); + eventset.setDeviceid(deviceid); + List list = eventset.queryList(dataSource,null,null); + config.setEventsetting(list); + + AIIPCPictureMatchSettingEntity picset = new AIIPCPictureMatchSettingEntity(); + picset.setDeviceid(deviceid); + list = picset.queryList(dataSource,null,null); + config.setPicturematchsetting(list); + + AIIPCTextMatchSettingEntity txtset = new AIIPCTextMatchSettingEntity(); + txtset.setDeviceid(deviceid); + list = txtset.queryList(dataSource,null,null); + config.setTextmatchsetting(list); + + return new RespEntity(RespCode.SUCCESS,config); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlClientLoginController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlClientLoginController.java new file mode 100644 index 0000000..185c370 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlClientLoginController.java @@ -0,0 +1,218 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.IOrganizationOperate; +import com.jingyi.iotserver.clientmanage.IUserOperate; +import com.jingyi.iotserver.clientmanage.model.*; +import com.jingyi.iotserver.common.configuration.DruidDataSourceConfig; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.clientmanage.UserService; +import com.jingyi.iotserver.firestationport.services.DatabaseTransfer; +import com.jingyi.iotserver.firestationport.services.userman.UserAccess; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.utils.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.sql.DataSource; +import java.util.List; + +//https://blog.csdn.net/huang906391/article/details/78376766 +//https://blog.csdn.net/likeyjs/article/details/80525042 + +//https://www.jianshu.com/p/43c97352aa1e + + +//httpsession https://www.cnblogs.com/diewufeixian/p/4221747.html +//httpsession https://www.cnblogs.com/zhaoYuQing-java2015/p/4621384.html + +@RestController +@CrossOrigin +public class FireCtrlClientLoginController { + @Autowired + private DataSource dataSource; + + @Autowired + private UserService userService; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private DatabaseTransfer databaseTransfer; + + @ResponseBody + @RequestMapping(value = "/user/login", method = RequestMethod.POST) + public RespEntity appLogin(HttpServletRequest request, HttpServletResponse response, @CookieValue(value = "token", required = false) String token) { + RespEntity rel = null; + String user = "monsensora"; + String pwd = "9pt2qug7"; + String url = "http://125.74.48.82:8082/user/login"; + String appkey = "fbc8210c-2e59-4767-8c6c-5f013c85a137"; + String screct = "381dba50a848e60de2dbdd642e1e3956"; +/* + GUIDUtil guid = new GUIDUtil(); + String appkey = guid.GeneralAppkey(); + String screct = guid.GenreralScerect(appkey); + System.out.println(appkey+" "+scerect); + */ + return new RespEntity(RespCode.SUCCESS); + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/user/agentlogin",method = RequestMethod.POST) + public RespEntity userAgentLogin(HttpServletRequest request, HttpServletResponse response, @CookieValue(value = "token", required = false) String token) { + RespEntity rel = null; + try{ + String json = HttpTools.getBodyFromRequest(request); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_CMD); + } + String name = JsonHelper.getStringValue(rootnode,"name"); + String password = JsonHelper.getStringValue(rootnode,"password"); + if(name==null){ + return new RespEntity(RespCode.USER_PWD_ERROR); + } + + UserInfoEntity user = new UserInfoEntity(); + user.setName(name); + user = (UserInfoEntity)user.QueryIt(dataSource); + if(name.equals("administrator")){ + user = new UserInfoEntity(); + user.setUsertype("super"); + user.setName("administrator"); + user.setScopelevel("master"); + String adminpwd = MD5Tools.md5(envConfigService.getSuperPassword()); + user.setPassword(MD5Tools.md5("firectrl"+name+adminpwd)); + } + if(user==null) + return new RespEntity(RespCode.USER_PWD_ERROR); + + String pwd = MD5Tools.md5("firectrl"+name+password); + + if(!pwd.equals(user.getPassword())){ + return new RespEntity(RespCode.USER_PWD_ERROR); + } + + + LoginResultEntity result = new LoginResultEntity(); + result.setSession(user.getUserrole()); + + OrganizationInfoEntity org; + if(user.IsSuper()) { + org = new OrganizationInfoEntity(); + org.setOrgname("iotserver"); + org.setBrigade("all"); + org.setDetachment("all"); + org.setAddress("China"); + org.setCity("China"); + }else{ + org = new OrganizationInfoEntity(); + org.setOrgname(user.getOrgname()); + org = (OrganizationInfoEntity)org.QueryIt(dataSource); + } + result.setOrganize(org); + result.setUsertype(user.getUsertype()); + result.setScopelevel(user.getScopelevel()); + result.setLevelvalue(user.getLevelvalue()); + // result.setUserinfo(user); + return new RespEntity(RespCode.SUCCESS,result); + }catch (Exception e){ + e.printStackTrace(); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/user/active",method = RequestMethod.POST) + public RespEntity userHeartBeat(HttpServletRequest request) { + return new RespEntity(RespCode.SUCCESS); + } + + private RespEntity executeOperateOnUser(HttpServletRequest request,IUserOperate op) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + UserInfoEntity userinfo = (UserInfoEntity)SQLTools.getEntityFromJson(rootnode,UserInfoEntity.class); + if(userinfo==null||userinfo.getName()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + return op.ExecuteOperate(userinfo,rootnode); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/user/hastaskauthor",method = RequestMethod.POST) + public RespEntity hasTaskAuthotity(HttpServletRequest request) { + RespEntity rel = null; + try { + + if(userAuthorManager.IsAdmin(request)||userAuthorManager.IsSuper(request)) + return new RespEntity(RespCode.SUCCESS); + if(userAuthorManager.checkUserAuthor(request.getHeader("authorization"),"firectrl.client.user.sendtask")) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } catch (Exception e) { + + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/user/hasnotifyauthor",method = RequestMethod.POST) + public RespEntity hasNotifyAuthotity(HttpServletRequest request) { + RespEntity rel = null; + try { + if(userAuthorManager.IsAdmin(request)||userAuthorManager.IsSuper(request)) + return new RespEntity(RespCode.SUCCESS); + if(userAuthorManager.checkUserAuthor(request.getHeader("authorization"),"firectrl.client.user.sendnotify")) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } catch (Exception e) { + + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/test/db",method = RequestMethod.POST) + public RespEntity dbtest(HttpServletRequest request) { + RespEntity rel = null; + try { + // DruidDataSourceConfig config = (DruidDataSourceConfig)SpringContextUtil.getBean(DruidDataSourceConfig.class); + // DataSource ds = config.getMySqlDataSource(); + // UserInfoEntity user = UserInfoEntity.QueryUser(ds,"administrator"); + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String name = JsonHelper.getStringValue(rootnode,"name"); + if(databaseTransfer.startTrans(name)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } catch (Exception e) { + + } + return new RespEntity(RespCode.FAIL); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlDataAnalyzeController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlDataAnalyzeController.java new file mode 100644 index 0000000..436b896 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlDataAnalyzeController.java @@ -0,0 +1,611 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.UserService; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallAckEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.*; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.*; + +@RestController +@CrossOrigin +public class FireCtrlDataAnalyzeController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private UserService userService; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private SensorService sensorService; + @ResponseBody + @RequestMapping(value="/firectrl/client/analyze/rollcallack",method = RequestMethod.POST) + public RespEntity roolcallAckAnalyze(HttpServletRequest request) { + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/analyze/stationonline",method = RequestMethod.POST) + public RespEntity stationOnlineAnalyze(HttpServletRequest request) { + RespEntity rel = null; + + ArrayList rellist = new ArrayList(); + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + if(station==null) + return new RespEntity(RespCode.EXCEPTION); + JsonNode timearray = JsonHelper.getLevel2(rootnode,"time"); + if(!timearray.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i rellist = new ArrayList(); + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode!=null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode, FireStationBaseInfoEntity.class); + if (station == null) + return new RespEntity(RespCode.EXCEPTION); + JsonNode timearray = JsonHelper.getLevel2(rootnode, "time"); + if (!timearray.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + + for(int i=0;i reportlist = new ArrayList(); + FireStationRollCallEntity rollentity = null; + if (username != null) { + rollentity = new FireStationRollCallEntity(); + rollentity.setUsername(username); + } + for(int i=0;i rollcalllist = rollentity.queryPage(dataSource,startstr, endstr, 0, 1024); + + if (scopenode != null && rollcalllist != null) { + //remove rollcall out scope + List rmlist = new ArrayList(); + List list = SQLTools.getEntityListFromJsonArray(scopenode, FireStationBaseInfoEntity.class); + if (list != null && list.size() > 0) { + for (SQLDataObject ob : rollcalllist) { + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)ob; + if (rollcall != null) { + try { + boolean rm = true; + String scope = rollcall.getScope(); + JsonNode rollscopelist = JsonHelper.parseBodyLevel1(scope); + List rolllist = SQLTools.getEntityListFromJsonArray(rollscopelist, FireStationBaseInfoEntity.class); + for (FireStationBaseInfoEntity userscope : list) { + if (userscope != null) { + for (FireStationBaseInfoEntity roll : rolllist) { + if (roll != null) { + if (userscope.checkScope(roll)) { + rm = false; + break; + } + } + } + if(!rm) + break; + } + } + + if (rm) + rmlist.add(rollcall); + } catch (Exception e) { + + } + } + } + for (FireStationRollCallEntity rollcall : rmlist) { + if (rollcall != null) + rollcalllist.remove(rollcall); + } + } + } + + RollcallReportForm report = new RollcallReportForm(); + HashMap stationrollcallmap = new HashMap(); + if (rollcalllist == null || rollcalllist.size() <= 0) { + report.setRollcall(0); + report.setAck(0); + report.setIgnore(0); + report.setExpect(0); + report.setRanking(null); + report.setIndex(index); + reportlist.add(report); + continue; + } + report.setRollcall(rollcalllist.size()); + for (SQLDataObject ob : rollcalllist) { + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)ob; + String scopejson = rollcall.getScope(); + + try { + JsonNode scopelist = JsonHelper.parseBodyLevel1(scopejson); + List list = SQLTools.getEntityListFromJsonArray(scopelist, FireStationBaseInfoEntity.class); + try { + int count = stationServices.queryStationCountByScope(list); + if (count > 0) + stationcount += count; + } catch (Exception e) { + + } + + FireStationRollCallAckEntity ackEntity = new FireStationRollCallAckEntity(); + int pageindex = 0; + int pagesize = 512; + ackEntity.setRollcallnumber(rollcall.getNumber()); + List acklist = null; + do { + acklist = stationServices.queryRollCallAckList(ackEntity, null, null, pagesize, pageindex); + pageindex++; + if (acklist == null) + break; + for (SQLDataObject oback : acklist) { + FireStationRollCallAckEntity ack = (FireStationRollCallAckEntity)oback; + StationRollcallCounter counter = stationrollcallmap.get(ack.getStationname()); + if (counter == null) { + counter = new StationRollcallCounter(); + counter.setName(ack.getStationname()); + if (ack.getState().equals("ack")) { + counter.setAck(1); + counter.setIgnore(0); + } else { + counter.setAck(0); + counter.setIgnore(1); + } + stationrollcallmap.put(counter.getName(), counter); + } else { + if (ack.getState().equals("ack")) { + counter.setAck(counter.getAck() + 1); + } else { + counter.setIgnore(counter.getIgnore() + 1); + } + } + } + } while (acklist != null && acklist.size() >= pagesize); + } catch (Exception e) { + + } + } + + + ArrayList ranking = new ArrayList(); + + for (Map.Entry entry : stationrollcallmap.entrySet()) { + StationRollcallCounter info = entry.getValue(); + if (info != null) { + report.setAck(report.getAck() + info.getAck()); + report.setIgnore(report.getIgnore() + info.getIgnore()); + ranking.add(info); + } + } + //Collections.sort(ranking, Collections.reverseOrder()); + Collections.sort(ranking); + report.setRanking(ranking); + report.setExpect(stationcount); + report.setIndex(index); + reportlist.add(report); + + } catch (Exception e) { + + } + + } + return new RespEntity(RespCode.SUCCESS, reportlist); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/analyze/stationonlinecount",method = RequestMethod.POST) + public RespEntity stationOnlineCountAnalyze(HttpServletRequest request) { + RespEntity rel = null; + + ArrayList rellist = new ArrayList(); + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + if(station==null) + return new RespEntity(RespCode.EXCEPTION); + try { + JsonNode times = JsonHelper.getLevel2(rootnode, "time"); + if(times==null||!times.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i rellist = new ArrayList(); + ArrayList stationnamelist = new ArrayList(); + ArrayList tslist = new ArrayList(); + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + if(station==null) + return new RespEntity(RespCode.EXCEPTION); + List stationlist = null; + int pageindex = 0; + do { + stationlist = stationServices.queryStationList(station, 1000, pageindex); + if(stationlist!=null){ + for(SQLDataObject ob:stationlist) { + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity) ob; + stationnamelist.add(s.getName()); + } + } + pageindex++; + }while(stationlist!=null&&stationlist.size()>=1000); + + + JsonNode timearray = JsonHelper.getLevel2(rootnode,"time"); + if(!timearray.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i stationnamelist = new ArrayList(); + ArrayList rellist = new ArrayList(); + ArrayList tplist = new ArrayList(); + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + if(station==null) + return new RespEntity(RespCode.EXCEPTION); + List stationlist = null; + int pageindex = 0; + do { + stationlist = stationServices.queryStationList(station, 1000, pageindex); + if(stationlist!=null){ + for(SQLDataObject ob:stationlist){ + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + stationnamelist.add(s.getName()); + } + + } + pageindex++; + }while(stationlist!=null&&stationlist.size()>=1000); + + + JsonNode timearray = JsonHelper.getLevel2(rootnode,"time"); + if(!timearray.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i stationnamelist = new ArrayList(); + + HashMap resultmap = new HashMap(); + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode, FireStationBaseInfoEntity.class); + if (station == null) + return new RespEntity(RespCode.EXCEPTION); + + List stationlist = null; + int pageindex = 0; + do { + stationlist = stationServices.queryStationList(station, 1000, pageindex); + if(stationlist!=null){ + for(SQLDataObject ob:stationlist) { + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + stationnamelist.add(s.getName()); + } + } + pageindex++; + }while(stationlist!=null&&stationlist.size()>=1000); + + for(String sn:stationnamelist){ + List list = SensorDeviceEntity.QueryByOwner(dataSource,sn); + if(list==null||list.size()<=0) + continue; + + for(SensorDeviceEntity sensor:list){ + + if(sensor==null) + continue; + + SensorStatusCount statuscount = resultmap.get(sensor.getDevicetype()); + if(statuscount==null){ + statuscount = new SensorStatusCount(); + resultmap.put(sensor.getDevicetype(),statuscount); + statuscount.setType(sensor.getDevicetype()); + } + statuscount.total++; + if(sensor.getEnableuse()!=null&&sensor.getEnableuse().equals("use")){ + String status = sensor.getStatus(); + if(status==null){ + statuscount.unknown++; + }else if(status.equals("normal")){ + statuscount.normal++; + }else if(status.equals("alarm")){ + statuscount.alarm++; + }else if(status.equals("broken")){ + statuscount.broken++; + }else { + statuscount.unknown++; + } + }else{ + statuscount.unused++; + } + } + } + } + + ArrayList rellist = new ArrayList(); + for(Map.Entry entry: resultmap.entrySet()){ + rellist.add(entry.getValue()); + } + rel = new RespEntity(RespCode.SUCCESS,rellist); + } catch (Exception e) { + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlFileController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlFileController.java new file mode 100644 index 0000000..8a8461b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlFileController.java @@ -0,0 +1,379 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCPictureMatchSettingEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCTextMatchSettingEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationMapInfoEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import java.io.*; +import java.net.URLEncoder; + +@RestController +@CrossOrigin +public class FireCtrlFileController { + @Autowired + private DataSource dataSource; + ///https://www.genetek.cc:8083/firectrl/file/download?fileName=log_jyiot.log + @RequestMapping("/firectrl/file/download") + public void download(String fileName, HttpServletRequest request, HttpServletResponse response) throws Exception { + //获取文件的绝对路径 + String realPath = request.getSession().getServletContext().getRealPath("upload"); + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File("./logs", fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + //动态设置响应类型,根据前台传递文件类型设置响应类型 + response.setContentType(request.getSession().getServletContext().getMimeType(extendFileName)); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(fileName,"UTF-8")); + //获取输出流对象(用于写文件) + ServletOutputStream os = response.getOutputStream(); + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,os); + + } + + ///https://www.genetek.cc:8083/firectrl/file/aiipc/download?deviceid=t123456&channel=IPC0&fileName=test1.jpg + @RequestMapping(value="/firectrl/file/aiipc/download") + public void downloadAIIPC(String deviceid,String channel,String fileName,HttpServletRequest request, HttpServletResponse response) throws Exception { + String path = "./aiipc"; + + if(deviceid!=null&&deviceid.length()>0) + path += "/"+deviceid; + if(channel!=null&&channel.length()>0) + path += "/"+channel; + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File(path, fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + //动态设置响应类型,根据前台传递文件类型设置响应类型 + response.setContentType(request.getSession().getServletContext().getMimeType(extendFileName)); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(fileName,"UTF-8")); + //获取输出流对象(用于写文件) + ServletOutputStream os = response.getOutputStream(); + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,os); + + } + + @RequestMapping(value="/firectrl/file/aiipc/matchpicture") + public void downloadAIIPCMatchPic(String deviceid,String channel,String fileName,HttpServletRequest request, HttpServletResponse response) throws Exception { + String path = "./aiipc"; + + if(deviceid!=null&&deviceid.length()>0) + path += "/"+deviceid; + if(channel!=null&&channel.length()>0) + path += "/"+channel; + path += "/match"; + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File(path, fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + //动态设置响应类型,根据前台传递文件类型设置响应类型 + response.setContentType(request.getSession().getServletContext().getMimeType(extendFileName)); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(fileName,"UTF-8")); + //获取输出流对象(用于写文件) + ServletOutputStream os = response.getOutputStream(); + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,os); + + } + + @ResponseBody + @RequestMapping(value = "/firectrl/file/aiipc/upload", method = RequestMethod.POST) + public RespEntity uploadFile(@RequestParam("jsondata") String jsondata,@RequestParam("file") MultipartFile file) { + String path = "./aiipc"; + String fileName = file.getOriginalFilename();//获取文件名 + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + + // if (!jsondata.isEmpty()) + { + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1( new String( jsondata.getBytes(),"UTF-8")); + if (rootnode != null) { + String deviceid = JsonHelper.getStringValue(rootnode,"id"); + if(deviceid!=null&&deviceid.length()>0) + path += "/"+deviceid; + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + String channel = JsonHelper.getStringValue(rootnode,"channel"); + if(channel!=null&&channel.length()>0) + path += "/"+channel; + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + } + } catch (Exception ee) { + return new RespEntity(RespCode.NOTEXIST); + } + }/* else { + return new RespEntity(RespCode.EXCEPTION); + }*/ + + if (!file.isEmpty()) { + + try { + InputStream ins = file.getInputStream(); + + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(new File(path + File.separator + fileName))); + + byte[] buffer = new byte[128*1024]; + int len = 0; + while((len = ins.read(buffer)) != -1) { + out.write(buffer,0,len); + } + out.flush(); + out.close(); + return new RespEntity(RespCode.SUCCESS); + } catch (FileNotFoundException e) { + return new RespEntity(RespCode.NOTEXIST); + } catch (IOException e) { + return new RespEntity(RespCode.EXCEPTION); + } + } else { + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value = "/firectrl/file/aiipc/uploadmatchpic", method = RequestMethod.POST) + public RespEntity uploadMatchPicture(@RequestParam("jsondata") String jsondata,@RequestParam("file") MultipartFile file) { + String path = "./aiipc"; + String fileName = file.getOriginalFilename();//获取文件名 + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + AIIPCPictureMatchSettingEntity setting = null ; + // if (!jsondata.isEmpty()) + { + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1( new String( jsondata.getBytes(),"UTF-8")); + if (rootnode != null) { + setting = (AIIPCPictureMatchSettingEntity) SQLTools.getEntityFromJson(rootnode, AIIPCPictureMatchSettingEntity.class); + + if(setting.getDeviceid()==null||setting.getDeviceid().length()<=0|| + setting.getChannel()==null||setting.getChannel().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,setting.getDeviceid()); + if(sensor == null) + return new RespEntity(RespCode.NOTEXIST); + + path += "/"+setting.getDeviceid(); + dir = new File(path); + if(!dir.exists()) + dir.mkdir(); + path += "/"+setting.getChannel(); + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + path += "/match"; + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + + setting.setImage(fileName); + setting.setImage(path+"/"+fileName); + } + } catch (Exception ee) { + return new RespEntity(RespCode.NOTEXIST); + } + }/* else { + return new RespEntity(RespCode.EXCEPTION); + }*/ + + if(setting.QueryIt(dataSource)!=null) + return new RespEntity(RespCode.EXIST); + + setting.setTimestamp(System.currentTimeMillis()/1000); + if (!file.isEmpty()) { + + try { + InputStream ins = file.getInputStream(); + + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(new File(path + File.separator + fileName))); + + byte[] buffer = new byte[128*1024]; + int len = 0; + while((len = ins.read(buffer)) != -1) { + out.write(buffer,0,len); + } + out.flush(); + out.close(); + setting.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS,setting); + } catch (FileNotFoundException e) { + return new RespEntity(RespCode.NOTEXIST); + } catch (IOException e) { + return new RespEntity(RespCode.EXCEPTION); + } + } else { + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value = "/firectrl/file/stationmap/upload", method = RequestMethod.POST) + public RespEntity uploadStationMapFile(@RequestParam("jsondata") String jsondata,@RequestParam("file") MultipartFile file) { + String path = "./stationmap"; + String fileName = file.getOriginalFilename();//获取文件名 + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + + // if (!jsondata.isEmpty()) + { + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1( new String( jsondata.getBytes(),"UTF-8")); + if (rootnode != null) { + FireStationMapInfoEntity map = (FireStationMapInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationMapInfoEntity.class); + if(map==null||map.getStation()==null||map.getMapid()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(map.QueryIt(dataSource)!=null) + return new RespEntity(RespCode.EXIST); + + if(map.getStation()!=null&&map.getStation().length()>0) + path += "/"+map.getStation(); + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + fileName = map.getMapid()+".jpg"; + map.Insert(dataSource); + } + } catch (Exception ee) { + return new RespEntity(RespCode.NOTEXIST); + } + }/* else { + return new RespEntity(RespCode.EXCEPTION); + }*/ + + if (!file.isEmpty()) { + + try { + InputStream ins = file.getInputStream(); + + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(new File(path + File.separator + fileName))); + + byte[] buffer = new byte[128*1024]; + int len = 0; + while((len = ins.read(buffer)) != -1) { + out.write(buffer,0,len); + } + out.flush(); + out.close(); + return new RespEntity(RespCode.SUCCESS); + } catch (FileNotFoundException e) { + return new RespEntity(RespCode.NOTEXIST); + } catch (IOException e) { + return new RespEntity(RespCode.EXCEPTION); + } + } else { + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value = "/firectrl/file/stationmap/upload2", method = RequestMethod.POST) + public RespEntity uploadStationMapFileEx(FireStationMapInfoEntity mapinfo,@RequestParam("file") MultipartFile file) { + if(mapinfo==null||mapinfo.getStation()==null||mapinfo.getMapid()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(mapinfo.QueryIt(dataSource)!=null) + return new RespEntity(RespCode.EXIST); + + String path = "./stationmap"; + String fileName = file.getOriginalFilename();//获取文件名 + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + if(mapinfo.getStation()!=null&&mapinfo.getStation().length()>0) + path += "/"+mapinfo.getStation(); + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + fileName = mapinfo.getMapid()+".jpg"; + mapinfo.Insert(dataSource); + + if (!file.isEmpty()) { + + try { + InputStream ins = file.getInputStream(); + + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(new File(path + File.separator + fileName))); + + byte[] buffer = new byte[128*1024]; + int len = 0; + while((len = ins.read(buffer)) != -1) { + out.write(buffer,0,len); + } + out.flush(); + out.close(); + return new RespEntity(RespCode.SUCCESS); + } catch (FileNotFoundException e) { + return new RespEntity(RespCode.NOTEXIST); + } catch (IOException e) { + return new RespEntity(RespCode.EXCEPTION); + } + } else { + return new RespEntity(RespCode.EXCEPTION); + } + } + + ///https://www.genetek.cc:8083/firectrl/file/stationmap/download?station=weizhan&mapid=12333 + @RequestMapping(value="/firectrl/file/stationmap/download") + public void downloadMap(String station,String mapid,HttpServletRequest request, HttpServletResponse response) throws Exception { + String path = "./stationmap"; + + if(station!=null&&station.length()>0) + path += "/"+station; + + String fileName = mapid+".jpg"; + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File(path, fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + //动态设置响应类型,根据前台传递文件类型设置响应类型 + response.setContentType(request.getSession().getServletContext().getMimeType(extendFileName)); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(fileName,"UTF-8")); + //获取输出流对象(用于写文件) + ServletOutputStream os = response.getOutputStream(); + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,os); + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlInspectionController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlInspectionController.java new file mode 100644 index 0000000..a8a91e1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlInspectionController.java @@ -0,0 +1,500 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.UserService; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.RoundInspectTaskResult; +import com.jingyi.iotserver.firestationport.model.inspection.InspectStationEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionDeviceEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionResultEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionTaskEntity; +import com.jingyi.iotserver.firestationport.model.todev.NoticeEntity; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@RestController +@CrossOrigin +public class FireCtrlInspectionController { + + @Autowired + private DataSource dataSource; + + @Autowired + private UserService userService; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + @ResponseBody + @RequestMapping(value="/firectrl/client/inspect/save",method = RequestMethod.POST) + public RespEntity addInspectionTask(HttpServletRequest request) { + + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + InspectStationEntity task = (InspectStationEntity) SQLTools.getEntityFromJson(rootnode, InspectStationEntity.class); + + if(task==null||task.getNumber()==null||task.getNumber().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(InspectStationEntity.Query(dataSource,task.getNumber())!=null) + return new RespEntity(RespCode.EXIST); + if(task.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"INSPECT_STATION", + "添加微站查岗",JsonHelper.convertObjectToStr(task),rel.getCode()); + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/inspect/getcount",method = RequestMethod.POST) + public RespEntity getInspectionTaskCount(HttpServletRequest request) { + + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + InspectStationEntity task = (InspectStationEntity) SQLTools.getEntityFromJson(rootnode, InspectStationEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + if(startstr==null||endstr==null) + return new RespEntity(RespCode.EXCEPTION); + if(task==null) + task = new InspectStationEntity(); + int count = task.queryCount(dataSource,startstr,endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/inspect/getlist",method = RequestMethod.POST) + public RespEntity getInspectionTaskList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + InspectStationEntity task = (InspectStationEntity) SQLTools.getEntityFromJson(rootnode, InspectStationEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + if(startstr==null||endstr==null) + return new RespEntity(RespCode.EXCEPTION); + if(task==null) + task = new InspectStationEntity(); + List list = task.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS, list); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/adddevice",method = RequestMethod.POST) + public RespEntity addRoundInspectDevice(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionDeviceEntity dev = (RoundInspectionDeviceEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionDeviceEntity.class); + + if(dev==null||dev.getDeviceid()==null||dev.getDeviceid().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(dev.QueryIt(dataSource)!=null) + return new RespEntity(RespCode.EXIST); + if(dev.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"ROUNDINSPECT_DEVICE", + "添加巡检设备",JsonHelper.convertObjectToStr(dev),rel.getCode()); + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/deldevice",method = RequestMethod.POST) + public RespEntity delRoundInspectDevice(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionDeviceEntity dev = (RoundInspectionDeviceEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionDeviceEntity.class); + + if(dev==null||dev.getDeviceid()==null||dev.getDeviceid().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(dev.QueryIt(dataSource)==null) + return new RespEntity(RespCode.NOTEXIST); + if(dev.Delete(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"ROUNDINSPECT_DEVICE", + "删除巡检设备",JsonHelper.convertObjectToStr(dev),rel.getCode()); + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/updatedevice",method = RequestMethod.POST) + public RespEntity updateRoundInspectDevice(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionDeviceEntity dev = (RoundInspectionDeviceEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionDeviceEntity.class); + + if(dev==null||dev.getDeviceid()==null||dev.getDeviceid().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(dev.QueryIt(dataSource)==null) + return new RespEntity(RespCode.NOTEXIST); + if(dev.Update(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ROUNDINSPECT_DEVICE", + "更新巡检设备信息",JsonHelper.convertObjectToStr(dev),rel.getCode()); + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/getdevicecount",method = RequestMethod.POST) + public RespEntity getRoundInspectDeviceCount(HttpServletRequest request) { + + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionDeviceEntity dev = (RoundInspectionDeviceEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionDeviceEntity.class); + + if(dev==null) + dev = new RoundInspectionDeviceEntity(); + int count = dev.queryCount(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/getdevicelist",method = RequestMethod.POST) + public RespEntity getRoundInspectDeviceList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionDeviceEntity dev = (RoundInspectionDeviceEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionDeviceEntity.class); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + if(dev==null) + dev = new RoundInspectionDeviceEntity(); + List list = dev.queryPage(dataSource,null,null,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS, list); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/addtask",method = RequestMethod.POST) + public RespEntity addRoundInspectTask(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionTaskEntity task = (RoundInspectionTaskEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionTaskEntity.class); + + if(task==null||task.getTaskid()==null||task.getTaskid().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(RoundInspectionTaskEntity.QueryRoundInspectionTask(dataSource,task.getTaskid())!=null) + return new RespEntity(RespCode.EXIST); + + task.setTimestamp(new Date()); + task.setCompletedtime(null); + task.setReceivedtime(null); + task.setStatus("sent"); + if(task.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + try { + NoticeEntity notice = new NoticeEntity(); + notice.setNoticeid("" + System.currentTimeMillis()); + notice.setTitle("巡检任务"); + notice.setContent("你站有新的任务,请登录移动设备获取任务,并尽快执行。"); + notice.setTimestamp(new Date()); + notice.setSender(task.getSender()); + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", task.getReceiver(), "notify", content, 0); + + }catch (Exception e){ + + } + }else + rel = new RespEntity(RespCode.FAIL); + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ROUNDINSPECT_TASK", + "添加巡检任务",JsonHelper.convertObjectToStr(task),rel.getCode()); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/canceltask",method = RequestMethod.POST) + public RespEntity cancelRoundInspectTask(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionTaskEntity task = (RoundInspectionTaskEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionTaskEntity.class); + + if(task==null||task.getTaskid()==null||task.getTaskid().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + task = RoundInspectionTaskEntity.QueryRoundInspectionTask(dataSource,task.getTaskid()); + if(task==null) + return new RespEntity(RespCode.NOTEXIST); + if(task.getStatus()!=null&&task.getStatus().equals("completed")) + return new RespEntity(RespCode.COMPLETED); + + task.setTimestamp(null); + task.setCompletedtime(null); + task.setReceivedtime(null); + task.setStatus("canceled"); + if(task.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + try { + NoticeEntity notice = new NoticeEntity(); + notice.setNoticeid("" + System.currentTimeMillis()); + notice.setTitle("巡检任务"); + notice.setContent("你站有巡检任务,已被取消。"); + notice.setTimestamp(new Date()); + notice.setSender(task.getSender()); + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", task.getReceiver(), "notify", content, 0); + + }catch (Exception e){ + + } + }else + rel = new RespEntity(RespCode.FAIL); + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"ROUNDINSPECT_TASK", + "取消巡检任务",JsonHelper.convertObjectToStr(task),rel.getCode()); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/gettaskcount",method = RequestMethod.POST) + public RespEntity getRoundInspectTaskCount(HttpServletRequest request) { + + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionTaskEntity task = (RoundInspectionTaskEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionTaskEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + if(task==null) + task = new RoundInspectionTaskEntity(); + int count = task.queryCount(dataSource,startstr,endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/gettasklist",method = RequestMethod.POST) + public RespEntity getRoundInspectTaskList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionTaskEntity task = (RoundInspectionTaskEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionTaskEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + if(task==null) + task = new RoundInspectionTaskEntity(); + List list = task.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS, list); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/getpicturecount",method = RequestMethod.POST) + public RespEntity getRoundInspectPictureCount(HttpServletRequest request) { + + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionResultEntity task = (RoundInspectionResultEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionResultEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + if(task==null) + task = new RoundInspectionResultEntity(); + int count = task.queryCount(dataSource,startstr,endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/getpicturelist",method = RequestMethod.POST) + public RespEntity getRoundInspectPictureList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + RoundInspectionResultEntity task = (RoundInspectionResultEntity) SQLTools.getEntityFromJson(rootnode, RoundInspectionResultEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + if(task==null) + task = new RoundInspectionResultEntity(); + List list = task.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS, list); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/roundinspect/gettaskresult",method = RequestMethod.POST) + public RespEntity getRoundInspectTaskResult(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + String taskid = JsonHelper.getStringValue(rootnode,"taskid"); + RoundInspectionTaskEntity task = RoundInspectionTaskEntity.QueryRoundInspectionTask(dataSource,taskid); + List list = RoundInspectionResultEntity.queryTaskResult(dataSource,taskid); + if(task==null) + return new RespEntity(RespCode.NOTEXIST); + RoundInspectTaskResult result = new RoundInspectTaskResult(); + result.setResult(list); + result.setTask(task); + return new RespEntity(RespCode.SUCCESS, result); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlMediaController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlMediaController.java new file mode 100644 index 0000000..2a744b2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlMediaController.java @@ -0,0 +1,161 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireMediaInfoEntity; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.List; + +@RestController +@CrossOrigin +public class FireCtrlMediaController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @ResponseBody + @RequestMapping(value="/firectrl/client/media/add",method = RequestMethod.POST) + public RespEntity addStationMedia(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + FireMediaInfoEntity mediainfo = (FireMediaInfoEntity) SQLTools.getEntityFromJson(rootnode, FireMediaInfoEntity.class); + if(mediainfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,mediainfo.getStation()); + + if(st!=null) { + mediainfo.setStation(st.getName()); + }else{ + return new RespEntity(RespCode.NOTEXIST); + } + if(mediainfo.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } catch (Exception e) { + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/medida/delete",method = RequestMethod.POST) + public RespEntity deleteStationMedia(HttpServletRequest request) { + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + FireMediaInfoEntity mediainfo = (FireMediaInfoEntity) SQLTools.getEntityFromJson(rootnode, FireMediaInfoEntity.class); + if(mediainfo==null||mediainfo.getStation()==null||mediainfo.getCreatetime()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(mediainfo.Delete(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } catch (Exception e) { + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/media/update",method = RequestMethod.POST) + public RespEntity updateStationMedia(HttpServletRequest request) { + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + FireMediaInfoEntity mediainfo = (FireMediaInfoEntity) SQLTools.getEntityFromJson(rootnode, FireMediaInfoEntity.class); + if(mediainfo==null||mediainfo.getStation()==null||mediainfo.getCreatetime()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,mediainfo.getStation()); + if(st!=null) { + mediainfo.setStation(st.getName()); + }else{ + return new RespEntity(RespCode.NOTEXIST); + } + if(mediainfo.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } catch (Exception e) { + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/media/getcount",method = RequestMethod.POST) + public RespEntity getStationMediaCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + FireMediaInfoEntity mediainfo = (FireMediaInfoEntity) SQLTools.getEntityFromJson(rootnode, FireMediaInfoEntity.class); + if(mediainfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int count = mediainfo.queryCount(dataSource,startstr,endstr); + CountResult result = new CountResult(); + result.setCount(count); + + return new RespEntity(RespCode.SUCCESS,result); + } catch (Exception e) { + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/media/getlist",method = RequestMethod.POST) + public RespEntity getStationMediaList(HttpServletRequest request) { + RespEntity rel = null; + + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + FireMediaInfoEntity mediainfo = (FireMediaInfoEntity) SQLTools.getEntityFromJson(rootnode, FireMediaInfoEntity.class); + if(mediainfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + List list = mediainfo.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + } catch (Exception e) { + return new RespEntity(RespCode.EXCEPTION); + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlPartnerController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlPartnerController.java new file mode 100644 index 0000000..08cd5ae --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlPartnerController.java @@ -0,0 +1,568 @@ +package com.jingyi.iotserver.firestationport.controller; + + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.UserService; +import com.jingyi.iotserver.clientmanage.model.ThirdPlatformInfoEntity; +import com.jingyi.iotserver.common.configuration.DruidDataSourceConfig; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.mdev.MDevPartnerInfo; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationStaffInfoEntity; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentInfoEntity; +import com.jingyi.iotserver.firestationport.model.partner.PartnerAlarm; +import com.jingyi.iotserver.firestationport.model.station.FireStationAlarmEntity; +import com.jingyi.iotserver.firestationport.model.todev.AssignmentEntity; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.security.PrivateKey; +//import java.util.Base64; +import org.apache.commons.codec.binary.Base64; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class FireCtrlPartnerController { + + @Autowired + private DataSource dataSource; + + @Autowired + private UserService userService; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private StationServices stationServices; + + @Autowired + private MessagePublisher messagePublisher; + + @Autowired + private SensorService sensorService; + + private boolean checkScope(ThirdPlatformInfoEntity platform,FireStationBaseInfoEntity station){ + if(platform==null||station==null) + return true; + + if(platform.getBrigade()!=null&&platform.getBrigade().length()>1&&station.getBrigade()!=null&&station.getBrigade().length()>1){ + if(!platform.getBrigade().equals(station.getBrigade())) + return false; + } + + if(platform.getBorough()!=null&&platform.getBorough().length()>1&&station.getBorough()!=null&&station.getBorough().length()>1){ + if(!platform.getBorough().equals(station.getBorough())) + return false; + } + + if(platform.getDetachment()!=null&&platform.getDetachment().length()>1&&station.getDetachment()!=null&&station.getDetachment().length()>1){ + if(!platform.getDetachment().equals(station.getDetachment())) + return false; + } + + if(platform.getStation()!=null&&platform.getStation().length()>1&&station.getName()!=null&&station.getName().length()>1){ + if(!platform.getStation().equals(station.getName())) + return false; + } + + return true; + } + + private boolean setScope(ThirdPlatformInfoEntity platform,FireStationBaseInfoEntity station){ + if(platform==null||station==null) + return false; + if(platform.getBrigade()!=null&&platform.getBrigade().length()>1) + station.setBrigade(platform.getBrigade()); + + + if(platform.getBorough()!=null&&platform.getBorough().length()>1) + station.setBorough(platform.getBorough()); + + + if(platform.getDetachment()!=null&&platform.getDetachment().length()>1) + station.setDetachment(platform.getDetachment()); + + return true; + } + private boolean setScope(ThirdPlatformInfoEntity platform,FireStationAlarmEntity station){ + if(platform==null||station==null) + return false; + if(platform.getBrigade()!=null&&platform.getBrigade().length()>1) + station.setBrigade(platform.getBrigade()); + + + if(platform.getBorough()!=null&&platform.getBorough().length()>1) + station.setBorough(platform.getBorough()); + + + if(platform.getDetachment()!=null&&platform.getDetachment().length()>1) + station.setDetachment(platform.getDetachment()); + + return true; + } + @ResponseBody + @RequestMapping(value="/firectrl/partner/getstation",method = RequestMethod.POST) + public RespEntity getStation(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity) SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(st!=null&&checkScope(platform,st)) + rel = new RespEntity(RespCode.SUCCESS, st); + else + rel = new RespEntity(RespCode.NOTEXIST, null); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/getstationcount",method = RequestMethod.POST) + public RespEntity getStationCount(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + try { + if(station==null) + station = new FireStationBaseInfoEntity(); + setScope(platform,station); + + int count = stationServices.queryStationCount(station); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/getstationlist",method = RequestMethod.POST) + public RespEntity getStationList(HttpServletRequest request) { + long start = System.currentTimeMillis(); + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + try { + if(station==null) + station = new FireStationBaseInfoEntity(); + setScope(platform,station); + List list = stationServices.queryStationList(station,pagesize,pageindex); + + rel = new RespEntity(RespCode.SUCCESS,list); + System.out.println("query station use time: "+((System.currentTimeMillis()-start))+" milliseconds count="+list.size()); + }catch (Exception e){ + e.printStackTrace(); + System.out.println("query station fail use time: "+((System.currentTimeMillis()-start))+" milliseconds"); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/getstationstaff",method = RequestMethod.POST) + public RespEntity getStationStaff(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||!checkScope(platform,station)) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationStaffInfoEntity st = new FireStationStaffInfoEntity(); + st.setStationName(station.getName()); + List list = st.queryList(dataSource,null,null); + for(SQLDataObject ob:list){ + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)ob; + if(staff!=null) + staff.setPassword(null); + } + if(list!=null) + rel = new RespEntity(RespCode.SUCCESS, list); + else + rel = new RespEntity(RespCode.FAIL, station); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/getstationequipment",method = RequestMethod.POST) + public RespEntity getStationEquipment(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||!checkScope(platform,station)) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + List equiplist = null; + if(station.getName()!=null){ + equiplist = stationServices.queryStationEquipmentByName(station.getName()); + } + else if(station.getDevice_id()!=null){ + equiplist = stationServices.queryStationEquipmentByDeviceID(station.getDevice_id()); + }else{ + return new RespEntity(RespCode.NOTEXIST); + } + if(equiplist!=null) + rel = new RespEntity(RespCode.SUCCESS, equiplist); + else + rel = new RespEntity(RespCode.FAIL, station); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/alarm/querycount",method = RequestMethod.POST) + public RespEntity queryStationAlarmCount(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmEntity alarm = (FireStationAlarmEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmEntity.class); + setScope(platform,alarm); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int count = alarm.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/alarm/querylist",method = RequestMethod.POST) + public RespEntity queryStationAlarmList(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmEntity alarm = (FireStationAlarmEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmEntity.class); + setScope(platform,alarm); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + List list = alarm.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/alarm/add",method = RequestMethod.POST) + public RespEntity addPartnerAlarm(HttpServletRequest request) { + RespEntity rel = null; + String sessionid = request.getHeader("authorization"); + ThirdPlatformInfoEntity platform = new ThirdPlatformInfoEntity(); + platform.setAppkey(sessionid); + platform = (ThirdPlatformInfoEntity)platform.QueryIt(dataSource); + if(platform==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + PartnerAlarm alarm = (PartnerAlarm)SQLTools.getEntityFromJson(rootnode,PartnerAlarm.class); + alarm.setParterid(platform.getId()); + alarm.setTimestamp(new Date()); + + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,alarm.getName()); + if(st!=null&&checkScope(platform,st)){ + if(alarm.Insert(dataSource)) { + String content = JsonHelper.convertObjectToStr(alarm); + JpushClientUtil.sendMessageToDevice("firectrl", alarm.getName(), "partneralarm", content, 0); + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST, null); + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + String pubkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCab9tZU7qVJsaVDFBOettyhi3Cxf9j9lYsp+VgXsPKcSWAVJq1fOyS2zCQjQrVxZbfXvub8ik93jTBXzXUhVCG+jXG202aNKC5uPgbo2IwAGU/8hr4o/Bj9fR1LCNr3uyYN/6GF+Fm/cEoKFWLkRl51EDxVorUirMNNwjLlbQ7vwIDAQAB"; + String prikey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJpv21lTupUmxpUMUE5623KGLcLF/2P2Viyn5WBew8pxJYBUmrV87JLbMJCNCtXFlt9e+5vyKT3eNMFfNdSFUIb6NcbbTZo0oLm4+BujYjAAZT/yGvij8GP19HUsI2ve7Jg3/oYX4Wb9wSgoVYuRGXnUQPFWitSKsw03CMuVtDu/AgMBAAECgYBh+44DgqficZOUhRd+c1w/sPnflZePaH8MHgndtsIp8teEMCln9DZ0hjStwY6aSp6KYczpCB86bXyzIyEYEO0hd87vQxrQH8wvLnQlXqBUGMG3IjEPUr25xhQFRVl8SNG3Bk5im0WUXcxQJxwS/514G5fADuKBpqIuspMS0XMYIQJBAOG7M5A84Oi4FdrO++u0U2WVOIl9RRPmY5c6rltFJ/XfihOgWz8ISaGhqO2PVZdh+hgZgZEI1D+iUcQ53kOVlV0CQQCvJUwIuz9Z3thCIG57oKUQTEYigEmE4GDWCJZ21rgi/I5TnmoHwwa7NF5t/1uO+sHzd7k34q8wUjuBYHDTskfLAkEAmzHbt7VDZHz7+Z4JMfqew96eKlkIHzBtFFJyAapAWRlBk1DSqzmFdizxObMsQ5JHIj6XCCIr2zw8P08R8yFquQJAWntZMXWSv9n5PQhGK4YNYEMXRIGj+Yp1XH1pRhGdZS22VYqUWlgtpQ7j7c2rPk1bX20teaqZOMxyw17QSv1iSwJAMTTq0frkipqCcz6zUSK5gShS4lsZirvEAlJUJ0vexi+wmIEohaXHGJRoy63tAUzU2pJCTTJG9bWhmYkueOf4nA=="; + @ResponseBody + @RequestMapping(value="/firectrl/partner/assign",method = RequestMethod.POST) + public String PartnerSendAssign(HttpServletRequest request) { + RespEntity rel = null; + + try { + String body = HttpTools.getBodyFromRequest(request); + String json = new String(Base64.decodeBase64(body),"UTF-8"); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + String reqSecret = JsonHelper.getStringValue(rootnode,"reqSecret"); + String reqInfo = JsonHelper.getStringValue(rootnode,"reqInfo"); + + if(reqSecret==null||reqInfo==null) + return "{\"code\": \"fail\",\"message\": \"错误参数\"}"; + PrivateKey pkeyobj= RSAUtil.string2PrivateKey(prikey); + + String deskey = new String(RSAUtil.privateDecrypt(Base64.decodeBase64(reqSecret),pkeyobj)); + + String src = TriDESEncryptUtil.Base64DESDecrypt2ByteString(deskey, reqInfo); + + rootnode = JsonHelper.parseBodyLevel1(src); + + String station = JsonHelper.getStringValue(rootnode,"id"); + String warnId = JsonHelper.getStringValue(rootnode,"warnId"); + String address = JsonHelper.getStringValue(rootnode,"address"); + String time = JsonHelper.getStringValue(rootnode,"time"); + String type = JsonHelper.getStringValue(rootnode,"type"); + String brigade = JsonHelper.getStringValue(rootnode,"brigade"); + String description = JsonHelper.getStringValue(rootnode,"description"); + double longitude = 0.0; + String str = JsonHelper.getStringValue(rootnode,"longitude"); + if(str!=null) + longitude = Double.parseDouble(str); + double latitude = 0.0; + str = JsonHelper.getStringValue(rootnode,"latitude"); + if(str!=null) + latitude = Double.parseDouble(str); + + FireStationBaseInfoEntity st = (FireStationBaseInfoEntity)FireStationBaseInfoEntity.QueryByDeviceID(dataSource,station); + if(st==null) + return "{\"code\": \"fail\",\"message\": \"微站不存在\"}"; + AssignmentEntity assignment = new AssignmentEntity(); + assignment.setReceiver(st.getName()); + assignment.setSendtype("toclient"); + assignment.setAssignmentid("ca-"+warnId); + assignment.setTitle(warnId); + assignment.setContent(description); + assignment.setSender("CA-platform"); + assignment.setType(type); + assignment.setTimestamp(new Date()); + assignment.setBrigade(brigade); + assignment.setLongitude(longitude); + assignment.setLatitude(latitude); + assignment.setAddress(address); + if(assignment.QueryIt(dataSource)!=null){ + return "{\"code\": \"fail\",\"message\": \"任务已经存在\"}"; + } + if(!assignment.Insert(dataSource)){ + return "{\"code\": \"fail\",\"message\": \"写数据库失败\"}"; + } + String content = JsonHelper.convertObjectToStr(assignment); + JpushClientUtil.sendMessageToDevice("firectrl", st.getName(), "assignment", content, 24*60*60); + + return "{\"code\": \"success\",\"message\": \"请求成功\"}"; + }catch (Exception e){ + return "{\"code\": \"fail\",\"message\": \"内部异常\"}"; + } + // + } + + @ResponseBody + @RequestMapping(value = "/rmttranfer/sendmessage", method = RequestMethod.POST) + public RespEntity sendMQTT(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String receiver = JsonHelper.getStringValue(rootnode, "receiver"); + String message = JsonHelper.getStringValue(rootnode, "message"); + + try { + messagePublisher.sendMessage(receiver+"_rtmtranfer",message); + rel = new RespEntity(RespCode.SUCCESS); + } catch (Exception e) { + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/getsensorcount",method = RequestMethod.POST) + public RespEntity getMDevPartnerSensorCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + String appkey = JsonHelper.getStringValue(rootnode,"appkey"); + String station = JsonHelper.getStringValue(rootnode,"station"); + MDevPartnerInfo p = (MDevPartnerInfo) SQLTools.getEntityFromJson(rootnode, MDevPartnerInfo.class); + if(p==null||p.getPartner()==null||station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMDevDataSource(); + p = (MDevPartnerInfo)p.QueryIt(ds); + if(p==null||!p.getStation().contains(station)) + return new RespEntity(RespCode.NOTEXIST); + + if(!p.getAppkey().equals(appkey)) + return new RespEntity(RespCode.NOAUTHOR); + + try { + SensorDeviceEntity sensor = (SensorDeviceEntity) SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + if(sensor==null) + sensor = new SensorDeviceEntity(); + if(sensor.getOwner()==null) + sensor.setOwner(station); + int count = sensorService.querySensorCount(sensor); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/partner/getsensorpage",method = RequestMethod.POST) + public RespEntity getMDevPartnerSensorList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + + String partner = JsonHelper.getStringValue(rootnode,"partner"); + + String appkey = JsonHelper.getStringValue(rootnode,"appkey"); + String station = JsonHelper.getStringValue(rootnode,"station"); + MDevPartnerInfo p = (MDevPartnerInfo) SQLTools.getEntityFromJson(rootnode, MDevPartnerInfo.class); + if(p==null||p.getPartner()==null||station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMDevDataSource(); + p = (MDevPartnerInfo)p.QueryIt(ds); + if(p==null||!p.getStation().contains(station)) + return new RespEntity(RespCode.NOTEXIST); + if(!p.getAppkey().equals(appkey)) + return new RespEntity(RespCode.NOAUTHOR); + + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + SensorDeviceEntity sensor = (SensorDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + if(sensor==null) + sensor = new SensorDeviceEntity(); + if(sensor.getOwner()==null) + sensor.setOwner(station); + List list = sensorService.querySensorPage(pagesize,pageindex,sensor); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlTalkController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlTalkController.java new file mode 100644 index 0000000..dd99238 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlTalkController.java @@ -0,0 +1,247 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.ClientRuningInfo; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.UserService; +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.clientmanage.model.DetachmentEntity; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.talk.TalkPlatformAccountInfo; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.List; + +@RestController +@CrossOrigin +public class FireCtrlTalkController { + @Autowired + private DataSource dataSource; + + @Autowired + private UserService userService; + + @Autowired + private UserAuthorManager userAuthorManager; + + @ResponseBody + @RequestMapping(value="/firectrl/client/talk/addplatformaccount",method = RequestMethod.POST) + public RespEntity addPlatformAccount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + TalkPlatformAccountInfo info = (TalkPlatformAccountInfo) SQLTools.getEntityFromJson(rootnode,TalkPlatformAccountInfo.class); + if(info==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if(info.QueryIt(dataSource)!=null) + rel = new RespEntity(RespCode.EXIST); + else{ + if(info.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE,"TALKACCOUNT", + "添加对讲企业号", JsonHelper.convertObjectToStr(info),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/talk/getplatformaccount",method = RequestMethod.POST) + public RespEntity getPlatformAccount(HttpServletRequest request) { + RespEntity rel = null; + try { + String sessionid = request.getHeader("authorization"); + + ClientRuningInfo userinfo = userAuthorManager.getUserInfo(sessionid); + if(userinfo==null) + return new RespEntity(RespCode.FAIL); + + String level = userinfo.getScopelevel(); + String levelval = userinfo.getLevelvalue(); + if(level==null||levelval==null){ + return new RespEntity(RespCode.FAIL); + } + + TalkPlatformAccountInfo account = new TalkPlatformAccountInfo(); + List alist = null; + + if(level.equals("detachment")){ + account.setScopelevel("detachment"); + account.setLevelvalue(levelval); + alist = account.queryList(dataSource,null,null); + + if(alist==null||alist.size()<=0) + { + DetachmentEntity detachment = new DetachmentEntity(); + detachment.setDetachment(levelval); + detachment = (DetachmentEntity)detachment.QueryIt(dataSource); + if(detachment!=null){ + account.setScopelevel("borough"); + account.setLevelvalue(detachment.getBorough()); + alist = account.queryList(dataSource,null,null); + + if(alist==null||alist.size()<=0){ + if(detachment.getBrigade()==null){ + BoroughEntity b = new BoroughEntity(); + b.setBorough(detachment.getBorough()); + b = (BoroughEntity)b.QueryIt(dataSource); + if(b!=null){ + detachment.setBrigade(b.getBrigade()); + } + } + account.setScopelevel("brigade"); + account.setLevelvalue(detachment.getBrigade()); + alist = account.queryList(dataSource,null,null); + } + } + } + }else if(level.equals("borough")){ + account.setScopelevel("borough"); + account.setLevelvalue(levelval); + alist = account.queryList(dataSource,null,null); + if(alist==null||alist.size()<=0){ + BoroughEntity b = new BoroughEntity(); + b.setBorough(account.getLevelvalue()); + b = (BoroughEntity)b.QueryIt(dataSource); + if(b!=null){ + account.setScopelevel("brigade"); + account.setLevelvalue(b.getBrigade()); + alist = account.queryList(dataSource,null,null); + } + + } + }else if(level.equals("brigade")){ + account.setScopelevel("brigade"); + account.setLevelvalue(account.getLevelvalue()); + alist = account.queryList(dataSource,null,null); + } + + if(alist!=null&&alist.size()>0) + return new RespEntity(RespCode.SUCCESS,alist.get(0)); + + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/talk/deleteplatformaccount",method = RequestMethod.POST) + public RespEntity deletePlatformAccount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + TalkPlatformAccountInfo info = (TalkPlatformAccountInfo)SQLTools.getEntityFromJson(rootnode,TalkPlatformAccountInfo.class); + if(info==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(info.QueryIt(dataSource)==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(info.Delete(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"TALKACCOUNT", + "删除对讲企业账号",JsonHelper.convertObjectToStr(info),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/talk/updatetalkplatfomraccount",method = RequestMethod.POST) + public RespEntity updatePlatformAccount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + TalkPlatformAccountInfo info = (TalkPlatformAccountInfo)SQLTools.getEntityFromJson(rootnode,TalkPlatformAccountInfo.class); + if(info==null) + rel = new RespEntity(RespCode.ERROR_REQUEST); + else{ + if(info.QueryIt(dataSource)==null) + rel = new RespEntity(RespCode.NOTEXIST); + else{ + if(info.Update(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + } + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"TALKACCOUNT", + "更新对讲企业账号信息",JsonHelper.convertObjectToStr(info),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/talk/gettalkplatfomraccountlist",method = RequestMethod.POST) + public RespEntity getPlatformAccountList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + try { + TalkPlatformAccountInfo info = (TalkPlatformAccountInfo)SQLTools.getEntityFromJson(rootnode,TalkPlatformAccountInfo.class); + if(info==null) + info = new TalkPlatformAccountInfo(); + + List list = info.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlVideoController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlVideoController.java new file mode 100644 index 0000000..1ab0f85 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireCtrlVideoController.java @@ -0,0 +1,290 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.DeviceRequestEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationVideoConfigEntity; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.netease.NeteaseVideoManager; +import com.jingyi.iotserver.firestationport.services.netease.NeteaseVideoService; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; + +//http://dev.netease.im/docs/product/直播/服务端API文档 + +@RestController +@CrossOrigin +public class FireCtrlVideoController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private NeteaseVideoService neteaseVideoService; + + @Autowired + private NeteaseVideoManager neteaseVideoManager; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + @ResponseBody + @RequestMapping(value="/firectrl/video/createchannel",method = RequestMethod.POST) + public RespEntity createChannel(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + rel = neteaseVideoService.createVideoChannel(station); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/video/deletechannel",method = RequestMethod.POST) + public RespEntity deleteChannel(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + rel = neteaseVideoService.deleteVideoChannel(station); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + }); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/video/getchannel",method = RequestMethod.POST) + public RespEntity getChannel(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + JsonNode jsonroot = (JsonNode)param; + FireStationVideoConfigEntity videoconfig = FireStationVideoConfigEntity.Query(dataSource,station.getName(), "netease"); + if (videoconfig != null) + return new RespEntity(RespCode.SUCCESS, videoconfig); + else + return new RespEntity(RespCode.FAIL); + } + }); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/video/syncchannel") + public RespEntity syncChannel(HttpServletRequest request) { + RespEntity rel = null; + try { + neteaseVideoService.syncVideoConfigList(); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + private RespEntity executeOperateOnStation(HttpServletRequest request,IFireStationOperate op){ + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null) + return new RespEntity(RespCode.FAIL, null); + JsonNode m = rootnode.findValue("stationname"); + if(m==null) + m = rootnode.findValue("name"); + if(m==null){ + rel = new RespEntity(RespCode.ERROR_REQUEST); + return rel; + } + String stationname = m.asText(); + + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + + if(station==null) + return new RespEntity(RespCode.NOTEXIST); + + rel = op.ExecuteOperate(station,rootnode); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/video/reportvideostatus") + public RespEntity reportVideoStatus(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + + ObjectMapper mapper = new ObjectMapper(); + DeviceRequestEntity reqinfo = parseRequestCMD(json); + + if(reqinfo!=null){ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + if(reqinfo.getCID()==2016){ + //open + neteaseVideoManager.StationVideoStart(station.getName()); + fireStationLiveManager.setVideoState(station.getName(),"open"); + }else if(reqinfo.getCID()==2017){ + //close + neteaseVideoManager.StationVideoStop(station.getName()); + fireStationLiveManager.setVideoState(station.getName(),"close"); + } + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + private DeviceRequestEntity parseRequestCMD(String json){ + DeviceRequestEntity rel = null; + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode rootnode = mapper.readTree(json); + if(rootnode==null) + return null; + JsonNode m = rootnode.findValue("Mark"); + String mark = m.asText(); + + JsonNode u = rootnode.findValue("UserName"); + String username = null; + if(u!=null) + username = u.asText(); + + JsonNode d = rootnode.findValue("DeviceId"); + String deviceid =null; + if(d!=null) + deviceid = d.asText(); + + JsonNode c = rootnode.findValue("CID"); + int cid = Integer.parseInt(c.asText()); + JsonNode p = rootnode.findValue("PTS"); + long pts = Long.parseLong(p.asText()); + + JsonNode data = rootnode.findValue("data"); + + rel = new DeviceRequestEntity(); + rel.setCID(cid); + rel.setDeviceId(deviceid); + rel.setMark(mark); + rel.setPTS(pts); + rel.setUserName(username); + if(data!=null){ + rel.setData(data.asText()); + } + }catch (Exception e){ + + } + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/video/openvideo",method = RequestMethod.POST) + public RespEntity startVideoTalk(HttpServletRequest request) { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + String brigade = JsonHelper.getStringValue(rootnode,"brigade"); + String borough = JsonHelper.getStringValue(rootnode,"borough"); + String detachment = JsonHelper.getStringValue(rootnode,"detachment"); + String name = JsonHelper.getStringValue(rootnode,"station"); + FireStationBaseInfoEntity station = null; + station = FireStationBaseInfoEntity.Query(dataSource,name); + if(station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String content = "{"; + + if(detachment!=null) + content += "\"detachment\":\""+detachment+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + else if(borough!=null) + content += "\"borough\":\""+borough+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + else if(brigade!=null) + content += "\"brigade\":\""+brigade+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + else + return new RespEntity(RespCode.ERROR_REQUEST); + JpushClientUtil.sendMessageToDevice("firectrl", name, "openvideo", content, 0); + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/video/closevideo",method = RequestMethod.POST) + public RespEntity stopVideoTalk(HttpServletRequest request) { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + String brigade = JsonHelper.getStringValue(rootnode,"brigade"); + String borough = JsonHelper.getStringValue(rootnode,"borough"); + String detachment = JsonHelper.getStringValue(rootnode,"detachment"); + String name = JsonHelper.getStringValue(rootnode,"station"); + FireStationBaseInfoEntity station = null; + station = FireStationBaseInfoEntity.Query(dataSource,name); + if(station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String content = "{"; + + if(detachment!=null) + content += "\"detachment\":\""+detachment+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + else if(borough!=null) + content += "\"borough\":\""+borough+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + else if(brigade!=null) + content += "\"brigade\":\""+brigade+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + else + content += "\"station\":\""+station+"\",\"timestamp\":\""+SQLTools.formatDate(new Date())+"\"}"; + JpushClientUtil.sendMessageToDevice("firectrl", name, "closevideo", content, 0); + + return new RespEntity(RespCode.SUCCESS); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientAlarmController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientAlarmController.java new file mode 100644 index 0000000..9d83899 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientAlarmController.java @@ -0,0 +1,240 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.ClientRuningInfo; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.CountResultByIndex; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationAlarmEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationAlarmProcessRecordEntity; +import com.jingyi.iotserver.firestationport.services.*; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class FireStationClientAlarmController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private UserAuthorManager userAuthorManager; + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/process",method = RequestMethod.POST) + public RespEntity processStationAlarm(HttpServletRequest request) { + RespEntity rel = null; + String session = request.getHeader("authorization"); + ClientRuningInfo runinfo = userAuthorManager.getUserInfo(session); + runinfo.getScopelevel(); + String sender = runinfo.getLevelvalue() ; + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode,"stationName"); + String alarmid = JsonHelper.getStringValue(rootnode,"alarmid"); + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,name); + if(station==null||alarmid==null) + return new RespEntity(RespCode.NOTEXIST); + FireStationAlarmEntity alarm = new FireStationAlarmEntity(); + alarm.setStation(name); + alarm.setAlarmid(alarmid); + alarm.setState("processed"); + alarm.setProcesstime(new Date()); + stationServices.processStationAlarm(alarm,sender); + if(!alarm.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/processall",method = RequestMethod.POST) + public RespEntity processStationAllAlarm(HttpServletRequest request) { + RespEntity rel = null; + String session = request.getHeader("authorization"); + ClientRuningInfo runinfo = userAuthorManager.getUserInfo(session); + runinfo.getScopelevel(); + String sender = runinfo.getLevelvalue() ; + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode,"stationName"); + + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,name); + if(station==null) + return new RespEntity(RespCode.NOTEXIST); + FireStationAlarmEntity alarm = new FireStationAlarmEntity(); + alarm.setStation(name); + alarm.setState("processed"); + stationServices.processStationAlarm(alarm,sender); + if(alarm.ProcessAllAlarm(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/querycount",method = RequestMethod.POST) + public RespEntity queryStationAlarmCount(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmEntity alarm = (FireStationAlarmEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int count = alarm.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/multi-querycount",method = RequestMethod.POST) + public RespEntity queryStationMultiAlarmCount(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmEntity alarm = (FireStationAlarmEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmEntity.class); + JsonNode timesnode = JsonHelper.getLevel2(rootnode,"times"); + if(timesnode==null||!timesnode.isArray()||timesnode.size()<=0) + return new RespEntity(RespCode.FAIL); + ArrayList infolist = new ArrayList(); + for(int i=0;i list = alarm.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/operation/add",method = RequestMethod.POST) + public RespEntity addStationAlarmOperation(HttpServletRequest request) { + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmProcessRecordEntity record = (FireStationAlarmProcessRecordEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmProcessRecordEntity.class); + FireStationAlarmEntity alarm = new FireStationAlarmEntity(); + alarm.setStation(record.getStation()); + alarm.setAlarmid(record.getAlarmid()); + if(alarm.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + record.setTimestamp(new Date()); + if(record.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/operation/getcount",method = RequestMethod.POST) + public RespEntity queryStationAlarmOperateCount(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmProcessRecordEntity alarm = (FireStationAlarmProcessRecordEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmProcessRecordEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + + int count = alarm.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/alarm/operation/getlist",method = RequestMethod.POST) + public RespEntity queryStationAlarmOperateList(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + FireStationAlarmProcessRecordEntity alarm = (FireStationAlarmProcessRecordEntity)SQLTools.getEntityFromJson(rootnode,FireStationAlarmProcessRecordEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + List list = alarm.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientController.java new file mode 100644 index 0000000..89a5757 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientController.java @@ -0,0 +1,2572 @@ +package com.jingyi.iotserver.firestationport.controller; + + +import com.alibaba.dubbo.common.json.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.clientmanage.model.UserInfoEntity; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.*; +import com.jingyi.iotserver.firestationport.model.equipment.EquipmentVerifyEntity; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentEntity; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentInfoEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallAckEntity; +import com.jingyi.iotserver.firestationport.model.school.GuardSignEventEntity; +import com.jingyi.iotserver.firestationport.model.station.PolicemanInfo; +import com.jingyi.iotserver.firestationport.model.station.*; +import com.jingyi.iotserver.firestationport.model.statistics.*; +import com.jingyi.iotserver.firestationport.model.todev.NoticeEntity; +import com.jingyi.iotserver.firestationport.model.todev.TimingJobEntity; +import com.jingyi.iotserver.firestationport.services.*; +import com.jingyi.iotserver.firestationport.services.analyze.StatisticsMessage; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.utils.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.io.*; +import java.net.HttpURLConnection; +import java.util.*; + +@RestController +@CrossOrigin +public class FireStationClientController { + + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private DatabaseDesInfoService databaseDesInfoService; + + @Autowired + private TimingJobManager timingJobManager; + + @Autowired + private ExcelService excelService; + + @Autowired + private DataStatisticsService dataStatisticsService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + + private final Logger logger = LoggerFactory.getLogger(FireStationClientController.class); + @ResponseBody + @RequestMapping(value="/firectrl/client/isactive") + public RespEntity firectrlIsActive() { + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/test") + public RespEntity firectrlTest() { + /* List list = new ArrayList(); + FireStationBaseInfoEntity st = new FireStationBaseInfoEntity(); + st.setBrigade("上海"); + list.add(st); + st = new FireStationBaseInfoEntity(); + st.setDetachment("1322"); + st.setBrigade("110"); + list.add(st); + + try { + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(list); + System.out.println(json); + }catch (Exception e) + { + + } + int count = stationServices.queryStationCountByScope(list); + list = stationServices.queryStationListByScope(list,10,0); + return new RespEntity(RespCode.SUCCESS,list); + */ + RollcallReportForm report = new RollcallReportForm(); + report.setRollcall(30); + report.setExpect(300); + report.setAck(200); + report.setIgnore(50); + List ranking = new ArrayList (); + StationRollcallCounter st = new StationRollcallCounter(); + st.setName("微型站0"); + st.setAck(270); + st.setIgnore(30); + ranking.add(st); + st = new StationRollcallCounter(); + st.setName("微型站1"); + st.setAck(250); + st.setIgnore(50); + ranking.add(st); + report.setRanking(ranking); + String json = null; + try { + json = JSON.json(report); + }catch (Exception e){ + + } + excelService.saveRollcallReport(report); + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/createstation",method = RequestMethod.POST) + public RespEntity createStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||station.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity old = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(old!=null){ + return new RespEntity(RespCode.EXIST); + } + if(station.getDevice_id()!=null){ + old = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,station.getDevice_id()); + if(old!=null){ + return new RespEntity(RespCode.DEVICE_BOUND); + } + } + station.setCreatetime(new Date(System.currentTimeMillis())); + if(station.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, station); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "STATION", + "创建微站", JsonHelper.convertObjectToStr(station), rel.getCode()); + } + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/deletestation",method = RequestMethod.POST) + public RespEntity deleteStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||station.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity old = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(old==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(stationServices.deleteStation(station)) { + rel = new RespEntity(RespCode.SUCCESS, station); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_DELETE, "STATION", + "删除微站", JsonHelper.convertObjectToStr(station), rel.getCode()); + }else + rel = new RespEntity(RespCode.WARN, station); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/updatestation",method = RequestMethod.POST) + public RespEntity updateStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||station.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity old = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(old==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(station.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, station); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_UPDATE, "STATION", + "修改微站信息", JsonHelper.convertObjectToStr(station), rel.getCode()); + }else + rel = new RespEntity(RespCode.FAIL, station); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstation",method = RequestMethod.POST) + public RespEntity getStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(st!=null) + rel = new RespEntity(RespCode.SUCCESS, st); + else + rel = new RespEntity(RespCode.NOTEXIST, null); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationcount",method = RequestMethod.POST) + public RespEntity getStationCount(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + try { + int count = station.queryCount(dataSource,null,null); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/getorgs",method = RequestMethod.POST) + public RespEntity getOrgByScope(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_CMD); + } + String name = JsonHelper.getStringValue(rootnode,"name"); + if(name == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + UserInfoEntity user = UserInfoEntity.QueryUser(dataSource,name); + if(user == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(name.equals("administrator")){ + + }else{ + + } + + }catch (Exception e){ + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationcountbyscope",method = RequestMethod.POST) + public RespEntity getStationCountByScope(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + List list = SQLTools.getEntityListFromJsonArray(rootnode,FireStationBaseInfoEntity.class); + if(list==null||list.size()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + OrganiztionUri uri = userAuthorManager.getUserScope(request.getHeader("authorization")); + if(uri==null) + return new RespEntity(RespCode.FAIL); + try { + int count = stationServices.queryStationCountByScope(list); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationlist",method = RequestMethod.POST) + public RespEntity getStationList(HttpServletRequest request) { + long start = System.currentTimeMillis(); + RespEntity rel = null; + + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station.getName() == null && station.getBorough() == null && station.getDetachment() == null && station.getBrigade() == null){ + new RespEntity(RespCode.FAIL); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + System.out.println("query station:/firectrl/client/getstationlist pageindex="+pageindex+ "start="+start); + try { + List list = stationServices.queryStationList(station,pagesize,pageindex); + + rel = new RespEntity(RespCode.SUCCESS,list); + logger.debug("query station use time: "+((System.currentTimeMillis()-start))+" milliseconds count="+list.size()); + // System.out.println("query station use time: "+((System.currentTimeMillis()-start))+" milliseconds count="+list.size()); + }catch (Exception e){ + e.printStackTrace(); + System.out.println("query station fail use time: "+((System.currentTimeMillis()-start))+" milliseconds"); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationlistbyscope",method = RequestMethod.POST) + public RespEntity getStationListByScope(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + JsonNode scope = rootnode.get("scope"); + List scopelist = SQLTools.getEntityListFromJsonArray(scope,FireStationBaseInfoEntity.class); + if(scopelist==null||scopelist.size()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + try { + List list = stationServices.queryStationListByScope(scopelist,pagesize,pageindex); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getneighbourstation",method = RequestMethod.POST) + public RespEntity getNeighbourStationList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + double longitude = JsonHelper.getDoubleValue(rootnode,"longitude"); + double latitude = JsonHelper.getDoubleValue(rootnode,"latitude"); + double radius = JsonHelper.getDoubleValue(rootnode,"radius"); + if(latitude<=0||longitude<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(radius<=0) + radius = 0.05; + String sql = "select * from firectrl_station_info_table where longitude>="+(longitude-radius)+" and longitude<="+(longitude+radius)+ + " and latitude>="+(latitude-radius)+" and latitude<="+(latitude+radius); + + try { + List list = SQLTools.ExecuteQuery(dataSource,sql,FireStationBaseInfoEntity.class); + /* ArrayList rl = new ArrayList(); + for(FireStationBaseInfoEntity s:list) { + StationRuningInfo info = fireStationLiveManager.getStationInfo(s.getName()); + if (info!=null&&info.lineState){ + rl.add(s); + } + }*/ + rel = new RespEntity(RespCode.SUCCESS,list); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationequipment",method = RequestMethod.POST) + public RespEntity getStationEquipment(HttpServletRequest request) { + RespEntity rel = null; + System.out.println("/firectrl/client/getstationequipment comein"); + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + System.out.println("station:"+station); + if(station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + List equiplist = null; + if(station.getName()!=null){ + equiplist = stationServices.queryStationEquipmentByName(station.getName()); + } + else if(station.getDevice_id()!=null){ + equiplist = stationServices.queryStationEquipmentByDeviceID(station.getDevice_id()); + }else{ + return new RespEntity(RespCode.NOTEXIST); + } + if(equiplist!=null) + rel = new RespEntity(RespCode.SUCCESS, equiplist); + else + rel = new RespEntity(RespCode.FAIL, station); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + System.out.println("return equpiment");//+rel.toString() + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/updatestationequipment",method = RequestMethod.POST) + public RespEntity updateStationEquipment(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + JsonNode m = rootnode.findValue("stationname"); + String stationname = m.asText(); + JsonNode equips = rootnode.findValue("equipments"); + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + if(!equips.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + if(station==null) + return new RespEntity(RespCode.NOTEXIST); + Map list = new HashMap(); + for(int i=0;i=0) + equipentity.setCount(count); + }else + continue; + equipentity.setType(1); + list.put(equipentity.getInfo_number(),equipentity); + + + }catch (Exception e){ + + } + } + if(list.size()>0) + stationServices.updateStationEquipment(station,list); + rel = new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/addstaff",method = RequestMethod.POST) + public RespEntity addStationStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationStaffInfoEntity.class); + + if(staff==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + rel = stationServices.addStationStaff(staff); + if(rel.getCode()==RespCode.SUCCESS.getCode()){ + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "STAFF", + "添加组员", JsonHelper.convertObjectToStr(staff), rel.getCode()); + } + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/deletestaff",method = RequestMethod.POST) + public RespEntity deleteStationStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationStaffInfoEntity.class); + + if(staff==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + rel = stationServices.deleteStationStaff(staff); + if(rel.getCode()==RespCode.SUCCESS.getCode()){ + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_DELETE, "STAFF", + "删除组员", JsonHelper.convertObjectToStr(staff), rel.getCode()); + } + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationstaff",method = RequestMethod.POST) + public RespEntity getStationStaff(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationStaffInfoEntity st = new FireStationStaffInfoEntity(); + st.setStationName(station.getName()); + List list = st.queryList(dataSource,null,null); + for(SQLDataObject ob:list){ + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)ob; + if(staff!=null) + staff.setPassword(null); + } + if(list!=null) + rel = new RespEntity(RespCode.SUCCESS, list); + else + rel = new RespEntity(RespCode.FAIL, station); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getmutilstationstaff",method = RequestMethod.POST) + public RespEntity getMutilStationStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + System.out.println(json); + if (json != null) { + ObjectMapper mapper = new ObjectMapper(); + try { + ArrayList stafflist = new ArrayList(); + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null||!rootnode.isArray()) + return new RespEntity(RespCode.FAIL, null); + + for(int i=0;i list = st.queryList(dataSource,null,null); + for(SQLDataObject ob:list){ + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)ob; + if(staff!=null) + staff.setPassword(null); + } + if(list!=null) + stafflist.addAll(list); + } + } + + if(stafflist.size()>0) + rel = new RespEntity(RespCode.SUCCESS, stafflist); + else + rel = new RespEntity(RespCode.FAIL); + + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/updatestaff",method = RequestMethod.POST) + public RespEntity updateStationStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + try { + + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationStaffInfoEntity.class); + if(staff==null||staff.getStaffid()==null||staff.getStaffid().length()<=0) + return new RespEntity(RespCode.ERROR_CMD); + if(FireStationStaffInfoEntity.Query(dataSource, staff.getStationName(),staff.getStaffid())==null) + return new RespEntity(RespCode.NOTEXIST); + if(staff.Update(dataSource)){ + rel = new RespEntity(RespCode.SUCCESS); + }else + rel = new RespEntity(RespCode.FAIL); + + if(rel.getCode()==RespCode.SUCCESS.getCode()){ + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_UPDATE, "STAFF", + "更新组员信息", JsonHelper.convertObjectToStr(staff), rel.getCode()); + } + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getonlinetime",method = RequestMethod.POST) + public RespEntity queryStationOnlineTime(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + Date start = SQLTools.StrToDateTime(startstr); + Date end = SQLTools.StrToDateTime(endstr); + + if(start==null||end==null||station==null) + return new RespEntity(RespCode.EXCEPTION); + rel = stationServices.queryStationOnlineTime(station,start,end); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getonjobtime",method = RequestMethod.POST) + public RespEntity queryStationOnSignTime(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + Date start = SQLTools.StrToDateTime(startstr); + Date end = SQLTools.StrToDateTime(endstr); + + if(start==null||end==null||station==null) + return new RespEntity(RespCode.EXCEPTION); + rel = stationServices.queryStationOnSignTime(station,start,end); + + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/settimingjob",method = RequestMethod.POST) + public RespEntity setTimingJob(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + try { + TimingJobEntity job = (TimingJobEntity)SQLTools.getEntityFromJson(rootnode,TimingJobEntity.class); + if(job==null||job.getTriggertime()==null||job.getNumber()==null||job.getNumber().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + JsonNode scope = rootnode.get("scope"); + if(scope!=null) + job.setScope(scope.toString()); + if(!timingJobManager.AddJob(job)) + return new RespEntity(RespCode.EXIST); + else { + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"TIMEROLLCALL", + "定时点名",JsonHelper.convertObjectToStr(job),0); + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/deletetimingjob",method = RequestMethod.POST) + public RespEntity deleteTimingJob(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + try { + TimingJobEntity job = (TimingJobEntity)SQLTools.getEntityFromJson(rootnode,TimingJobEntity.class); + if(job==null||job.getNumber()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + if(!timingJobManager.deleteJob(job)) + return new RespEntity(RespCode.NOTEXIST); + else{ + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"TIMEROLLCALL", + "定时点名",JsonHelper.convertObjectToStr(job),0); + return new RespEntity(RespCode.SUCCESS); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + + @ResponseBody + @RequestMapping(value="/firectrl/client/gettimingjob",method = RequestMethod.POST) + public RespEntity getTimingJobs(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + try { + TimingJobEntity job = (TimingJobEntity)SQLTools.getEntityFromJson(rootnode,TimingJobEntity.class); + if(job==null||job.getUsername()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + TimingJobEntity jb = new TimingJobEntity(); + jb.setUsername(job.getUsername()); + List list = jb.queryAcitveList(dataSource); + + if(list==null||list.size()<=0) + return new RespEntity(RespCode.SUCCESS,null); + else + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/jpush",method = RequestMethod.POST) + public RespEntity sentMessageToDeviceByJpush(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String alias = JsonHelper.getStringValue(rootnode,"alias"); + String tag = JsonHelper.getStringValue(rootnode,"tag"); + String content = JsonHelper.getLevel2(rootnode,"content").toString(); + String title = JsonHelper.getStringValue(rootnode,"title"); + int livetime = JsonHelper.getIntValue(rootnode,"livetime"); + + if(alias!=null&&alias.length()<=0) + alias = null; + if(tag!=null&&tag.length()<=0) + tag = null; + if(livetime<0) + livetime = 0; + try { + if(alias!=null) + JpushClientUtil.sendMessageToDevice("firectrl",alias,title,content,livetime); + else if(tag!=null) + JpushClientUtil.sendNotifyToGroup("firectrl",tag,title,content,livetime); + else + JpushClientUtil.sendMessageToAll("firectrl",title,content,livetime); + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"MESSAGE", + "发送消息",HttpTools.getBodyFromRequest(request),0); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/setstationbound",method = RequestMethod.POST) + public RespEntity setStationBound(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode, "stationName"); + // JsonNode node = JsonHelper.getLevel2(rootnode, "service_bound"); + String service = JsonHelper.getStringValue(rootnode, "service_bound"); + // if(node!=null) + // service = node.toString(); + // node = JsonHelper.getLevel2(rootnode, "venue_bound"); + String venue = JsonHelper.getStringValue(rootnode, "venue_bound");; + // if(node!=null) + // venue = node.toString(); + if (FireStationBaseInfoEntity.Query(dataSource,name) == null) + return new RespEntity(RespCode.NOTEXIST); + + if (service == null && venue == null) + return new RespEntity(RespCode.ERROR_CMD); + + FireStationBoundEntity bound = new FireStationBoundEntity(); + bound.setStationName(name); + bound.setVenue_bound(venue); + bound.setService_bound(service); + if(FireStationBoundEntity.Query(dataSource,name)!=null) + bound.Update(dataSource); + else + bound.Insert(dataSource); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_VERIFY,"STATION", + "设置微站服务范围",venue,0); + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationbound",method = RequestMethod.POST) + public RespEntity getStationBound(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode, "stationName"); + FireStationBoundEntity bound = FireStationBoundEntity.Query(dataSource,name); + return new RespEntity(RespCode.SUCCESS,bound); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/getequipmentverifycount",method = RequestMethod.POST) + public RespEntity queryEquipmentVerifyCount(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallAckEntity rollcallack = (FireStationRollCallAckEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallAckEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + + try { + + EquipmentVerifyEntity verify = new EquipmentVerifyEntity(); + int count = verify.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getequipmentverifylist",method = RequestMethod.POST) + public RespEntity queryEquipmentVerifyList(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + String brigade = JsonHelper.getStringValue(rootnode,"brigade"); + String borough = JsonHelper.getStringValue(rootnode,"borough"); + String detachment = JsonHelper.getStringValue(rootnode,"detachment"); + + + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + try { + EquipmentVerifyEntity verify = new EquipmentVerifyEntity(); + List list = verify.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + ArrayList resp = new ArrayList(); + for(SQLDataObject ob:list){ + EquipmentVerifyEntity v = (EquipmentVerifyEntity)ob; + if(fireStationLiveManager.matchScope(v.getName(),brigade,borough,detachment)) + resp.add(v); + } + return new RespEntity(RespCode.SUCCESS,resp); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getequipmentverify",method = RequestMethod.POST) + public RespEntity queryEquipmentVerify(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode,"name"); + + try { + + EquipmentVerifyEntity verify = EquipmentVerifyEntity.Query(dataSource,name); + if(verify!=null) + return new RespEntity(RespCode.SUCCESS,verify); + else + return new RespEntity(RespCode.NOTEXIST); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/equipmentverify",method = RequestMethod.POST) + public RespEntity EquipmentVerify(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode,"name"); + String confirm = JsonHelper.getStringValue(rootnode,"confirm");//accept refuse ignore + try { + + EquipmentVerifyEntity verify = EquipmentVerifyEntity.Query(dataSource,name); + if(verify==null) + return new RespEntity(RespCode.NOTEXIST); + if(confirm==null) + return new RespEntity(RespCode.ERROR_CMD); + + NoticeEntity notice = new NoticeEntity(); + notice.setNoticeid("" + System.currentTimeMillis()); + notice.setTitle("装备信息修改确认"); + notice.setSender("system"); + notice.setTimestamp(new Date()); + + + if(confirm.equals("accept")){ + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,name); + + notice.setContent("装备信息修改确认通过。"); + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", name, "notify", content, 0); + + if(stationServices.updateStationEquipment(station,verify.getNewSetting())) { + verify.Delete(dataSource); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_VERIFY,"EQUIPMENT", + "确认设备信息修改",verify.getNewSetting(),0); + return new RespEntity(RespCode.SUCCESS); + } + return new RespEntity(RespCode.FAIL); + }else if(confirm.equals("refuse")){ + verify.setStatus("refuse"); + // verify.Update(dataSource); + verify.Delete(dataSource); + notice.setContent("装备信息修改确认未通过。"); + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", name, "notify", content, 0); + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_VERIFY,"EQUIPMENT", + "拒绝设备信息修改",verify.getNewSetting(),0); + return new RespEntity(RespCode.SUCCESS); + }else{ + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstaionversion",method = RequestMethod.POST) + public RespEntity queryStationAppVersion(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String name = JsonHelper.getStringValue(rootnode,"stationName"); + + String version = fireStationLiveManager.getStationAppVersion(name); + return new RespEntity(RespCode.SUCCESS,version); + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/station/property/add",method = RequestMethod.POST) + public RespEntity addStationProperty(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode, "station"); + String name = JsonHelper.getStringValue(rootnode, "name"); + String type = JsonHelper.getStringValue(rootnode, "type"); + String property = JsonHelper.getStringValue(rootnode, "property"); + if (station == null || station.length() <= 0 ||name == null || name.length() <= 0 || type == null || type.length() <= 0 || property == null || property.length() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,station); + if (st == null) + return new RespEntity(RespCode.NOTEXIST); + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setStation(station); + pro.setName(name); + pro.setType(type); + pro.setProperty(property); + if (pro.addProperty(dataSource)) { + + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"PROPERTY", + "设置微站属性值",HttpTools.getBodyFromRequest(request),rel.getCode()); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/station/property/delete",method = RequestMethod.POST) + public RespEntity deleteStationProperty(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode, "station"); + String name = JsonHelper.getStringValue(rootnode, "name"); + String type = JsonHelper.getStringValue(rootnode, "type"); + String property = JsonHelper.getStringValue(rootnode, "property"); + if (station == null || station.length() <= 0 ) + return new RespEntity(RespCode.ERROR_REQUEST); + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,station); + if (st == null) + return new RespEntity(RespCode.NOTEXIST); + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setStation(station); + pro.setName(name); + pro.setType(type); + pro.setProperty(property); + if (pro.Delete(dataSource)) { + + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"PROPERTY", + "删除微站属性值",HttpTools.getBodyFromRequest(request),rel.getCode()); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/station/property/get",method = RequestMethod.POST) + public RespEntity getStationProperty(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode, "station"); + String name = JsonHelper.getStringValue(rootnode, "name"); + String type = JsonHelper.getStringValue(rootnode, "type"); + + if ((station == null || station.length() <= 0)) + return new RespEntity(RespCode.ERROR_REQUEST); + + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setStation(station); + pro.setName(name); + pro.setType(type); + List list = pro.queryList(dataSource,null,null); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getdistance",method = RequestMethod.POST) + public RespEntity getDistanceList(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + List list = (List)SQLTools.getEntityListFromJsonArray(rootnode,O2DDistanceInfo.class); + if(list==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + for(O2DDistanceInfo info:list){ + try{ + String url = "https://restapi.amap.com/v3/direction/walking?origin="; + try { + String key = "0ae6456395501ef661f282eb0093bdec"; + url += info.getLongitude()+","+info.getLatitude()+"&destination="+info.getDestlongitude()+","+info.getDestlatitude()+ + "&extensions=all&output=json&key="+key; + HttpURLConnection connection = HttpTools.createHttpConnection(url); + connection.setRequestMethod("GET"); + connection.connect(); + info.setDuration(-1); + info.setDistance(-1); + + int responseCode = connection.getResponseCode(); + if(responseCode == HttpURLConnection.HTTP_OK){ + String json = HttpTools.getBodyFromRespone(connection); + + JsonNode pathnode = JsonHelper.parseBodyLevel1(json); + String result = JsonHelper.getStringValue(pathnode,"info"); + if(result==null||!result.equals("ok")) + continue; + pathnode = JsonHelper.getLevel2(pathnode,"route"); + if(pathnode==null) + continue; + pathnode = JsonHelper.getLevel2(pathnode,"paths"); + if(pathnode==null||!pathnode.isArray()||pathnode.size()<=0) + continue; + for(int i=0;i=Integer.parseInt(distance)){ + info.setDistance(Integer.parseInt(distance)); + info.setDuration(Integer.parseInt(duration)); + } + }catch (Exception e){ + + } + } + + } + + }catch (Exception e){ + + } + + }catch (Exception e){ + + } + } + + return new RespEntity(RespCode.SUCCESS, list); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/fireunit/add",method = RequestMethod.POST) + public RespEntity addFireUnit(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + FireUnitEntity unit = (FireUnitEntity) SQLTools.getEntityFromJson(rootnode, FireUnitEntity.class); + if (unit == null || unit.getFireunitname() == null || unit.getFireunitname().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if(FireUnitEntity.Query(dataSource,unit.getFireunitname())!=null){ + return new RespEntity(RespCode.EXIST); + } + if (unit.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"FIREUNIT", + "添加消防队",JsonHelper.convertObjectToStr(unit),rel.getCode()); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/fireunit/delete",method = RequestMethod.POST) + public RespEntity deleteFireUnit(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String unitname = JsonHelper.getStringValue(rootnode, "fireunitname"); + + if (unitname == null || unitname.length() <= 0 ) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(FireUnitEntity.Query(dataSource,unitname)==null) { + return new RespEntity(RespCode.NOTEXIST); + } + FireUnitEntity unit = new FireUnitEntity(); + unit.setFireunitname(unitname); + + if (unit.Delete(dataSource)) { + + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"FIREUNIT", + "删除消防队",unitname,rel.getCode()); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/fireunit/update",method = RequestMethod.POST) + public RespEntity updateFireUnit(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + FireUnitEntity unit = (FireUnitEntity) SQLTools.getEntityFromJson(rootnode, FireUnitEntity.class); + if (unit == null || unit.getFireunitname() == null || unit.getFireunitname().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if(FireUnitEntity.Query(dataSource,unit.getFireunitname())==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (unit.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"FIREUNIT", + "更改消防队",JsonHelper.convertObjectToStr(unit),rel.getCode()); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/fireunit/getlist",method = RequestMethod.POST) + public RespEntity getFireUnitList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireUnitEntity unit = (FireUnitEntity) SQLTools.getEntityFromJson(rootnode, FireUnitEntity.class); + if(unit==null) + unit = new FireUnitEntity(); + + List list = unit.queryList(dataSource,null,null); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/reportfile/generate",method = RequestMethod.POST) + public RespEntity generateReportFile(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode,"station"); + String content = JsonHelper.getStringValue(rootnode,"content"); + String url = JsonHelper.getStringValue(rootnode,"url"); + + String head = ""; + String tail = ""; + + String filepath = envConfigService.getStationReportFilePath()+"\\"+station+".html"; + FileOutputStream out = null; + try { + out = new FileOutputStream(new File(filepath)); + out.write(head.getBytes("UTF-8")); + out.write(content.getBytes("UTF-8")); + out.write(tail.getBytes("UTF-8")); + }catch (Exception e){ + e.printStackTrace(); + }finally { + try{ + if(out!=null) + out.close(); + }catch (Exception ee){ + + } + } + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/reportfile/query",method = RequestMethod.POST) + public RespEntity queryReportFile(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode,"station"); + String content = null; + + String filepath = envConfigService.getStationReportFilePath()+"\\"+station+".html"; + File file = new File(filepath); + + if(!file.exists()) + return new RespEntity(RespCode.NOTEXIST); + + FileInputStream in= null; + try { + + in = new FileInputStream(file); + int filelen = in.available(); + if(filelen<=0) + return new RespEntity(RespCode.EMPTY); + byte [] data = new byte[filelen]; + in.read(data); + content = new String(data,"UTF-8"); + in.close(); + }catch (Exception e){ + e.printStackTrace(); + }finally { + try{ + if(in!=null) + in.close(); + }catch (Exception ee){ + + } + } + + if(content!=null){ + if(content.length()<=61) + return new RespEntity(RespCode.FAIL); + content = content.substring(47,content.length()-14); + } + return new RespEntity(RespCode.SUCCESS,content); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/station/runtimecache/query",method = RequestMethod.POST) + public RespEntity queryStationRuntimeCache(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode,"station"); + // if(station==null||FireStationBaseInfoEntity.Query(dataSource,station)==null) + // return new RespEntity(RespCode.NOTEXIST); + + FireStationRuntimeStatusCacheEntity cache = (FireStationRuntimeStatusCacheEntity)SQLTools.getEntityFromJson(rootnode, FireStationRuntimeStatusCacheEntity.class); + if(cache==null) + new FireStationRuntimeStatusCacheEntity(); + + if(rootnode.get("sum1")==null) + cache.setSum1(-1); + + if(rootnode.get("sum2")==null) + cache.setSum2(-1); + List list = cache.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/person/add",method = RequestMethod.POST) + public RespEntity addPersonInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if (per == null || per.getStaffid() == null || per.getStaffid().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null || per.getStation().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if(per.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (per.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"PERSONINFO", + "添加人员",JsonHelper.convertObjectToStr(per),rel.getCode()); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/person/delete",method = RequestMethod.POST) + public RespEntity deletePersonInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if (per == null || per.getStaffid() == null || per.getStaffid().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null || per.getStation().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + + + if (per.Delete(dataSource)) { + + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"PERSONINFO", + "删除人员",JsonHelper.convertObjectToStr(per),rel.getCode()); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/person/update",method = RequestMethod.POST) + public RespEntity updatePersonInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if (per == null || per.getStaffid() == null || per.getStaffid().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null || per.getStation().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if (per.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"PERSONINFO", + "更改人员信息",JsonHelper.convertObjectToStr(per),rel.getCode()); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/person/getlist",method = RequestMethod.POST) + public RespEntity getPersonInfoList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if(per==null) + per = new PersonInfoEntity(); + + List list = per.queryList(dataSource,null,null); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/map/delete",method = RequestMethod.POST) + public RespEntity deleteStationMap(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationMapInfoEntity map = (FireStationMapInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationMapInfoEntity.class); + + if(map==null||map.getStation()==null||map.getMapid()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + map = (FireStationMapInfoEntity)map.QueryIt(dataSource); + if(map==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(map.deleteRecords(dataSource,null,null)) { + String path = "./stationmap/"+map.getStation()+"/"+map.getMapid()+".jpg"; + File file = new File(path); + try{ + file.delete(); + }catch (Exception delex){ + + } + rel = new RespEntity(RespCode.SUCCESS, map); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_DELETE, "STATIONMAP", + "删除微站地图", JsonHelper.convertObjectToStr(map), rel.getCode()); + }else + rel = new RespEntity(RespCode.WARN, map); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/map/update",method = RequestMethod.POST) + public RespEntity updateStationMap(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationMapInfoEntity map = (FireStationMapInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationMapInfoEntity.class); + + if(map==null||map.getStation()==null||map.getMapid()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationMapInfoEntity old = (FireStationMapInfoEntity)map.QueryIt(dataSource); + if(old==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(old.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, old); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_UPDATE, "STATIONMAP", + "修改微站地图信息", JsonHelper.convertObjectToStr(old), rel.getCode()); + }else + rel = new RespEntity(RespCode.FAIL, old); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/map/getcount",method = RequestMethod.POST) + public RespEntity getStationMapCount(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationMapInfoEntity map = (FireStationMapInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationMapInfoEntity.class); + try { + int count = map.queryCount(dataSource,null,null); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/map/getpage",method = RequestMethod.POST) + public RespEntity getStationMapPage(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationMapInfoEntity map = (FireStationMapInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationMapInfoEntity.class); + try { + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + if (map == null) + map = new FireStationMapInfoEntity(); + List list = map.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/updatestationdata",method = RequestMethod.POST) + public RespEntity updateStationData(HttpServletRequest request) { + RespEntity rel = null; + String json = HttpTools.getBodyFromRequest(request); + System.out.println("updatestationdata: " + json); + + // JsonNode rootnode=HttpTools.getJsonFromRequest(request); + // FireStationSchoolEntity stationData = (FireStationSchoolEntity)SQLTools.getEntityFromJson(rootnode,FireStationSchoolEntity.class); + + FireStationSchoolEntity stationData = JSONObject.parseObject(json, FireStationSchoolEntity.class); + if(stationData==null||stationData.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + FireStationSchoolEntity oldData = (FireStationSchoolEntity)stationData.QueryIt(dataSource); + System.out.println("updateStationData 2: " + JSONObject.toJSONString(oldData)); + try { + if(oldData == null){ + if(stationData.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, stationData); + }else + rel = new RespEntity(RespCode.FAIL, stationData); + }else{ + if(stationData.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, stationData); + }else + rel = new RespEntity(RespCode.FAIL, stationData); + } + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationdata",method = RequestMethod.POST) + public RespEntity getStationData(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationSchoolEntity stationData = (FireStationSchoolEntity)SQLTools.getEntityFromJson(rootnode,FireStationSchoolEntity.class); + + if(stationData==null||stationData.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + FireStationSchoolEntity oldData = (FireStationSchoolEntity)stationData.QueryIt(dataSource); + try { + if(oldData == null){ + rel = new RespEntity(RespCode.FAIL); + }else{ + System.out.println("getstationdata: " + JsonHelper.convertObjectToStr(oldData)); + rel = new RespEntity(RespCode.SUCCESS, oldData); + } + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationsdata",method = RequestMethod.POST) + public RespEntity getStationsData(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationSchoolEntity stationData = (FireStationSchoolEntity)SQLTools.getEntityFromJson(rootnode,FireStationSchoolEntity.class); + + if(stationData==null||stationData.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = stationData.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeman/getlist",method = RequestMethod.POST) + public RespEntity getPolicemanList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PolicemanInfo policemanInfo = (PolicemanInfo)SQLTools.getEntityFromJson(rootnode,PolicemanInfo.class); + + if(policemanInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(policemanInfo.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = policemanInfo.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeman/add",method = RequestMethod.POST) + public RespEntity addPolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(per.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (per.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeman/delete",method = RequestMethod.POST) + public RespEntity deletePolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (per.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeman/update",method = RequestMethod.POST) + public RespEntity updatePolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (per.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + /* + **** person quarter info **** + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/quarter/getlist",method = RequestMethod.POST) + public RespEntity getQuarterList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + QuarterInfo quarterInfo = (QuarterInfo)SQLTools.getEntityFromJson(rootnode,QuarterInfo.class); + + if(quarterInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(quarterInfo.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = quarterInfo.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/quarter/add",method = RequestMethod.POST) + public RespEntity addQuarterInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + QuarterInfo quarterInfo = (QuarterInfo) SQLTools.getEntityFromJson(rootnode, QuarterInfo.class); + if (quarterInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if (quarterInfo.getName() == null || quarterInfo.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(quarterInfo.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (quarterInfo.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/quarter/delete",method = RequestMethod.POST) + public RespEntity deleteQuarterInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + QuarterInfo quarterInfo = (QuarterInfo) SQLTools.getEntityFromJson(rootnode, QuarterInfo.class); + if (quarterInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( quarterInfo.getBrigade() == null || quarterInfo.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (quarterInfo.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/quarter/update",method = RequestMethod.POST) + public RespEntity updateQuarterInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + QuarterInfo quarterInfo = (QuarterInfo) SQLTools.getEntityFromJson(rootnode, QuarterInfo.class); + if (quarterInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( quarterInfo.getBrigade() == null || quarterInfo.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (quarterInfo.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + /* + **** police room info **** + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/policeroom/getlist",method = RequestMethod.POST) + public RespEntity getPoliceroomList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PoliceRoomInfo quarterInfo = (PoliceRoomInfo)SQLTools.getEntityFromJson(rootnode,PoliceRoomInfo.class); + + if(quarterInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(quarterInfo.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = quarterInfo.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeroom/add",method = RequestMethod.POST) + public RespEntity addPoliceroomInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PoliceRoomInfo roomInfo = (PoliceRoomInfo) SQLTools.getEntityFromJson(rootnode, PoliceRoomInfo.class); + if (roomInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if (roomInfo.getName() == null || roomInfo.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(roomInfo.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (roomInfo.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeroom/delete",method = RequestMethod.POST) + public RespEntity deletePoliceroomInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + PoliceRoomInfo roomInfo = (PoliceRoomInfo) SQLTools.getEntityFromJson(rootnode, PoliceRoomInfo.class); + if (roomInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( roomInfo.getBrigade() == null || roomInfo.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (roomInfo.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/policeroom/update",method = RequestMethod.POST) + public RespEntity updatePoliceroomInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PoliceRoomInfo roomInfo = (PoliceRoomInfo) SQLTools.getEntityFromJson(rootnode, PoliceRoomInfo.class); + if (roomInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( roomInfo.getBrigade() == null || roomInfo.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (roomInfo.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + /* + **** query statistics info **** + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/calc_station_day",method = RequestMethod.POST) + public RespEntity calcAllStatistics(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StatisticsMessage msg = (StatisticsMessage)SQLTools.getEntityFromJson(rootnode,StatisticsMessage.class); + + if(msg==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(msg.getYear() <= 0 || msg.getMonth() <= 0|| msg.getDay() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(msg.getBrigade() == null|| msg.getBorough() == null || msg.getStation() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + msg.setCode(StatisticsMessage.School_Day_Summary_Code); + + dataStatisticsService.addStatisticsMessage(msg); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个station按月查询每天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/station_month_days_list",method = RequestMethod.POST) + public RespEntity getStationDaysSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StationDaySummaryEntity stationDaySummary = (StationDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,StationDaySummaryEntity.class); + + if(stationDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationDaySummary.getYear() <= 0 || stationDaySummary.getMonth() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationDaySummary.getBrigade() == null || stationDaySummary.getStation() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = stationDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***多个station查询某一天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/stations_one_day_list",method = RequestMethod.POST) + public RespEntity getStationsOneDaySummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StationDaySummaryEntity stationDaySummary = (StationDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,StationDaySummaryEntity.class); + + if(stationDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationDaySummary.getYear() <= 0 || stationDaySummary.getMonth() <= 0 || stationDaySummary.getDay() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = stationDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***多个station查询当天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/stations_last_list",method = RequestMethod.POST) + public RespEntity getStationsLastSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StationDaySummaryEntity stationDaySummary = (StationDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,StationDaySummaryEntity.class); + + if(stationDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + Calendar calendarTime = Calendar.getInstance(); + int nYear = calendarTime.get(Calendar.YEAR); + int nMonth =calendarTime.get(Calendar.MONTH)+1; + int nDay = calendarTime.get(Calendar.DAY_OF_MONTH); + stationDaySummary.setYear(nYear); + stationDaySummary.setMonth(nMonth); + stationDaySummary.setDay(nDay); + + List list = stationDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sign/get_signed_schools",method = RequestMethod.POST) + public RespEntity getSignedSchoolList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StationDaySummaryEntity stationDaySummary = (StationDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,StationDaySummaryEntity.class); + + if(stationDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + Calendar calendarTime = Calendar.getInstance(); + int nYear = calendarTime.get(Calendar.YEAR); + int nMonth =calendarTime.get(Calendar.MONTH)+1; + int nDay = calendarTime.get(Calendar.DAY_OF_MONTH); + stationDaySummary.setYear(nYear); + stationDaySummary.setMonth(nMonth); + stationDaySummary.setDay(nDay); + + List list = StationDaySummaryEntity.QuerySignedSchoolOneDay(dataSource, stationDaySummary.getBrigade(), nYear, nMonth, nDay); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个station查询多个月度数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/station_months_list",method = RequestMethod.POST) + public RespEntity getStationMonthsSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StationMonthSummaryEntity stationMonthSummary = (StationMonthSummaryEntity)SQLTools.getEntityFromJson(rootnode,StationMonthSummaryEntity.class); + + if(stationMonthSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationMonthSummary.getYear() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationMonthSummary.getBrigade() == null || stationMonthSummary.getStation() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = stationMonthSummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***多个station查询某一个月月度数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/stations_one_month_list",method = RequestMethod.POST) + public RespEntity getStationsOneMonthSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StationMonthSummaryEntity stationMonthSummary = (StationMonthSummaryEntity)SQLTools.getEntityFromJson(rootnode,StationMonthSummaryEntity.class); + + if(stationMonthSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationMonthSummary.getYear() <= 0 || stationMonthSummary.getMonth() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(stationMonthSummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = stationMonthSummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个borough按月查询每天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/borough_month_days_list",method = RequestMethod.POST) + public RespEntity getBoroughDaysSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughDaySummaryEntity boroughDaySummary = (BoroughDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,BoroughDaySummaryEntity.class); + + if(boroughDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughDaySummary.getYear() <= 0 || boroughDaySummary.getMonth() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughDaySummary.getBrigade() == null || boroughDaySummary.getBorough() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = boroughDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***多个borough查询某一天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/boroughs_one_day_list",method = RequestMethod.POST) + public RespEntity getBoroughsOneDaySummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughDaySummaryEntity boroughDaySummary = (BoroughDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,BoroughDaySummaryEntity.class); + + if(boroughDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughDaySummary.getYear() <= 0 || boroughDaySummary.getMonth() <= 0 || boroughDaySummary.getDay() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = boroughDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***多个borough查询当天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/boroughs_last_list",method = RequestMethod.POST) + public RespEntity getBoroughsLastSummaryList(HttpServletRequest request) { + /* + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughLastDaySummaryEntity boroughLastSummary = (BoroughLastDaySummaryEntity)SQLTools.getEntityFromJson(rootnode, BoroughLastDaySummaryEntity.class); + + if(boroughLastSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughLastSummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = boroughLastSummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + + */ + + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughDaySummaryEntity boroughDaySummary = (BoroughDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,BoroughDaySummaryEntity.class); + + if(boroughDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(boroughDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + Calendar calendarTime = Calendar.getInstance(); + int nYear = calendarTime.get(Calendar.YEAR); + int nMonth =calendarTime.get(Calendar.MONTH)+1; + int nDay = calendarTime.get(Calendar.DAY_OF_MONTH); + boroughDaySummary.setYear(nYear); + boroughDaySummary.setMonth(nMonth); + boroughDaySummary.setDay(nDay); + List list = boroughDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个borough查询多个月度数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/borough_months_list",method = RequestMethod.POST) + public RespEntity getBoroughMonthsSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughMonthSummaryEntity boroughMonthSummary = (BoroughMonthSummaryEntity)SQLTools.getEntityFromJson(rootnode,BoroughMonthSummaryEntity.class); + + if(boroughMonthSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughMonthSummary.getYear() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughMonthSummary.getBrigade() == null || boroughMonthSummary.getBorough() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = boroughMonthSummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***多个borough查询某一个月月度数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/boroughs_one_month_list",method = RequestMethod.POST) + public RespEntity getBoroughsOneMonthSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughMonthSummaryEntity boroughMonthSummary = (BoroughMonthSummaryEntity)SQLTools.getEntityFromJson(rootnode,BoroughMonthSummaryEntity.class); + + if(boroughMonthSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughMonthSummary.getYear() <= 0 || boroughMonthSummary.getMonth() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughMonthSummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = boroughMonthSummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个brigade按月查询每天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/brigade_month_days_list",method = RequestMethod.POST) + public RespEntity getBrigadeDaysSummaryList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BrigadeDaySummaryEntity brigadeDaySummary = (BrigadeDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,BrigadeDaySummaryEntity.class); + + if(brigadeDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(brigadeDaySummary.getYear() <= 0 || brigadeDaySummary.getMonth() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(brigadeDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = brigadeDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个brigade查询当天数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/brigade_last_day",method = RequestMethod.POST) + public RespEntity getBrigadeLastSummaryList(HttpServletRequest request) { + /* + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BrigadeLastDaySummaryEntity brigadeLastSummary = (BrigadeLastDaySummaryEntity)SQLTools.getEntityFromJson(rootnode, BrigadeLastDaySummaryEntity.class); + + if(brigadeLastSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(brigadeLastSummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + BrigadeLastDaySummaryEntity oldData = (BrigadeLastDaySummaryEntity)brigadeLastSummary.QueryIt(dataSource); + if(oldData == null){ + rel = new RespEntity(RespCode.FAIL); + }else{ + rel = new RespEntity(RespCode.SUCCESS, oldData); + } + return rel; + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + + */ + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BrigadeDaySummaryEntity brigadeDaySummary = (BrigadeDaySummaryEntity)SQLTools.getEntityFromJson(rootnode,BrigadeDaySummaryEntity.class); + + if(brigadeDaySummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(brigadeDaySummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + Calendar calendarTime = Calendar.getInstance(); + int nYear = calendarTime.get(Calendar.YEAR); + int nMonth =calendarTime.get(Calendar.MONTH)+1; + int nDay = calendarTime.get(Calendar.DAY_OF_MONTH); + brigadeDaySummary.setYear(nYear); + brigadeDaySummary.setMonth(nMonth); + brigadeDaySummary.setDay(nDay); + List list = brigadeDaySummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + ***单个brigade查询多个月度数据 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/statistics/brigade_months_list",method = RequestMethod.POST) + public RespEntity getBrigadeMonthsSummaryList(HttpServletRequest request) { + //TODO: + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughMonthSummaryEntity boroughMonthSummary = (BoroughMonthSummaryEntity)SQLTools.getEntityFromJson(rootnode,BoroughMonthSummaryEntity.class); + + if(boroughMonthSummary==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughMonthSummary.getYear() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughMonthSummary.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = boroughMonthSummary.queryPage(dataSource, null, null, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientNoticeController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientNoticeController.java new file mode 100644 index 0000000..a4dd390 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientNoticeController.java @@ -0,0 +1,1258 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.clientmanage.model.BrigadeEntity; +import com.jingyi.iotserver.clientmanage.model.DetachmentEntity; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.AssignmentAnalyzeInfo; +import com.jingyi.iotserver.firestationport.model.complexquery.NoticeAnalyzeInfo; +import com.jingyi.iotserver.firestationport.model.complexquery.StationAssignmentAnalyzeInfo; +import com.jingyi.iotserver.firestationport.model.complexquery.StationNoticeAnalyzeInfo; +import com.jingyi.iotserver.firestationport.model.todev.*; + +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentMQTTMessage; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class +FireStationClientNoticeController { + + @Autowired + private DataSource dataSource; + + @Autowired + private UserAuthorManager userAuthorManager; + @Autowired + private MessagePublisher messagePublisher; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/send", method = RequestMethod.POST) + public RespEntity sendNoticeToStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + NoticeEntity notice = (NoticeEntity) SQLTools.getEntityFromJson(rootnode, NoticeEntity.class); + int livetime = JsonHelper.getIntValue(rootnode,"livetime"); + if(livetime<=0){ + livetime = 24*60*60; + } + if (notice == null || notice.getNoticeid() == null || notice.getNoticeid().length() <= 0 || + notice.getReceiver() == null || notice.getReceiver().length() <= 0 || + notice.getSendtype() == null || notice.getSendtype().length() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if (NoticeEntity.QueryNotice(dataSource, notice.getNoticeid()) != null) + return new RespEntity(RespCode.EXIST); + + try { + notice.setTimestamp(new Date()); + if (!notice.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + String content = JsonHelper.convertObjectToStr(notice); + if (content == null) + return new RespEntity(RespCode.ERROR_REQUEST); + String [] receivers = notice.getReceiver().split("##"); + if(receivers==null||receivers.length<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i list = notice.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/getstatus", method = RequestMethod.POST) + public RespEntity getNoticeStatus(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String noticeid = JsonHelper.getStringValue(rootnode, "noticeid"); + + if (noticeid == null) + return new RespEntity(RespCode.NOTEXIST); + NoticeEntity notice = NoticeEntity.QueryNotice(dataSource, noticeid); + if(notice==null) + return new RespEntity(RespCode.NOTEXIST); + NoticeStatusEntity status = new NoticeStatusEntity(); + status.setId(notice.getId()); + status.setNoticeid(noticeid); + status.extendName(""+notice.getId()); + List list = status.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/analyzeold", method = RequestMethod.POST) + public RespEntity getNoticeAnalyzeInfoold(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + NoticeEntity notice = (NoticeEntity) SQLTools.getEntityFromJson(rootnode, NoticeEntity.class); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + String receiver = JsonHelper.getStringValue(rootnode, "receiver"); + int pagesize = 100; + int pageindex = 0; + if (notice == null) + notice = new NoticeEntity(); + List list = null; + int noticecount = 0; + int receivedcount = 0; + int readcount = 0; + + int total = 0; + do { + list = notice.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + if(list!=null) + noticecount += list.size(); + for(SQLDataObject ob:list){ + NoticeEntity asi = (NoticeEntity)ob; + NoticeStatusEntity status = new NoticeStatusEntity(); + status.extendName(""+asi.getId()); + status.setId(asi.getId()); + if(asi.getBrigade()!=null||asi.getBorough()!=null||asi.getDetachment()!=null||asi.getStation()!=null){ + FireStationBaseInfoEntity station = new FireStationBaseInfoEntity(); + station.setName(asi.getStation()); + station.setBrigade(asi.getBrigade()); + station.setBorough(asi.getBorough()); + station.setDetachment(asi.getDetachment()); + total += station.queryCount(dataSource,null,null); + } + List statuslist = status.queryList(dataSource,null,null); + if(statuslist==null) + continue; + for(SQLDataObject sob:statuslist){ + NoticeStatusEntity ass = (NoticeStatusEntity)sob; + String state = ass.getState(); + if(state==null) + continue; + if(state.equals("received" )){ + receivedcount++; + }else if(state.equals("read")){ + readcount++; + } + } + } + }while(list!=null&&list.size()==100); + + NoticeAnalyzeInfo info = new NoticeAnalyzeInfo(); + info.noticecount = noticecount; + info.receivedcount = receivedcount; + info.readcount = readcount; + info.total = total; + return new RespEntity(RespCode.SUCCESS, info); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + private int NoticeInfoScope(NoticeEntity as,OrganiztionUri uri){ + int total = 0; + if (as.getSendtype() != null && as.getSendtype().equals("toclient")) { + String[] receivers = as.getReceiver().split("##"); + for(int i=0;i list = qury.queryList(dataSource, startstr, endstr); + if(uri==null) { + uri = new OrganiztionUri(); + } + int noticecount = 0; + int receivedcount = 0; + int readcount = 0; + int total = 0; + + { + if(list!=null){ + for(SQLDataObject ob:list){ + try { + NoticeEntity as = (NoticeEntity) ob; + + if (as != null) { + int bereceicecount = NoticeInfoScope(as,uri); + if(bereceicecount>0) + noticecount++; + total += bereceicecount; + + NoticeStatusEntity status = new NoticeStatusEntity(); + status.setId(as.getId()); + status.extendName(""+as.getId()); + List statuslist = status.queryList(dataSource,null,null); + if(statuslist==null) + continue; + for(SQLDataObject asob:statuslist){ + NoticeStatusEntity ass = (NoticeStatusEntity)asob; + String state = ass.getState(); + if(state==null) + continue; + if(state.equals("received" )){ + receivedcount++; + }else if(state.equals("read")){ + readcount++; + } + } + } + }catch (Exception e){ + + } + } + } + } + + NoticeAnalyzeInfo info = new NoticeAnalyzeInfo(); + info.noticecount = noticecount; + info.receivedcount = receivedcount; + info.readcount = readcount; + info.total = total; + return new RespEntity(RespCode.SUCCESS, info); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/multi-analyze", method = RequestMethod.POST) + public RespEntity getNoticeMultiAnalyzeInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + OrganiztionUri uri = (OrganiztionUri) SQLTools.getEntityFromJson(rootnode, OrganiztionUri.class); + + JsonNode timesnode = JsonHelper.getLevel2(rootnode,"times"); + if(timesnode==null||!timesnode.isArray()||timesnode.size()<=0) + return new RespEntity(RespCode.FAIL); + + ArrayList infolist = new ArrayList(); + for(int i=0;i list = qury.queryList(dataSource, startstr, endstr); + if(uri==null) { + uri = new OrganiztionUri(); + } + int noticecount = 0; + int receivedcount = 0; + int readcount = 0; + int total = 0; + + { + if(list!=null){ + for(SQLDataObject ob:list){ + try { + NoticeEntity as = (NoticeEntity) ob; + + if (as != null) { + int bereceicecount = NoticeInfoScope(as,uri); + if(bereceicecount>0) + noticecount++; + total += bereceicecount; + + NoticeStatusEntity status = new NoticeStatusEntity(); + status.setId(as.getId()); + status.extendName(""+as.getId()); + List statuslist = status.queryList(dataSource,null,null); + if(statuslist==null) + continue; + for(SQLDataObject asob:statuslist){ + NoticeStatusEntity ass = (NoticeStatusEntity)asob; + String state = ass.getState(); + if(state==null) + continue; + if(state.equals("received" )){ + receivedcount++; + }else if(state.equals("read")){ + readcount++; + } + } + } + }catch (Exception e){ + + } + } + } + } + NoticeAnalyzeInfo info = new NoticeAnalyzeInfo(); + info.noticecount = noticecount; + info.receivedcount = receivedcount; + info.readcount = readcount; + info.total = total; + info.setIndex(index); + infolist.add(info); + } + + return new RespEntity(RespCode.SUCCESS, infolist); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/stationreport", method = RequestMethod.POST) + public RespEntity getStationNoticeReport(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String station = JsonHelper.getStringValue(rootnode, "station"); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + NoticeEntity notice =new NoticeEntity(); + FireStationBaseInfoEntity s = FireStationBaseInfoEntity.Query(dataSource,station); + if(s==null) + return new RespEntity(RespCode.NOTEXIST); + int index=0; + + List list = null; + StationNoticeAnalyzeInfo info = new StationNoticeAnalyzeInfo(); + int noticecount = 0; + int readcount = 0; + + ArrayList infolist = new ArrayList(); + do { + list = notice.queryPage(dataSource, startstr, endstr, index, 1000); + if(list!=null){ + for(SQLDataObject ob:list){ + NoticeEntity as = (NoticeEntity)ob; + try { + boolean add = false; + String[] receivers = as.getReceiver().split("##"); + if (as.getStation() != null) { + if(checkeReceiver(receivers,station)) + add = true; + } else if (as.getDetachment() != null) { + if(checkeReceiver(receivers,s.getDetachment())) + add = true; + }else if (as.getBorough() != null) { + if(checkeReceiver(receivers,s.getBorough())) + add = true; + }else if (as.getBrigade() != null) { + if(checkeReceiver(receivers,s.getBrigade())) + add = true; + } + if(add) { + StationNoticeAnalyzeInfo.StationNoticeInfo in = info.allocinfo(); + NoticeStatusEntity status = new NoticeStatusEntity(); + status.extendName(""+as.getId()); + status.setId(as.getId()); + status.setStation(station); + status.setNoticeid(as.getNoticeid()); + status = (NoticeStatusEntity)status.QueryIt(dataSource); + in.setNotice(as); + in.setStatus(status); + infolist.add(in); + noticecount++; + if(status!=null){ + if(status.getState().equals("read")) + readcount++; + } + } + }catch (Exception e){ + + } + } + } + index++; + }while(list!=null&&list.size()>=1000); + + info.setNoticecount(noticecount); + info.setReadcount(readcount); + info.setList(infolist); + return new RespEntity(RespCode.SUCCESS, info); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value = "/firectrl/client/assignment/send", method = RequestMethod.POST) + public RespEntity sendAssignmentToStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + AssignmentEntity assignment = (AssignmentEntity) SQLTools.getEntityFromJson(rootnode, AssignmentEntity.class); + int livetime = JsonHelper.getIntValue(rootnode,"livetime"); + if(livetime<=0){ + livetime = 24*60*60; + } + + if (assignment == null || assignment.getAssignmentid() == null || assignment.getAssignmentid().length() <= 0 || + assignment.getReceiver() == null || assignment.getReceiver().length() <= 0 || + assignment.getSendtype() == null || assignment.getSendtype().length() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + if (AssignmentEntity.QueryAssignment(dataSource, assignment.getAssignmentid()) != null) + return new RespEntity(RespCode.EXIST); + + try { + assignment.setTimestamp(new Date()); + if (!assignment.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + String content = JsonHelper.convertObjectToStr(assignment); + if (content == null) + return new RespEntity(RespCode.ERROR_REQUEST); + String [] receivers = assignment.getReceiver().split("##"); + if(receivers==null||receivers.length<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i list = assignment.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + private boolean staionInUri(FireStationBaseInfoEntity st,OrganiztionUri uri){ + if(st==null) + return false; + if(uri==null) + return true; + if(uri.station!=null){ + if(uri.station.equals(st.getName())) + return true; + else + return false; + }else if(uri.detachment!=null){ + if(uri.detachment.equals(st.getDetachment())) + return true; + else + return false; + }else if(uri.borough!=null){ + if(uri.borough.equals(st.getBorough())) + return true; + else + return false; + }else if(uri.brigade!=null){ + if(uri.brigade.equals(st.getBrigade())) + return true; + else + return false; + } + return false; + } + @ResponseBody + @RequestMapping(value = "/firectrl/client/assignment/getlistbyscope", method = RequestMethod.POST) + public RespEntity getAssignmentListByScope(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + OrganiztionUri uri = (OrganiztionUri) SQLTools.getEntityFromJson(rootnode, OrganiztionUri.class); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + AssignmentEntity qury = new AssignmentEntity(); + List list = qury.queryList(dataSource, startstr, endstr); + + ArrayList rellist = new ArrayList(); + if(uri==null||(uri.brigade==null&&uri.borough==null&&uri.detachment==null&&uri.station==null)){ + if(list!=null) + rellist.addAll(list); + }else{ + if(list!=null){ + for(SQLDataObject ob:list){ + try { + AssignmentEntity as = (AssignmentEntity) ob; + if (as != null) { + if (as.getSendtype() != null && as.getSendtype().equals("toclient")) { + String[] receivers = as.getReceiver().split("##"); + for(int i=0;i resultlist = new ArrayList(); + List list = null; + StationAssignmentAnalyzeInfo info = new StationAssignmentAnalyzeInfo(); + int assimentcount = 0; + int receivedcount = 0; + int processedcount = 0; + int completedcount = 0; + ArrayList infolist = new ArrayList(); + do { + list = assignment.queryPage(dataSource, startstr, endstr, index, 1000); + if(list!=null){ + for(SQLDataObject ob:list){ + AssignmentEntity as = (AssignmentEntity)ob; + try { + boolean add = false; + String[] receivers = as.getReceiver().split("##"); + if (as.getStation() != null) { + if(checkeReceiver(receivers,station)) + add = true; + } else if (as.getDetachment() != null) { + if(checkeReceiver(receivers,s.getDetachment())) + add = true; + }else if (as.getBorough() != null) { + if(checkeReceiver(receivers,s.getBorough())) + add = true; + }else if (as.getBrigade() != null) { + if(checkeReceiver(receivers,s.getBrigade())) + add = true; + } + if(add) { + StationAssignmentAnalyzeInfo.StationAssignmentInfo in = info.allocinfo(); + AssignmentStatusEntity status = AssignmentStatusEntity.QueryAssignmentStatus(dataSource, as.getAssignmentid(), station, as.getId()); + in.setAssignment(as); + in.setStatus(status); + infolist.add(in); + assimentcount++; + if(status!=null){ + receivedcount++; + if(status.getState().equals("processed")) + processedcount++; + else if(status.getState().equals("completed")) { + completedcount++; + processedcount++; + } + } + } + }catch (Exception e){ + + } + } + } + index++; + }while(list!=null&&list.size()>=1000); + + info.setAssimentcount(assimentcount); + info.setReceivedcount(receivedcount); + info.setProcessedcount(processedcount); + info.setCompletedcount(completedcount); + info.setList(infolist); + return new RespEntity(RespCode.SUCCESS, info); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/assignment/getstatus", method = RequestMethod.POST) + public RespEntity getAssignmentStatus(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String assignmentid = JsonHelper.getStringValue(rootnode, "assignmentid"); + + if (assignmentid == null) + return new RespEntity(RespCode.NOTEXIST); + AssignmentEntity assignment = AssignmentEntity.QueryAssignment(dataSource,assignmentid); + if(assignment==null) + return new RespEntity(RespCode.NOTEXIST); + AssignmentStatusEntity status = new AssignmentStatusEntity(); + status.setId(assignment.getId()); + status.setAssignmentid(assignmentid); + status.extendName(""+assignment.getId()); + List list = status.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + @ResponseBody + @RequestMapping(value = "/firectrl/client/assignment/analyzeold", method = RequestMethod.POST) + public RespEntity getAssignmentAnalyzeInfoOld(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + AssignmentEntity assignment = (AssignmentEntity) SQLTools.getEntityFromJson(rootnode, AssignmentEntity.class); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = 100; + int pageindex = 0; + if (assignment == null) + assignment = new AssignmentEntity(); + List list = null; + int assignmentcount = 0; + int receivedcount = 0; + int processedcount = 0; + int completecount = 0; + int total = 0; + do { + list = assignment.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + if(list!=null) + assignmentcount += list.size(); + for(SQLDataObject ob:list){ + AssignmentEntity asi = (AssignmentEntity)ob; + AssignmentStatusEntity status = new AssignmentStatusEntity(); + status.setId(asi.getId()); + if(asi.getBrigade()!=null||asi.getBorough()!=null||asi.getDetachment()!=null||asi.getStation()!=null){ + FireStationBaseInfoEntity station = new FireStationBaseInfoEntity(); + station.setName(asi.getStation()); + station.setBrigade(asi.getBrigade()); + station.setBorough(asi.getBorough()); + station.setDetachment(asi.getDetachment()); + total += station.queryCount(dataSource,null,null); + } + status.extendName(""+asi.getId()); + List statuslist = status.queryList(dataSource,null,null); + if(statuslist==null) + continue; + for(SQLDataObject asob:statuslist){ + AssignmentStatusEntity ass = (AssignmentStatusEntity)asob; + String state = ass.getState(); + if(state==null) + continue; + if(state.equals("received" )){ + receivedcount++; + }else if(state.equals("processed")){ + processedcount++; + }else if(state.equals("completed")){ + completecount++; + } + } + } + pageindex++; + }while(list!=null&&list.size()==100); + + AssignmentAnalyzeInfo info = new AssignmentAnalyzeInfo(); + info.assignmentcount = assignmentcount; + info.receivedcount = receivedcount; + info.processedcount = processedcount; + info.completecount = completecount; + info.total = total; + return new RespEntity(RespCode.SUCCESS, info); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + private int AssignmentInfoScope(AssignmentEntity as,OrganiztionUri uri){ + int total = 0; + if (as.getSendtype() != null && as.getSendtype().equals("toclient")) { + String[] receivers = as.getReceiver().split("##"); + for(int i=0;i list = qury.queryList(dataSource, startstr, endstr); + if(uri==null) { + uri = new OrganiztionUri(); + } + int assignmentcount = 0; + int receivedcount = 0; + int processedcount = 0; + int completecount = 0; + int total = 0; + + { + if(list!=null){ + for(SQLDataObject ob:list){ + try { + AssignmentEntity as = (AssignmentEntity) ob; + + if (as != null) { + int bereceicecount = AssignmentInfoScope(as,uri); + if(bereceicecount>0) + assignmentcount++; + total += bereceicecount; + + AssignmentStatusEntity status = new AssignmentStatusEntity(); + status.setId(as.getId()); + status.extendName(""+as.getId()); + List statuslist = status.queryList(dataSource,null,null); + if(statuslist==null) + continue; + for(SQLDataObject asob:statuslist){ + AssignmentStatusEntity ass = (AssignmentStatusEntity)asob; + String state = ass.getState(); + if(state==null) + continue; + if(state.equals("received" )){ + receivedcount++; + }else if(state.equals("processed")){ + processedcount++; + }else if(state.equals("completed")){ + completecount++; + } + } + } + }catch (Exception e){ + + } + } + } + } + + AssignmentAnalyzeInfo info = new AssignmentAnalyzeInfo(); + info.assignmentcount = assignmentcount; + info.receivedcount = receivedcount; + info.processedcount = processedcount; + info.completecount = completecount; + info.total = total; + return new RespEntity(RespCode.SUCCESS, info); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/assignment/statechange",method = RequestMethod.POST) + public RespEntity changeAssignmentState(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String assignmentid = JsonHelper.getStringValue(rootnode,"assignmentid"); + String station = JsonHelper.getStringValue(rootnode,"station"); + if(assignmentid==null||assignmentid.length()<=0||station==null||station.length()<=0) + return new RespEntity(RespCode.NOTEXIST); + AssignmentEntity assignmentinfo = AssignmentEntity.QueryAssignment(dataSource,assignmentid); + if(assignmentinfo==null) + return new RespEntity(RespCode.NOTEXIST); + AssignmentEventEntity event = (AssignmentEventEntity) SQLTools.getEntityFromJson(rootnode, AssignmentEventEntity.class); + if(event==null) + return new RespEntity(RespCode.FAIL); + if(event.getTimestamp()==null) + event.setTimestamp(new Date()); + if(event.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/assignment/geteventcount",method = RequestMethod.POST) + public RespEntity getAssignmentEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + AssignmentEventEntity event = (AssignmentEventEntity) SQLTools.getEntityFromJson(rootnode, AssignmentEventEntity.class); + if(event==null) + event = new AssignmentEventEntity(); + int count = event.queryCount(dataSource,startstr,endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/assignment/geteventlist",method = RequestMethod.POST) + public RespEntity getAssignmentEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + AssignmentEventEntity event = (AssignmentEventEntity) SQLTools.getEntityFromJson(rootnode, AssignmentEventEntity.class); + + if (event == null) + event = new AssignmentEventEntity(); + List list = event.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/assignment/getprocessinfo",method = RequestMethod.POST) + public RespEntity getAssignmentProcessInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + AssignmentProcessInfoEntity info = (AssignmentProcessInfoEntity) SQLTools.getEntityFromJson(rootnode, AssignmentProcessInfoEntity.class); + + List list = info.queryList(dataSource,startstr,endstr); + return new RespEntity(RespCode.SUCCESS, list); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/sendmqtt", method = RequestMethod.POST) + public RespEntity sendMQTT(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String topic = JsonHelper.getStringValue(rootnode, "topic"); + String message = JsonHelper.getStringValue(rootnode, "message"); + + try { + messagePublisher.sendMessage(topic,message); + rel = new RespEntity(RespCode.SUCCESS); + } catch (Exception e) { + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/notice/sendudp", method = RequestMethod.POST) + public RespEntity sendUDPAgentCmd(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String topic = JsonHelper.getStringValue(rootnode, "topic"); + String message = JsonHelper.getStringValue(rootnode, "message"); + + UDPAgentMQTTMessage agentMQTTMessage = new UDPAgentMQTTMessage(); + agentMQTTMessage.setMessage(message); + agentMQTTMessage.setTopic(topic); + try { + ioTCtrlServer.translateHttp2InternetUdp(UDPAgentPackage.TYPE_MDEV_MQTT, JSON.toJSONString(agentMQTTMessage)); + } catch (Exception e) { + e.printStackTrace(); + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientRollcallController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientRollcallController.java new file mode 100644 index 0000000..f80fb8c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientRollcallController.java @@ -0,0 +1,552 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.model.DetachmentEntity; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallAckEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.*; +import com.jingyi.iotserver.firestationport.services.*; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.*; + +@RestController +@CrossOrigin +public class FireStationClientRollcallController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private DatabaseDesInfoService databaseDesInfoService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private UserAuthorManager userAuthorManager; + + @ResponseBody + @RequestMapping(value="/firectrl/client/startrollcall",method = RequestMethod.POST) + public RespEntity startRollCall(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + try { + FireStationRollCallEntity rollcall = (FireStationRollCallEntity) SQLTools.getEntityFromJson(rootnode,FireStationRollCallEntity.class); + if(rollcall.getStarttime()==null) + rollcall.setStarttime(new Date(System.currentTimeMillis())); + JsonNode scope = rootnode.get("scope"); + if(scope!=null) + rollcall.setScope(scope.toString()); + if(rollcall==null) + rel = new RespEntity(RespCode.NOTEXIST); + else + rel = stationServices.addRollCall(rollcall); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE,"ROLLCALL", + "发起点名", JsonHelper.convertObjectToStr(rollcall),rel.getCode()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcallcount",method = RequestMethod.POST) + public RespEntity queryRollCallCount(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + try { + if(rollcall==null) + rollcall = new FireStationRollCallEntity(); + int count = rollcall.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcalllist",method = RequestMethod.POST) + public RespEntity getRollCallList(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + if(rollcall==null) + rollcall = new FireStationRollCallEntity(); + try { + List list = rollcall.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcallstatistics",method = RequestMethod.POST) + public RespEntity getRollCallStatistics(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + if(rollcall==null) + rollcall = new FireStationRollCallEntity(); + + try { + List list = rollcall.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + List statistics = new ArrayList(); + for(SQLDataObject ob:list){ + FireStationRollCallEntity entity = (FireStationRollCallEntity)ob; + if(entity!=null){ + RollCallStatisticsInfo info = new RollCallStatisticsInfo(); + try { + List stationscope = SQLTools.getEntityListFromJson(entity.getScope(), FireStationBaseInfoEntity.class); + int count = stationServices.queryStationCountByScope(stationscope); + info.setRollcallnumber(entity.getNumber()); + info.setStationcount(count); + info.setStarttime(entity.getStarttime()); + + FireStationRollCallAckEntity rollcallack = new FireStationRollCallAckEntity(); + rollcallack.setRollcallnumber(entity.getNumber()); + rollcallack.setState("ack"); + + count = rollcallack.queryCount(dataSource,null,null); + info.setAckcount(count); + rollcallack.setState("ignore"); + count = rollcallack.queryCount(dataSource,null,null); + info.setIgnorecount(count); + statistics.add(info); + }catch (Exception e){ + + } + } + } + return new RespEntity(RespCode.SUCCESS,statistics); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcallackcount",method = RequestMethod.POST) + public RespEntity queryRollCallAckCount(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallAckEntity rollcallack = (FireStationRollCallAckEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallAckEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + try { + if(rollcallack==null) + rollcallack = new FireStationRollCallAckEntity(); + int count = rollcallack.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcallacklist",method = RequestMethod.POST) + public RespEntity getRollCallAckList(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallAckEntity rollcallack = (FireStationRollCallAckEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallAckEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + rollcallack.setState(null); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + + try { + if(rollcallack==null) + rollcallack = new FireStationRollCallAckEntity(); + List list = rollcallack.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcallnotacklist",method = RequestMethod.POST) + public RespEntity getRollCallNotAckList(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)SQLTools.getEntityFromJson(rootnode,FireStationRollCallEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + String brigade = JsonHelper.getStringValue(rootnode,"brigade"); + String borough = JsonHelper.getStringValue(rootnode,"borough"); + String detachment = JsonHelper.getStringValue(rootnode,"detachment"); + + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + if(pagesize<=0) + pagesize = 100; + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pageindex<0) + pageindex = 0; + ArrayList notacklist = new ArrayList(); + if(rollcall==null) + rollcall = new FireStationRollCallEntity(); + try { + + List list = rollcall.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + List statistics = new ArrayList(); + for(SQLDataObject ob:list){ + FireStationRollCallEntity entity = (FireStationRollCallEntity)ob; + if(entity!=null){ + RollCallStatisticsInfo info = new RollCallStatisticsInfo(); + try { + /* List stationscope = SQLTools.getEntityListFromJson(entity.getScope(), FireStationBaseInfoEntity.class); + int count = stationServices.queryStationCountByScope(stationscope); + info.setRollcallnumber(entity.getNumber()); + info.setStationcount(count); + info.setStarttime(entity.getStarttime()); +*/ + FireStationRollCallAckEntity rollcallack = new FireStationRollCallAckEntity(); + rollcallack.setRollcallnumber(entity.getNumber()); + rollcallack.setState("ignore"); + // count = stationServices.queryRollCallAckCount(rollcallack,null,null); + List notack = rollcallack.queryPage(dataSource,null,null,0,1000); + for(SQLDataObject oback:notack){ + FireStationRollCallAckEntity ack = (FireStationRollCallAckEntity)oback; + if(fireStationLiveManager.matchScope(ack.getStationname(),brigade,borough,detachment)) + notacklist.add(ack); + } + }catch (Exception e){ + + } + } + } + return new RespEntity(RespCode.SUCCESS,notacklist); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/patchrollcallack",method = RequestMethod.POST) + public RespEntity patckRollCallAck(HttpServletRequest request) { + RespEntity rel = null; + try{ + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + List notack = SQLTools.getEntityListFromJsonArray(rootnode,FireStationRollCallAckEntity.class); + for(FireStationRollCallAckEntity ack:notack){ + ack.setState("ack"); + ack.setAcktime(new Date()); + ack.Update(dataSource); + } + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_PATCH,"ROLLCALL", + "补点名",JsonHelper.convertObjectToStr(notack),0); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getrollcallreportform",method = RequestMethod.POST) + public RespEntity getRollcallReportform(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + String username = JsonHelper.getStringValue(rootnode,"username"); + JsonNode scopenode = JsonHelper.getLevel2(rootnode,"scope"); + + FireStationRollCallEntity rollentity = null; + if(username!=null){ + rollentity = new FireStationRollCallEntity(); + rollentity.setUsername(username); + } + int stationcount = 0; + if(rollentity==null) + rollentity = new FireStationRollCallEntity(); + try { + + List rollcalllist = rollentity.queryPage(dataSource,startstr,endstr,0,1024); + + if(scopenode!=null&&rollcalllist!=null){ + //remove rollcall out scope + List rmlist = new ArrayList(); + List list = SQLTools.getEntityListFromJsonArray(scopenode,FireStationBaseInfoEntity.class); + if(list!=null&&list.size()>0){ + for(SQLDataObject ob:rollcalllist){ + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)ob; + if(rollcall!=null){ + try { + boolean rm = true; + String scope = rollcall.getScope(); + JsonNode rollscopelist = JsonHelper.parseBodyLevel1(scope); + List rolllist = SQLTools.getEntityListFromJsonArray(rollscopelist, FireStationBaseInfoEntity.class); + for (FireStationBaseInfoEntity userscope : list) { + if (userscope != null) { + for(FireStationBaseInfoEntity roll:rolllist){ + if(roll!=null){ + if(userscope.checkScope(roll)){ + rm = false; + break; + } + } + } + } + } + + if(rm) + rmlist.add(rollcall); + }catch (Exception e){ + + } + } + } + for(FireStationRollCallEntity rollcall:rmlist){ + if(rollcall!=null) + rollcalllist.remove(rollcall); + } + } + } + + RollcallReportForm report = new RollcallReportForm(); + HashMap stationrollcallmap = new HashMap(); + if(rollcalllist==null||rollcalllist.size()<=0){ + report.setRollcall(0); + report.setAck(0); + report.setIgnore(0); + report.setExpect(0); + report.setRanking(null); + return new RespEntity(RespCode.SUCCESS,report); + } + report.setRollcall(rollcalllist.size()); + for(SQLDataObject ob:rollcalllist){ + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)ob; + String scopejson = rollcall.getScope(); + + try{ + JsonNode scopelist = JsonHelper.parseBodyLevel1(scopejson); + List list = SQLTools.getEntityListFromJsonArray(scopelist,FireStationBaseInfoEntity.class); + try { + int count = stationServices.queryStationCountByScope(list); + if(count>0) + stationcount+=count; + }catch (Exception e){ + + } + + FireStationRollCallAckEntity ackEntity = new FireStationRollCallAckEntity(); + int pageindex = 0; + int pagesize = 512; + ackEntity.setRollcallnumber(rollcall.getNumber()); + List acklist = null; + do { + acklist = ackEntity.queryPage(dataSource, null, null, pageindex, pagesize); + pageindex++; + if (acklist == null) + break; + for (SQLDataObject oback : acklist) { + FireStationRollCallAckEntity ack = (FireStationRollCallAckEntity)oback; + StationRollcallCounter counter = stationrollcallmap.get(ack.getStationname()); + if (counter == null) { + counter = new StationRollcallCounter(); + counter.setName(ack.getStationname()); + if (ack.getState().equals("ack")) { + counter.setAck(1); + counter.setIgnore(0); + } else { + counter.setAck(0); + counter.setIgnore(1); + } + stationrollcallmap.put(counter.getName(), counter); + } else { + if (ack.getState().equals("ack")) { + counter.setAck(counter.getAck() + 1); + } else { + counter.setIgnore(counter.getIgnore() + 1); + } + } + } + }while(acklist!=null&&acklist.size()>=pagesize); + }catch (Exception e){ + + } + } + + + ArrayList ranking = new ArrayList(); + + for(Map.Entry entry: stationrollcallmap.entrySet()) { + StationRollcallCounter info = entry.getValue(); + if(info!=null){ + report.setAck(report.getAck()+info.getAck()); + report.setIgnore(report.getIgnore()+info.getIgnore()); + ranking.add(info); + } + } + //Collections.sort(ranking, Collections.reverseOrder()); + Collections.sort(ranking); + report.setRanking(ranking); + report.setExpect(stationcount); + return new RespEntity(RespCode.SUCCESS,report); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getstationrollcallreportform",method = RequestMethod.POST) + public RespEntity getStationRollcallReportform(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + String stationname = JsonHelper.getStringValue(rootnode, "name"); + + if(startstr==null||endstr==null||stationname==null) + return new RespEntity(RespCode.ERROR_CMD); + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + if(station==null) + return new RespEntity(RespCode.NOTEXIST); + + int ackcount = 0; + int ignorecount = 0; + FireStationRollCallAckEntity ackEntity = new FireStationRollCallAckEntity(); + int pageindex = 0; + int pagesize = 1024; + ackEntity.setStationname(stationname); + List acklist = null; + acklist = ackEntity.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + + StationRollcallReportForm report = new StationRollcallReportForm(); + ArrayList list = new ArrayList(); + for(SQLDataObject ob : acklist){ + FireStationRollCallAckEntity ack = (FireStationRollCallAckEntity)ob; + if(ack==null) + continue; + StationRollcallAckInfo info = new StationRollcallAckInfo(); + info.setNumber(ack.getRollcallnumber()); + FireStationRollCallEntity rollcall = FireStationRollCallEntity.Query(dataSource,ack.getRollcallnumber()); + if(rollcall==null) + continue; + info.setStarttime(rollcall.getStarttime()); + info.setState(ack.getState()); + info.setAcktime(ack.getAcktime()); + + try { + if (ack.getState().equals("ack")) { + ackcount++; + } else { + ignorecount++; + } + }catch (Exception e){ + continue; + } + list.add(info); + } + report.setAck(ackcount); + report.setIgnore(ignorecount); + report.setList(list); + int rollcallcount = 0; + try{ + FireStationRollCallEntity rollcal = new FireStationRollCallEntity(); + List rollcalllist = rollcal.queryPage(dataSource,startstr,endstr,0,1024); + for(SQLDataObject ob:rollcalllist){ + FireStationRollCallEntity rollcall = (FireStationRollCallEntity)ob; + String scope = rollcall.getScope(); + try { + List scopelist = SQLTools.getEntityListFromJson(scope, DetachmentEntity.class); + for(DetachmentEntity detach:scopelist){ + String brigade = detach.getBrigade(); + String borough = detach.getBorough(); + String detachemnt = detach.getDetachment(); + if(brigade!=null&&!brigade.equals(station.getBrigade())) + continue; + if(borough!=null&&!borough.equals(station.getBorough())) + continue; + if(detachemnt!=null&&!detachemnt.equals(station.getDetachment())) + continue; + rollcallcount++; + break; + } + }catch (Exception e){ + + } + } + + }catch (Exception e){ + + } + report.setRollcall(rollcallcount); + rel = new RespEntity(RespCode.SUCCESS,report); + return rel; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientSensorController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientSensorController.java new file mode 100644 index 0000000..1149c8a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationClientSensorController.java @@ -0,0 +1,2872 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.analyze.AlarmDayCount; +import com.jingyi.iotserver.firestationport.model.complexquery.ACBParameterCalculate; +import com.jingyi.iotserver.firestationport.model.complexquery.SensorAlarmCount; +import com.jingyi.iotserver.firestationport.model.complexquery.SensorAlarmCountElement; +import com.jingyi.iotserver.firestationport.model.multiPlatform.MultiAlarmEvent; +import com.jingyi.iotserver.firestationport.model.partner.CityTruckOrderEntity; +import com.jingyi.iotserver.firestationport.model.publicsafe.PublicAlarmEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCInvadeEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.ProcessAlarmEventOpRecord; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmSummaryEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.sensor.*; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.model.station.StationStaffAISignInfo; +import com.jingyi.iotserver.firestationport.services.DatabaseDesInfoService; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.PushButtonEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.SensorEventUpdateNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.apache.http.util.TextUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class FireStationClientSensorController { + + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private DatabaseDesInfoService databaseDesInfoService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private SensorService sensorService; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + + private RespEntity executeOperateOnSensor(HttpServletRequest request,ISensorOperate op) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorDeviceEntity sensor = (SensorDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + if(sensor==null||sensor.getDeviceid()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + return op.ExecuteOperate(sensor,rootnode); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + private RespEntity executeOperateOnSensorSubdev(HttpServletRequest request,ISensorSubdevOperate op) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorSubDeviceEntity sensor = (SensorSubDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorSubDeviceEntity.class); + if(sensor==null||sensor.getDeviceid()==null||sensor.getPosition()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + return op.ExecuteOperate(sensor,rootnode); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getsensortypes",method = RequestMethod.POST) + public RespEntity getSensorTypeList(HttpServletRequest request) { + /* ArrayList list = new ArrayList(); + SensorTypeResult type = new SensorTypeResult(); + type.setType("smoking"); + list.add(type); + type = new SensorTypeResult(); + type.setType("earthinductor"); + list.add(type); +*/ + ArrayList list = new ArrayList(); + list.add("smoking"); + list.add("earthinductor"); + return new RespEntity(RespCode.SUCCESS,list); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/addsensor",method = RequestMethod.POST) + public RespEntity addSensor(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,sensor.getOwner()); + if(station!=null){ + sensor.setDetachment(station.getDetachment()); + sensor.setBorough(station.getBorough()); + sensor.setBrigade(station.getBrigade()); + } + RespEntity rel = sensorService.addSensor(sensor); + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"SENSOR", + "添加传感器", JsonHelper.convertObjectToStr(sensor),rel.getCode()); + return rel; + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/deletesensor",method = RequestMethod.POST) + public RespEntity deleteSensor(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + SensorDeviceEntity s = SensorDeviceEntity.Query(dataSource,sensor.getDeviceid()); + if(s==null) + return new RespEntity(RespCode.NOTEXIST); + if(s.getDevicetype().equals("smoking")) + sensorService.stopSmokingBuzEvent(s.getDeviceid()); + RespEntity rel = sensorService.deleteSensor(sensor.getDeviceid()); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"SENSOR", + "删除传感器",JsonHelper.convertObjectToStr(sensor),rel.getCode()); + return rel; + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/updatesensor",method = RequestMethod.POST) + public RespEntity updateSensor(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + RespEntity rel = sensorService.updateSensor(sensor); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"SENSOR", + "更新传感器信息",JsonHelper.convertObjectToStr(sensor),rel.getCode()); + return rel; + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/setsensor",method = RequestMethod.POST) + public RespEntity setSensor(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + String usage = sensor.getEnableuse(); + if(usage==null||(!usage.equals("close")&&!usage.equals("use"))) + return new RespEntity(RespCode.ERROR_REQUEST); + + RespEntity rel = sensorService.updateSensor(sensor); + if(usage.equals("close")) + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_RUN,"SENSOR", + "启用传感器",JsonHelper.convertObjectToStr(sensor),rel.getCode()); + else + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_STOP,"SENSOR", + "停用传感器",JsonHelper.convertObjectToStr(sensor),rel.getCode()); + return rel; + } + }); + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/opensensoralarm",method = RequestMethod.POST) + public RespEntity setSensorAlarmOpen(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + SensorDeviceEntity setsensor = new SensorDeviceEntity(); + setsensor.setDeviceid(sensor.getDeviceid()); + setsensor.setAlarm("open"); + return sensorService.updateSensor(setsensor); + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/closesensoralarm",method = RequestMethod.POST) + public RespEntity setSensorAlarmClose(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + SensorDeviceEntity setsensor = new SensorDeviceEntity(); + setsensor.setDeviceid(sensor.getDeviceid()); + setsensor.setAlarm("close"); + return sensorService.updateSensor(setsensor); + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/stopsmokingbuzevent",method = RequestMethod.POST) + public RespEntity stopSmokingBuzEvent(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + + return sensorService.stopSmokingBuzEvent(sensor.getDeviceid()); + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getsensor",method = RequestMethod.POST) + public RespEntity getSensor(HttpServletRequest request) { + return executeOperateOnSensor(request,new ISensorOperate(){ + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param){ + SensorDeviceEntity s = SensorDeviceEntity.Query(dataSource,sensor.getDeviceid()); + if(s==null) + return new RespEntity(RespCode.NOTEXIST); + else + return new RespEntity(RespCode.SUCCESS,s); + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/getownersensor",method = RequestMethod.POST) + public RespEntity getOwnerSensor(HttpServletRequest request) { + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + String owner = JsonHelper.getStringValue(rootnode,"owner"); + List list = SensorDeviceEntity.QueryByOwner(dataSource,owner); + if(list==null||list.size()<=0) + return new RespEntity(RespCode.NOTEXIST); + else + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/querysensorcount",method = RequestMethod.POST) + public RespEntity getSensorCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorDeviceEntity sensor = (SensorDeviceEntity) SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + int count = sensorService.querySensorCount(sensor); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/querysensorpage",method = RequestMethod.POST) + public RespEntity getSensorPage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + SensorDeviceEntity sensor = (SensorDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + List list = sensorService.querySensorPage(pagesize,pageindex,sensor); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getacbstatuscount",method = RequestMethod.POST) + public RespEntity getACBStatusCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + + ACBEventEntity event = (ACBEventEntity) SQLTools.getEntityFromJson(rootnode, ACBEventEntity.class); + if(event==null) + event = new ACBEventEntity(); + + event.setType("status"); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getacbstatuslist",method = RequestMethod.POST) + public RespEntity getACBStatusList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + ACBEventEntity event = (ACBEventEntity) SQLTools.getEntityFromJson(rootnode, ACBEventEntity.class); + if(event==null) + event = new ACBEventEntity(); + + event.setType("status"); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getacbalarmcount",method = RequestMethod.POST) + public RespEntity getACBAlarmCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + ACBEventEntity event = (ACBEventEntity) SQLTools.getEntityFromJson(rootnode, ACBEventEntity.class); + if(event==null) + event = new ACBEventEntity(); + + event.setType("alarm"); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getacbalarmlist",method = RequestMethod.POST) + public RespEntity getACBAlarmList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + ACBEventEntity event = (ACBEventEntity) SQLTools.getEntityFromJson(rootnode, ACBEventEntity.class); + if(event==null) + event = new ACBEventEntity(); + event.setType("alarm"); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getacbstatusinfocount",method = RequestMethod.POST) + public RespEntity getACBStatusInfoCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + ACBStatusEntity event = (ACBStatusEntity) SQLTools.getEntityFromJson(rootnode, ACBStatusEntity.class); + if(event==null) + event = new ACBStatusEntity(); + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getacbinfostatuslist",method = RequestMethod.POST) + public RespEntity getACBStatusInfoList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + ACBStatusEntity event = (ACBStatusEntity) SQLTools.getEntityFromJson(rootnode, ACBStatusEntity.class); + if(event==null) + event = new ACBStatusEntity(); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/calacbparameter",method = RequestMethod.POST) + public RespEntity calACBDeviceParameter(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + String deviceid = JsonHelper.getStringValue(rootnode, "deviceid"); + + if(deviceid==null||SensorDeviceEntity.Query(dataSource,deviceid)==null) + return new RespEntity(RespCode.NOTEXIST); + + ACBParameterCalculate param = sensorService.calACBParameter(deviceid,startstr,endstr); + return new RespEntity(RespCode.SUCCESS,param); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/liquidgage/getstatuscount",method = RequestMethod.POST) + public RespEntity getLiquidGageStatusCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + LiquidGageEventEntity event = (LiquidGageEventEntity) SQLTools.getEntityFromJson(rootnode, LiquidGageEventEntity.class); + if(event==null) + event = new LiquidGageEventEntity(); + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/liquidgage/getstatuslist",method = RequestMethod.POST) + public RespEntity getLiquidGageStatusList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + LiquidGageEventEntity event = (LiquidGageEventEntity) SQLTools.getEntityFromJson(rootnode, LiquidGageEventEntity.class); + if(event==null) + event = new LiquidGageEventEntity(); + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/pipepressure/getstatuscount",method = RequestMethod.POST) + public RespEntity getPipePressureStatusCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + PipePressureEventEntity event = (PipePressureEventEntity) SQLTools.getEntityFromJson(rootnode, PipePressureEventEntity.class); + if(event==null) + event = new PipePressureEventEntity(); + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/pipepressure/getstatuslist",method = RequestMethod.POST) + public RespEntity getPipePressureStatusList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + PipePressureEventEntity event = (PipePressureEventEntity) SQLTools.getEntityFromJson(rootnode, PipePressureEventEntity.class); + if(event==null) + event = new PipePressureEventEntity(); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/gassensor/getstatuscount",method = RequestMethod.POST) + public RespEntity getGasSensorStatusCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + GasSensorEventEntity event = (GasSensorEventEntity) SQLTools.getEntityFromJson(rootnode, GasSensorEventEntity.class); + if(event==null) + event = new GasSensorEventEntity(); + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/gassensor/getstatuslist",method = RequestMethod.POST) + public RespEntity getGasSensorStatusList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + GasSensorEventEntity event = (GasSensorEventEntity) SQLTools.getEntityFromJson(rootnode, GasSensorEventEntity.class); + if(event==null) + event = new GasSensorEventEntity(); + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/gassensor/getlaststatus",method = RequestMethod.POST) + public RespEntity getGasSensorLastStatus(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + + GasSensorEventEntity event = (GasSensorEventEntity) SQLTools.getEntityFromJson(rootnode, GasSensorEventEntity.class); + if(event==null) + event = new GasSensorEventEntity(); + + SQLDataObject ob = event.QueryLast(dataSource); + return new RespEntity(RespCode.SUCCESS,ob); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/liquidgage/setalarmrange") + public RespEntity setLiquidGaeAlarmRange(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + LiquidGageAlarmSettingEntity set = (LiquidGageAlarmSettingEntity)SQLTools.getEntityFromJson(rootnode, LiquidGageAlarmSettingEntity.class); + if(set==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(set.getLowpower()<0) + set.setLowout(10); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,set.getDeviceid()); + if(sensor==null) + return new RespEntity(RespCode.NOTEXIST); + set.setDevicetype(sensor.getDevicetype()); + if(set.SetOut(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/pipepressure/setalarmrange") + public RespEntity setPipePressureAlarmRange(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + LiquidGageAlarmSettingEntity set = (LiquidGageAlarmSettingEntity)SQLTools.getEntityFromJson(rootnode, LiquidGageAlarmSettingEntity.class); + if(set==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(set.getLowpower()<0) + set.setLowout(10); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,set.getDeviceid()); + if(sensor==null) + return new RespEntity(RespCode.NOTEXIST); + set.setDevicetype(sensor.getDevicetype()); + if(set.SetOut(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alerterhost/getalarmcount",method = RequestMethod.POST) + public RespEntity getAlerterHostAlarmCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + AlerterHostEventEntity event = (AlerterHostEventEntity)SQLTools.getEntityFromJson(rootnode, AlerterHostEventEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + if(event==null) + event = new AlerterHostEventEntity(); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alerterhost/getalarmlist",method = RequestMethod.POST) + public RespEntity getAlerterHostAlarmList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + AlerterHostEventEntity event = (AlerterHostEventEntity)SQLTools.getEntityFromJson(rootnode, AlerterHostEventEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + if(event==null) + event = new AlerterHostEventEntity(); + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/smoking/getbzeventcount",method = RequestMethod.POST) + public RespEntity getSmokingBzEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + SmokingBuzEventEntity event = (SmokingBuzEventEntity)SQLTools.getEntityFromJson(rootnode, SmokingBuzEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/smoking/getbzeventlist",method = RequestMethod.POST) + public RespEntity getSmokingBzEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + SmokingBuzEventEntity event = (SmokingBuzEventEntity)SQLTools.getEntityFromJson(rootnode, SmokingBuzEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/earthinductor/getbzeventcount",method = RequestMethod.POST) + public RespEntity getEarthinductorBzEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + EarthInductorBuzEventEntity event = (EarthInductorBuzEventEntity)SQLTools.getEntityFromJson(rootnode, EarthInductorBuzEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/earthinductor/getbzeventlist",method = RequestMethod.POST) + public RespEntity geEarthinductorBzEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + EarthInductorBuzEventEntity event = (EarthInductorBuzEventEntity)SQLTools.getEntityFromJson(rootnode, EarthInductorBuzEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aicamera/geteventcount",method = RequestMethod.POST) + public RespEntity getAICameraEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + AICameraEventEntity event = (AICameraEventEntity)SQLTools.getEntityFromJson(rootnode, AICameraEventEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + if(event==null) { + event = new AICameraEventEntity(); + } + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aicamera/geteventlist",method = RequestMethod.POST) + public RespEntity getAICameraEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + AICameraEventEntity event = (AICameraEventEntity)SQLTools.getEntityFromJson(rootnode, AICameraEventEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + if(event==null) { + event = new AICameraEventEntity(); + } + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarmhost/geteventcount",method = RequestMethod.POST) + public RespEntity getAlarmHostEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + STVAlarmEventEntity event = (STVAlarmEventEntity)SQLTools.getEntityFromJson(rootnode, STVAlarmEventEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + if(event==null) { + event = new STVAlarmEventEntity(); + } + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarmhost/geteventlist",method = RequestMethod.POST) + public RespEntity getAlarmHostEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + STVAlarmEventEntity event = (STVAlarmEventEntity)SQLTools.getEntityFromJson(rootnode, STVAlarmEventEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + if(event==null) { + event = new STVAlarmEventEntity(); + } + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm/multi-querycount",method = RequestMethod.POST) + public RespEntity getSensorAlarmCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + OrganiztionUri uri = (OrganiztionUri) SQLTools.getEntityFromJson(rootnode, OrganiztionUri.class); + if(uri==null) + return new RespEntity(RespCode.FAIL); + JsonNode timesnode = JsonHelper.getLevel2(rootnode,"times"); + if(timesnode==null||!timesnode.isArray()||timesnode.size()<=0) + return new RespEntity(RespCode.FAIL); + SensorDeviceEntity sensor = new SensorDeviceEntity(); + sensor.setOwner(uri.getStation()); + sensor.setBrigade(uri.getBrigade()); + sensor.setBorough(uri.getBorough()); + sensor.setDetachment(uri.getDetachment()); + ArrayList infolist = new ArrayList(); + List sensorlist = sensor.queryList(dataSource,null,null); + if(sensorlist==null) + return new RespEntity(RespCode.SUCCESS,infolist); + + for(int i=0;i countlist = new ArrayList (); + SensorAlarmCountElement element = new SensorAlarmCountElement(); + element.setCount(somking); + element.setType("somking"); + countlist.add(element); + + element = new SensorAlarmCountElement(); + element.setCount(earthinductor); + element.setType("earthinductor"); + countlist.add(element); + + element = new SensorAlarmCountElement(); + element.setCount(waterpressure); + element.setType("waterpressure"); + countlist.add(element); + + element = new SensorAlarmCountElement(); + element.setCount(ACB); + element.setType("ACB"); + countlist.add(element); + + element = new SensorAlarmCountElement(); + element.setCount(gas); + element.setType("gas"); + countlist.add(element); + + element = new SensorAlarmCountElement(); + element.setCount(waterpos); + element.setType("waterpos"); + countlist.add(element); + + element = new SensorAlarmCountElement(); + element.setCount(AI); + element.setType("AI"); + countlist.add(element); + + SensorAlarmCount reulst = new SensorAlarmCount(); + reulst.setIndex(index); + reulst.setCountlist(countlist); + infolist.add(reulst); + } + return new RespEntity(RespCode.SUCCESS,infolist); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/addsubdev",method = RequestMethod.POST) + public RespEntity addSensorSubdev(HttpServletRequest request) { + return executeOperateOnSensorSubdev(request,new ISensorSubdevOperate(){ + public RespEntity ExecuteOperate(SensorSubDeviceEntity ss, Object param){ + SensorDeviceEntity s = SensorDeviceEntity.Query(dataSource,ss.getDeviceid()); + if(s==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(ss.getPosition()==null||ss.getPosition().length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(ss.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + ss.Insert(dataSource); + RespEntity rel = new RespEntity(RespCode.SUCCESS); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_CREATE,"SENSORSUB", + "添加传感器子设备", JsonHelper.convertObjectToStr(ss),rel.getCode()); + return rel; + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/delsubdev",method = RequestMethod.POST) + public RespEntity deleteSensorSubdev(HttpServletRequest request) { + return executeOperateOnSensorSubdev(request,new ISensorSubdevOperate(){ + public RespEntity ExecuteOperate(SensorSubDeviceEntity ss, Object param){ + if(ss.QueryIt(dataSource)!=null){ + ss.Delete(dataSource); + }else + return new RespEntity(RespCode.NOTEXIST); + + RespEntity rel = new RespEntity(RespCode.SUCCESS); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"SENSORSUB", + "删除传感器子设备",JsonHelper.convertObjectToStr(ss),rel.getCode()); + return rel; + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/updatesubdev",method = RequestMethod.POST) + public RespEntity updateSensorSubdev(HttpServletRequest request) { + return executeOperateOnSensorSubdev(request,new ISensorSubdevOperate(){ + public RespEntity ExecuteOperate(SensorSubDeviceEntity ss, Object param){ + RespEntity rel ; + if(ss.Update(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"SENSORSUB", + "更新传感器信息子设备",JsonHelper.convertObjectToStr(ss),rel.getCode()); + return rel; + } + }); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/getsubdevlist",method = RequestMethod.POST) + public RespEntity getSensorSubdevList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorSubDeviceEntity ss = (SensorSubDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorSubDeviceEntity.class); + if(ss==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + List list = ss.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS,list); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/querysensorstatecount",method = RequestMethod.POST) + public RespEntity getSensorStateCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorLinkStateEntity state = (SensorLinkStateEntity) SQLTools.getEntityFromJson(rootnode,SensorLinkStateEntity.class); + int count = state.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/querysensostaterpage",method = RequestMethod.POST) + public RespEntity getSensorStatePage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + SensorLinkStateEntity state = (SensorLinkStateEntity)SQLTools.getEntityFromJson(rootnode,SensorLinkStateEntity.class); + List list = state.queryPage(dataSource,null,null,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/gassensor/deleteevent",method = RequestMethod.POST) + public RespEntity delGasSensorEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + GasSensorEventEntity event = (GasSensorEventEntity) SQLTools.getEntityFromJson(rootnode, GasSensorEventEntity.class); + if(event==null) + event = new GasSensorEventEntity(); + + + boolean bl = event.deleteRecords(dataSource,startstr,endstr); + + if(bl) + rel = new RespEntity(RespCode.SUCCESS); + else + rel =new RespEntity(RespCode.FAIL); + + userAuthorManager.AddUserOperate(request,UserAuthorManager.USER_OPERATE_TYPE_DELETE,"SENSOREVENT", + "删除气体传感器记录",rootnode.asText(),rel.getCode()); + + return rel; + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/invade/getcount",method = RequestMethod.POST) + public RespEntity getAIIPCInvadeCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + AIIPCInvadeEventEntity event = (AIIPCInvadeEventEntity) SQLTools.getEntityFromJson(rootnode, AIIPCInvadeEventEntity.class); + if(event==null) + event = new AIIPCInvadeEventEntity(); + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/aiipc/invade/getlist",method = RequestMethod.POST) + public RespEntity getAIIPCInvadeList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + AIIPCInvadeEventEntity event = (AIIPCInvadeEventEntity) SQLTools.getEntityFromJson(rootnode, AIIPCInvadeEventEntity.class); + if(event==null) + event = new AIIPCInvadeEventEntity(); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watermeter/geteventcount",method = RequestMethod.POST) + public RespEntity getWaterMeterEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + WaterMeterEventEntity event = (WaterMeterEventEntity)SQLTools.getEntityFromJson(rootnode, WaterMeterEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watermeter/geteventlist",method = RequestMethod.POST) + public RespEntity getWaterMeterEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + WaterMeterEventEntity event = (WaterMeterEventEntity)SQLTools.getEntityFromJson(rootnode, WaterMeterEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watermeter/getmonthcount",method = RequestMethod.POST) + public RespEntity getWaterMeterMonthCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + WaterMeterMonthCountEntity event = (WaterMeterMonthCountEntity)SQLTools.getEntityFromJson(rootnode, WaterMeterMonthCountEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + List list= event.queryCounts(dataSource); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watermeter/getdaycount",method = RequestMethod.POST) + public RespEntity getWaterMeterDayCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + WaterMeterMonthCountEntity event = (WaterMeterMonthCountEntity)SQLTools.getEntityFromJson(rootnode, WaterMeterMonthCountEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + List list= event.queryCounts(dataSource); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watermeter/gethourcount",method = RequestMethod.POST) + public RespEntity getWaterMeterHourCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + WateMeterHourCountEntity event = (WateMeterHourCountEntity)SQLTools.getEntityFromJson(rootnode, WateMeterHourCountEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + List list= event.queryCounts(dataSource); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/pushbutton/read",method = RequestMethod.POST) + public RespEntity setPushButtonEventRead(HttpServletRequest request) { + try{ + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + PushButtonEventEntity event = (PushButtonEventEntity)SQLTools.getEntityFromJson(rootnode, PushButtonEventEntity.class); + String operator = event.getOperator(); + event = (PushButtonEventEntity)event.QueryIt(dataSource); + + if(event!=null) + { + event.setReadstate("isread"); + if(!TextUtils.isEmpty(operator)){ + event.setOperator(operator); + } + event.setReadtime(new Date()); + PushButtonEventNotify notify = new PushButtonEventNotify(); + notify.setStation(event.getOwner()); + notify.setDeviceid(event.getDeviceid()); + notify.setTimestamp(event.getTimestamp()); + notify.setAlarmstate(event.getAlarmstate()); + notify.setDevicetype(event.getDevicetype()); + notify.setReadstate(event.getReadstate()); + notify.setReadtime(event.getReadtime()); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, notify.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(event.getDeviceid()); + pro.setDevice_type(event.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + if(event.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + } + + }catch (Exception e) + { + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/pushbutton/geteventcount",method = RequestMethod.POST) + public RespEntity getPushButtonEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + PushButtonEventEntity event = (PushButtonEventEntity)SQLTools.getEntityFromJson(rootnode, PushButtonEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/pushbutton/geteventlist",method = RequestMethod.POST) + public RespEntity getPushButtonEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + PushButtonEventEntity event = (PushButtonEventEntity)SQLTools.getEntityFromJson(rootnode, PushButtonEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/truckmuck/read",method = RequestMethod.POST) + public RespEntity readTruckMuckEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + MuckTruckEventEntity event = (MuckTruckEventEntity)SQLTools.getEntityFromJson(rootnode, MuckTruckEventEntity.class); + // System.out.println(rootnode.toString()); + if(event==null||event.getTimestamp()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(event.QueryIt(dataSource)!=null) + { + event.setStatus("read"); + if(event.Update(dataSource)) + { + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/truckmuck/geteventcount",method = RequestMethod.POST) + public RespEntity getTruckMuckEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + MuckTruckEventEntity event = (MuckTruckEventEntity)SQLTools.getEntityFromJson(rootnode, MuckTruckEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/truckmuck/geteventlist",method = RequestMethod.POST) + public RespEntity getTruckMuckEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + MuckTruckEventEntity event = (MuckTruckEventEntity)SQLTools.getEntityFromJson(rootnode, MuckTruckEventEntity.class); + + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/task/update",method = RequestMethod.POST) + public RespEntity getUpdateCityMgrTask(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + CityMgrEventEntity event = (CityMgrEventEntity) SQLTools.getEntityFromJson(rootnode, CityMgrEventEntity.class); + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(event.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/gettaskcount",method = RequestMethod.POST) + public RespEntity getCityMgrTaskCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + CityMgrEventEntity event = (CityMgrEventEntity) SQLTools.getEntityFromJson(rootnode, CityMgrEventEntity.class); + if(event==null) + event = new CityMgrEventEntity(); + + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/gettasklist",method = RequestMethod.POST) + public RespEntity getCityMgrTaskList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + CityMgrEventEntity event = (CityMgrEventEntity) SQLTools.getEntityFromJson(rootnode, CityMgrEventEntity.class); + if(event==null) + event = new CityMgrEventEntity(); + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + //城管通用接口 + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/common/update",method = RequestMethod.POST) + public RespEntity getUpdateCityMgrCommon(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + CityMgrCommonEntity event = (CityMgrCommonEntity) SQLTools.getEntityFromJson(rootnode, CityMgrCommonEntity.class); + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(event.QueryIt(dataSource)!=null) + { + //event.setStatus("read"); + if(event.Update(dataSource)) + { + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/common/getcount",method = RequestMethod.POST) + public RespEntity getCityMgrCommonCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + CityMgrCommonEntity event = (CityMgrCommonEntity) SQLTools.getEntityFromJson(rootnode, CityMgrCommonEntity.class); + if(event==null) + event = new CityMgrCommonEntity(); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/common/getlist",method = RequestMethod.POST) + public RespEntity getCityMgrCommonList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + CityMgrCommonEntity event = (CityMgrCommonEntity) SQLTools.getEntityFromJson(rootnode, CityMgrCommonEntity.class); + if(event==null) + event = new CityMgrCommonEntity(); + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + //城管车辆聚集接口 + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/gatheringtask/update",method = RequestMethod.POST) + public RespEntity updateCityMgrGatheringTask(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + CityTruckOrderEntity event = (CityTruckOrderEntity) SQLTools.getEntityFromJson(rootnode, CityTruckOrderEntity.class); + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if(event.QueryIt(dataSource)!=null) + { + //event.setStatus("read"); + if(event.Update(dataSource)) + { + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/gatheringtask/getcount",method = RequestMethod.POST) + public RespEntity getCityMgrGatheringTaskCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + CityTruckOrderEntity event = (CityTruckOrderEntity) SQLTools.getEntityFromJson(rootnode, CityTruckOrderEntity.class); + if(event==null) + event = new CityTruckOrderEntity(); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/gatheringtask/getlist",method = RequestMethod.POST) + public RespEntity getCityMgrGatheringTaskList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + CityTruckOrderEntity event = (CityTruckOrderEntity) SQLTools.getEntityFromJson(rootnode, CityTruckOrderEntity.class); + if(event==null) + event = new CityTruckOrderEntity(); + + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/citymgr/entrance/staff_sign/getcount",method = RequestMethod.POST) + public RespEntity getStaffSignCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + StationStaffAISignInfo event = (StationStaffAISignInfo) SQLTools.getEntityFromJson(rootnode, StationStaffAISignInfo.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/entrance/staff_sign_list",method = RequestMethod.POST) + public RespEntity getStaffSignList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + StationStaffAISignInfo event = (StationStaffAISignInfo) SQLTools.getEntityFromJson(rootnode, StationStaffAISignInfo.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + /* + *** 统一告警事件模型 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/getcount",method = RequestMethod.POST) + public RespEntity getSensorAlarmEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + SensorAlarmEventEntity event = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/getlist",method = RequestMethod.POST) + public RespEntity getSensorAlarmEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + SensorAlarmEventEntity event = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + if(list != null){ + for(int iAlarm = 0; iAlarm < list.size(); iAlarm++){ + SensorAlarmEventEntity sensorAlarm = (SensorAlarmEventEntity)list.get(iAlarm); + String sensorType = sensorAlarm.getDevicetype(); + if(TextUtils.isEmpty(sensorType)){ + continue; + } + switch (sensorType){ + case PushAlarmPointEntity.Device_TYPE_PBA: + case PushAlarmPointEntity.Device_TYPE_DeShangAn:{ + PushAlarmPointEntity deShangAnDev = new PushAlarmPointEntity(); + deShangAnDev.setPointId(sensorAlarm.getDeviceId()); + deShangAnDev = (PushAlarmPointEntity)deShangAnDev.QueryIt(dataSource); + if(deShangAnDev == null){ + continue; + } + sensorAlarm.setUser1Name(deShangAnDev.getUserName()); + sensorAlarm.setUser2Name(deShangAnDev.getUser2Name()); + sensorAlarm.setUser3Name(deShangAnDev.getUser3Name()); + sensorAlarm.setUser1Phone(deShangAnDev.getUserPhone()); + sensorAlarm.setUser2Phone(deShangAnDev.getUser2Phone()); + sensorAlarm.setUser3Phone(deShangAnDev.getUser3Phone()); + + }break; + } + } + } + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/getlist_diff",method = RequestMethod.POST) + public RespEntity getSensorAlarmEventDiffList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + SensorAlarmEventEntity event = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + event.addDiffCond("state"); + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + if(list != null){ + for(int iAlarm = 0; iAlarm < list.size(); iAlarm++){ + SensorAlarmEventEntity sensorAlarm = (SensorAlarmEventEntity)list.get(iAlarm); + String sensorType = sensorAlarm.getDevicetype(); + if(TextUtils.isEmpty(sensorType)){ + continue; + } + switch (sensorType){ + case PushAlarmPointEntity.Device_TYPE_PBA: + case PushAlarmPointEntity.Device_TYPE_DeShangAn:{ + PushAlarmPointEntity deShangAnDev = new PushAlarmPointEntity(); + deShangAnDev.setPointId(sensorAlarm.getDeviceId()); + deShangAnDev = (PushAlarmPointEntity)deShangAnDev.QueryIt(dataSource); + if(deShangAnDev == null){ + continue; + } + sensorAlarm.setUser1Name(deShangAnDev.getUserName()); + sensorAlarm.setUser2Name(deShangAnDev.getUser2Name()); + sensorAlarm.setUser3Name(deShangAnDev.getUser3Name()); + sensorAlarm.setUser1Phone(deShangAnDev.getUserPhone()); + sensorAlarm.setUser2Phone(deShangAnDev.getUser2Phone()); + sensorAlarm.setUser3Phone(deShangAnDev.getUser3Phone()); + + }break; + } + } + } + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/getlist_today",method = RequestMethod.POST) + public RespEntity getSensorAlarmEventTodayList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + int pagesize = 1000; + int pageindex = 0; + String strStartDay = SQLTools.formatDay(new Date()); + + String startstr = strStartDay + " 00:00:00"; + String endstr = strStartDay + " 23:59:59"; + + SensorAlarmEventEntity event = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + if(list != null){ + for(int iAlarm = 0; iAlarm < list.size(); iAlarm++){ + SensorAlarmEventEntity sensorAlarm = (SensorAlarmEventEntity)list.get(iAlarm); + String sensorType = sensorAlarm.getDevicetype(); + if(TextUtils.isEmpty(sensorType)){ + continue; + } + PushAlarmPointEntity deShangAnDev = new PushAlarmPointEntity(); + deShangAnDev.setPointId(sensorAlarm.getDeviceId()); + deShangAnDev = (PushAlarmPointEntity)deShangAnDev.QueryIt(dataSource); + if(deShangAnDev != null){ + sensorAlarm.setUser1Name(deShangAnDev.getUserName()); + sensorAlarm.setUser2Name(deShangAnDev.getUser2Name()); + sensorAlarm.setUser3Name(deShangAnDev.getUser3Name()); + sensorAlarm.setUser1Phone(deShangAnDev.getUserPhone()); + sensorAlarm.setUser2Phone(deShangAnDev.getUser2Phone()); + sensorAlarm.setUser3Phone(deShangAnDev.getUser3Phone()); + } + + } + } + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value="/multialarm/client/sensor/alarm_event/dayline",method = RequestMethod.POST) + public RespEntity getAlarmCountSevenDay(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SensorAlarmEventEntity alarmEvent = (SensorAlarmEventEntity)SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + + if(alarmEvent==null) + alarmEvent = new SensorAlarmEventEntity(); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String isBefore = JsonHelper.getStringValue(rootnode,"before"); + System.out.println("getAlarmCountSevenDay: " + startstr); + + Date startDate = SQLTools.StrToDateTime(startstr); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(startDate); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH)+1; + int day = calendar.get(Calendar.DATE); + String strMon = String.format("%02d", month); + String tsBeginTime = ""; + tsBeginTime += year; + tsBeginTime += "-"; + tsBeginTime += strMon; + tsBeginTime += "-"; + tsBeginTime += day; + tsBeginTime += " 00:00:00"; + + Date beginDate = SQLTools.StrToDateTime(tsBeginTime); + List list = new ArrayList<>(); + + if("1".equalsIgnoreCase(isBefore)){ + for(int iDay = 0; iDay < 7; iDay++){ + Date queryStart = new Date(beginDate.getTime() + (iDay - 6) *24*3600000); + Date middleNight = new Date(beginDate.getTime() + (iDay+1 - 6)*24*3600000); + + String querySt = SQLTools.formatDate(queryStart); + String queryEnd = SQLTools.formatDate(middleNight); + + int countAlarm = alarmEvent.queryCount(dataSource,querySt,queryEnd); + AlarmDayCount alarmDayCount = new AlarmDayCount(); + + calendar.setTime(queryStart); + alarmDayCount.setYear(String.valueOf(calendar.get(Calendar.YEAR))); + alarmDayCount.setMonth(String.valueOf(calendar.get(Calendar.MONTH)+1)); + alarmDayCount.setDay(String.valueOf(calendar.get(Calendar.DATE))); + alarmDayCount.setCountAlarm(countAlarm); + list.add(alarmDayCount); + } + }else{ + for(int iDay = 0; iDay<7; iDay++){ + Date queryStart = new Date(beginDate.getTime() + iDay*24*3600000); + Date middleNight = new Date(beginDate.getTime() + (iDay+1)*24*3600000); + + String querySt = SQLTools.formatDate(queryStart); + String queryEnd = SQLTools.formatDate(middleNight); + + int countAlarm = alarmEvent.queryCount(dataSource,querySt,queryEnd); + + AlarmDayCount alarmDayCount = new AlarmDayCount(); + calendar.setTime(queryStart); + alarmDayCount.setYear(String.valueOf(calendar.get(Calendar.YEAR))); + alarmDayCount.setMonth(String.valueOf(calendar.get(Calendar.MONTH)+1)); + alarmDayCount.setDay(String.valueOf(calendar.get(Calendar.DATE))); + alarmDayCount.setCountAlarm(countAlarm); + + list.add(alarmDayCount); + } + } + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/read",method = RequestMethod.POST) + public RespEntity readSensorAlarmEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + SensorAlarmEventEntity event = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(event.getEventId() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + SensorAlarmEventEntity eventDB = (SensorAlarmEventEntity)event.QueryIt(dataSource); + if(eventDB != null) { + eventDB.setReadState(SensorAlarmEventEntity.STATE_Read); + eventDB.setStateTime(new Date()); + if(eventDB.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/check",method = RequestMethod.POST) + public RespEntity checkSensorAlarmEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + SensorAlarmEventEntity event = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if(event==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(event.getEventId() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + SensorAlarmEventEntity eventDB = (SensorAlarmEventEntity)event.QueryIt(dataSource); + if(eventDB != null) { + eventDB.setState(SensorAlarmEventEntity.STATE_DISPATCHED); + eventDB.setStateTime(new Date()); + + if(FireCtrlSystemInit.netMode == 1) { + if("wechat".equalsIgnoreCase(eventDB.getAlarmSource())){ + try{ + PublicAlarmEntity publicAlarm = new PublicAlarmEntity(); + publicAlarm.setAlarmId(eventDB.getEventId()); + PublicAlarmEntity publicAlarmDB = (PublicAlarmEntity)publicAlarm.QueryIt(dataSource); + if(publicAlarmDB != null){ + publicAlarmDB.setCheckResult("1"); + publicAlarmDB.setCheckTime(new Date()); + publicAlarmDB.setStatus("close"); + publicAlarmDB.Update(dataSource); + MultiAlarmEvent multiAlarmEvent = new MultiAlarmEvent(publicAlarmDB); + System.out.println("report alarm to multi-plat 一键报警: "+ JSON.toJSONString(multiAlarmEvent)); + multiAlarmEvent.reportToMultiPlat(); + + publicAlarmDB.reportImageToMultiPlat(); + } + + }catch (Exception e){ + System.out.println("report alarm to multi-plat 一键报警 fail: "+ e); + } + } + + } + + if(eventDB.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/update",method = RequestMethod.POST) + public RespEntity updateSensorAlarmEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + ProcessAlarmEventOpRecord eventOpRecord = (ProcessAlarmEventOpRecord) SQLTools.getEntityFromJson(rootnode, ProcessAlarmEventOpRecord.class); + if(eventOpRecord==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(eventOpRecord.getEventId() == null || eventOpRecord.getNewState() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorAlarmEventEntity eventDB = new SensorAlarmEventEntity(); + eventDB.setEventId(eventOpRecord.getEventId()); + System.out.println("update sensor event: "+ JSON.toJSONString(eventDB)); + + eventDB = (SensorAlarmEventEntity)eventDB.QueryIt(dataSource); + if(eventDB != null) { + Date recordTime = new Date(); + eventOpRecord.setPreviousState(eventDB.getState()); + eventDB.setState(eventOpRecord.getNewState()); + if(!SensorAlarmEventEntity.STATE_Read.equalsIgnoreCase(eventDB.getReadState())){ + eventDB.setReadState(SensorAlarmEventEntity.STATE_Read); + eventDB.setStateTime(recordTime); + } + + if(eventDB.Update(dataSource)) { + + SensorEventUpdateNotify notify = new SensorEventUpdateNotify(eventOpRecord); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(eventDB.getBrigade()); + pro.setBorough(eventDB.getBorough()); + pro.setDetachment(eventDB.getDetachment()); + pro.setStation(eventDB.getStation()); + pro.setDevice_id(eventDB.getDeviceId()); + pro.setDevice_type(eventDB.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + + eventOpRecord.setRecordId(eventDB.getEventId() + "_" + recordTime.getTime()); + eventOpRecord.setTimestamp(recordTime); + + eventOpRecord.Insert(dataSource); + + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/get_image",method = RequestMethod.POST) + public RespEntity getAlarmEventImage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String imageId = JsonHelper.getStringValue(rootnode, "imageId"); + if(imageId==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + EventImageEntity imageDate = new EventImageEntity(imageId); + EventImageEntity imageDateInDB = (EventImageEntity)imageDate.QueryIt(dataSource); + if(imageDateInDB==null){ + return new RespEntity(RespCode.NOTEXIST); + } + return new RespEntity(RespCode.SUCCESS,imageDateInDB); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/summary",method = RequestMethod.POST) + public RespEntity getSensorAlarmEventSummary(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + SensorAlarmSummaryEntity event = (SensorAlarmSummaryEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmSummaryEntity.class); + if(event == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getYear() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + List listAlarms = new ArrayList<>(); + List list= event.queryPage(dataSource,null,null, 0, 500); + if(list == null || list.isEmpty()){ + SensorAlarmSummaryEntity zeroSummary = new SensorAlarmSummaryEntity(); + zeroSummary.setAlarmTotal(0); + listAlarms.add(zeroSummary); + return new RespEntity(RespCode.SUCCESS,listAlarms); + } + if(event.getMode() == null){ + return new RespEntity(RespCode.SUCCESS,list); + } + switch (event.getMode()){ + case SensorAlarmSummaryEntity.Mode_Day:{ + return new RespEntity(RespCode.SUCCESS,list); + } + case SensorAlarmSummaryEntity.Mode_Week:{ + SensorAlarmSummaryEntity zeroSummary = new SensorAlarmSummaryEntity(); + + int weekTotal = 0; + for(int iDay = 0; iDay < list.size(); iDay++){ + SensorAlarmSummaryEntity daySum = (SensorAlarmSummaryEntity)list.get(iDay); + weekTotal += daySum.getAlarmTotal(); + } + zeroSummary.setAlarmTotal(weekTotal); + listAlarms.add(zeroSummary); + return new RespEntity(RespCode.SUCCESS,listAlarms); + } + case SensorAlarmSummaryEntity.Mode_Month:{ + SensorAlarmSummaryEntity zeroSummary = new SensorAlarmSummaryEntity(); + + int weekTotal = 0; + for(int iDay = 0; iDay < list.size(); iDay++){ + SensorAlarmSummaryEntity daySum = (SensorAlarmSummaryEntity)list.get(iDay); + weekTotal += daySum.getAlarmTotal(); + } + zeroSummary.setAlarmTotal(weekTotal); + listAlarms.add(zeroSummary); + return new RespEntity(RespCode.SUCCESS,listAlarms); + } + case SensorAlarmSummaryEntity.Mode_Year:{ + SensorAlarmSummaryEntity zeroSummary = new SensorAlarmSummaryEntity(); + + int weekTotal = 0; + for(int iDay = 0; iDay < list.size(); iDay++){ + SensorAlarmSummaryEntity daySum = (SensorAlarmSummaryEntity)list.get(iDay); + weekTotal += daySum.getAlarmTotal(); + } + zeroSummary.setAlarmTotal(weekTotal); + listAlarms.add(zeroSummary); + return new RespEntity(RespCode.SUCCESS,listAlarms); + } + } + + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value="/firectrl/client/skynet_ipc/getlist",method = RequestMethod.POST) + public RespEntity getSkynetIPCList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SkynetIPCEntity ipcInfo = (SkynetIPCEntity)SQLTools.getEntityFromJson(rootnode,SkynetIPCEntity.class); + if(ipcInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(ipcInfo.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 500; + if (pageindex < 0) + pageindex = 0; + + List list = ipcInfo.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/skynet_ipc/add",method = RequestMethod.POST) + public RespEntity addSkynetIPC(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SkynetIPCEntity ipcInfo = (SkynetIPCEntity) SQLTools.getEntityFromJson(rootnode, SkynetIPCEntity.class); + if (ipcInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if (ipcInfo.getPointCode() == null || ipcInfo.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(ipcInfo.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (ipcInfo.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/skynet_ipc/delete",method = RequestMethod.POST) + public RespEntity deleteSkynetIPC(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + SkynetIPCEntity ipcInfo = (SkynetIPCEntity) SQLTools.getEntityFromJson(rootnode, SkynetIPCEntity.class); + if (ipcInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( ipcInfo.getBrigade() == null || ipcInfo.getPointCode() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (ipcInfo.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/skynet_ipc/update",method = RequestMethod.POST) + public RespEntity updateSkynetIPC(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SkynetIPCEntity ipcInfo = (SkynetIPCEntity) SQLTools.getEntityFromJson(rootnode, SkynetIPCEntity.class); + if (ipcInfo == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( ipcInfo.getBrigade() == null || ipcInfo.getPointCode() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (ipcInfo.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + /* + 德尚安报警点防区管理 + */ + @ResponseBody + @RequestMapping(value="/firectrl/client/push_alarm_point/add",method = RequestMethod.POST) + public RespEntity addPushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity) SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( alarmPointEntity.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if (alarmPointEntity.getDeviceType() == null ) + return new RespEntity(RespCode.ERROR_CMD); + if(alarmPointEntity.getDeviceType().equals("de_shang_an")){ + if (alarmPointEntity.getPointCode() == null || alarmPointEntity.getAccount() == null) + return new RespEntity(RespCode.ERROR_CMD); + if (alarmPointEntity.getPointId() == null ){ + alarmPointEntity.setPointId(alarmPointEntity.getAccount() + "_" + alarmPointEntity.getPointCode()); + } + alarmPointEntity.setDeviceId(alarmPointEntity.getPointId()); + }else{ + if (alarmPointEntity.getPointId() == null ) + return new RespEntity(RespCode.ERROR_CMD); + if (alarmPointEntity.getDeviceId() == null ){ + alarmPointEntity.setDeviceId(alarmPointEntity.getPointId()); + } + + } + + if(alarmPointEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (alarmPointEntity.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(alarmPointEntity), "/firectrl/agent/push_alarm_point/add"); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/push_alarm_point/delete",method = RequestMethod.POST) + public RespEntity deletePushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity) SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( alarmPointEntity.getBrigade() == null || alarmPointEntity.getPointId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (alarmPointEntity.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(alarmPointEntity), "/firectrl/agent/push_alarm_point/delete"); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/push_alarm_point/update",method = RequestMethod.POST) + public RespEntity updatePushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity) SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( alarmPointEntity.getBrigade() == null || alarmPointEntity.getPointId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (alarmPointEntity.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(alarmPointEntity), "/firectrl/agent/push_alarm_point/update"); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/agent/push_alarm_point/add",method = RequestMethod.POST) + public RespEntity addPushAlarmPointAgent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity) SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(alarmPointEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (alarmPointEntity.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/agent/push_alarm_point/delete",method = RequestMethod.POST) + public RespEntity deletePushAlarmPointAgent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity) SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( alarmPointEntity.getBrigade() == null || alarmPointEntity.getPointId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (alarmPointEntity.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/agent/push_alarm_point/update",method = RequestMethod.POST) + public RespEntity updatePushAlarmPointAgent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity) SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( alarmPointEntity.getBrigade() == null || alarmPointEntity.getPointId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (alarmPointEntity.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/push_alarm_point/getlist",method = RequestMethod.POST) + public RespEntity getPushAlarmPointList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity)SQLTools.getEntityFromJson(rootnode,PushAlarmPointEntity.class); + if(alarmPointEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmPointEntity.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = alarmPointEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/push_alarm_point/getcount",method = RequestMethod.POST) + public RespEntity getPushAlarmPointCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PushAlarmPointEntity alarmPointEntity = (PushAlarmPointEntity)SQLTools.getEntityFromJson(rootnode,PushAlarmPointEntity.class); + if(alarmPointEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(alarmPointEntity.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int count = alarmPointEntity.queryCount(dataSource,null,null); + CountResult countobj = new CountResult(); + countobj.setCount(count); + return new RespEntity(RespCode.SUCCESS,countobj); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watercheck/getstatuslist",method = RequestMethod.POST) + public RespEntity waterCheckDeviceStatusList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + WaterCheckDataEntity event = (WaterCheckDataEntity) SQLTools.getEntityFromJson(rootnode, WaterCheckDataEntity.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getDeviceid()==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/watercheck/getlaststatus",method = RequestMethod.POST) + public RespEntity getWaterCheckLastStatus(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + WaterCheckDataEntity event = (WaterCheckDataEntity) SQLTools.getEntityFromJson(rootnode, WaterCheckDataEntity.class); + if(event==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(event.getDeviceid()==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + SQLDataObject ob = event.QueryLast(dataSource); + return new RespEntity(RespCode.SUCCESS,ob); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationController.java new file mode 100644 index 0000000..31e767a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationController.java @@ -0,0 +1,1865 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.*; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentInfoEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionResultEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionTaskEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallAckEntity; +import com.jingyi.iotserver.firestationport.model.sensor.ACBEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.EarthInductorBuzEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SmokingBuzEventEntity; +import com.jingyi.iotserver.firestationport.model.equipment.EquipmentVerifyEntity; +import com.jingyi.iotserver.firestationport.model.station.*; +import com.jingyi.iotserver.firestationport.model.todev.*; +import com.jingyi.iotserver.firestationport.model.update.SoftwareUpdateTaskEntity; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.netease.NeteaseVideoService; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.AssignmentStatusNotify; +import com.jingyi.iotserver.firestationport.websocket.message.NoticeStatusNotify; +import com.jingyi.iotserver.firestationport.websocket.message.StationInfoVerifyNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class FireStationController { + + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private NeteaseVideoService neteaseVideoService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private SensorService sensorService; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + private final Logger logger = LoggerFactory.getLogger(FireStationController.class); + + @Autowired + private MessagePublisher messagePublisher; + + @ResponseBody + @RequestMapping(value = "/firectrl/op/quit", method = RequestMethod.GET) + public RespEntity exitSER(HttpServletRequest request) { + RespEntity rel = null; + System.exit(0); + return new RespEntity(RespCode.SUCCESS); + } + + @RequestMapping(value="/firectrl/getmqttaddr",method = RequestMethod.GET) + public RespEntity getMqttAddress(HttpServletRequest request) { + + return new RespEntity(RespCode.SUCCESS,messagePublisher.getMqttAddress()); + } + + @ResponseBody + @RequestMapping(value="/firectrl/getbaseinfo",method = RequestMethod.POST) + public RespEntity getFireStationBaseInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if(json==null) + json = (String) request.getAttribute("req-json"); + if (json != null) { + DeviceRequestEntity reqinfo = parseRequestCMD(json); + if(reqinfo!=null){ + if(reqinfo.getCID()!=2004){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null&&reqinfo.getDeviceId().length()>1) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null&&reqinfo.getUserName().length()>1) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) + rel = new RespEntity(RespCode.SUCCESS,station,reqinfo.getCID()); + else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/base",method = RequestMethod.POST) + public RespEntity getStationBaseInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + FireStationBaseInfoEntity station = JSON.parseObject(json, FireStationBaseInfoEntity.class); + if (station == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if (station.getName() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + station = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + + if(station!=null) + rel = new RespEntity(RespCode.SUCCESS,station); + else + rel = new RespEntity(RespCode.NOTEXIST); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/uploadbaseinfo",method = RequestMethod.POST) + public RespEntity uploadFireStationBaseInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + DeviceRequestEntity reqinfo = parseRequestCMD(json); + ObjectMapper mapper = new ObjectMapper(); + FireStationBaseInfoEntity tostation = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(reqinfo.getData(),FireStationBaseInfoEntity.class); + if(reqinfo!=null&&tostation!=null){ + if(reqinfo.getCID()!=2012){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + tostation.setDevice_id(null); + tostation.setName(station.getName()); + tostation.Update(dataSource); + station = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + logger.info(station.getName()+"update station info"); + rel = new RespEntity(RespCode.SUCCESS, station, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + // e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getextinfo",method = RequestMethod.POST) + public RespEntity getFireStationExtInfo(HttpServletRequest request) { + + String json = HttpTools.getBodyFromRequest(request); + if(json!=null){ + + } + return new RespEntity(RespCode.SUCCESS,json); + } + + @ResponseBody + @RequestMapping(value="/firectrl/uploadextinfo",method = RequestMethod.POST) + public RespEntity uploadFireStationExtInfo(HttpServletRequest request) { + + String json = HttpTools.getBodyFromRequest(request); + if(json!=null){ + + } + return null; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getequipment",method = RequestMethod.POST) + public RespEntity getFireStationEquipment(HttpServletRequest request) { + + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + + ObjectMapper mapper = new ObjectMapper(); + DeviceRequestEntity reqinfo = parseRequestCMD(json); + if(reqinfo!=null){ + if(reqinfo.getCID()!=2005){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) + { + List list = stationServices.queryStationEquipmentByName(station.getName()); + rel = new RespEntity(RespCode.SUCCESS,list,reqinfo.getCID()); + } + else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + // e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/uploadequipment",method = RequestMethod.POST) + public RespEntity uploadFireStationEquipment(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + + DeviceRequestEntity reqinfo = parseRequestCMD(json); + + if(reqinfo!=null){ + if(reqinfo.getCID()!=2013){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station==null){ + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + return rel; + } + logger.info(station.getName()+"update equipment info"); + logger.info("==>"+json); + + EquipmentVerifyEntity equipverify = new EquipmentVerifyEntity(); + equipverify.setName(station.getName()); + equipverify.setNumber(station.getNumber()); + equipverify.setStatus("apply"); + equipverify.setNewSetting(reqinfo.getData()); + + List equiplist = null; + try{ + equiplist = stationServices.queryStationEquipmentByName(station.getName()); + }catch (Exception e){ + + } + if(equiplist==null||equiplist.size()<=0) { + equipverify.setOldSetting(null); + }else { + String old = JsonHelper.convertObjectToStr(equiplist); + equipverify.setOldSetting(old); + } + equipverify.Insert(dataSource); + + StationInfoVerifyNotify notify = new StationInfoVerifyNotify(); + notify.setInfotype("equipment"); + notify.setStation(station.getName()); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(station.getBrigade()); + pro.setBorough(station.getBorough()); + pro.setDetachment(station.getDetachment()); + pro.setStation(station.getName()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + return new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + /* + if(stationServices.updateStationEquipment(station,reqinfo.getData())) + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + else + rel = new RespEntity(RespCode.FAIL,reqinfo.getCID()); + */ + + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getstationvideoinfo",method = RequestMethod.POST) + public RespEntity queryStationVideoInfo(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + FireStationVideoConfigEntity config = FireStationVideoConfigEntity.Query(dataSource,station.getName(),"netease"); + if(config!=null) + rel = new RespEntity(RespCode.SUCCESS,config,reqinfo.getCID()); + else + rel = new RespEntity(RespCode.FAIL,reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2015); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/heartbeat",method = RequestMethod.POST) + public RespEntity setStationHeartbeat(HttpServletRequest request) { + /* RespEntity rel = null; + System.out.print("setStationHeartbeat:"); + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + String name = JsonHelper.getStringValue(rootnode,"UserName"); + System.out.println(name); + if(name==null) + return new RespEntity(RespCode.NOTEXIST); + FireStationBaseInfoEntity station = stationServices.queryStationBaseInfoByName(name); + if(station==null) + return new RespEntity(RespCode.NOTEXIST); + fireStationLiveManager.setStationActive(station); + rel = new RespEntity(RespCode.SUCCESS); + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + */ + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode attachinfo = null; + if(reqinfo!=null){ + attachinfo = JsonHelper.parseBodyLevel1(reqinfo.getData()); + } + fireStationLiveManager.setStationActive(station,attachinfo); + System.out.println("kk station heartbeat: "+station.getName()+" time:"+System.currentTimeMillis()/1000); + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2001); + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/sign",method = RequestMethod.POST) + public RespEntity setStationSignState(HttpServletRequest request) { +/* + RespEntity rel = null; + System.out.print("setStationSignState:"); + try { + String json = HttpTools.getBodyFromRequest(request); + // System.out.println(json); + JsonNode rootnode=JsonHelper.parseBodyLevel1(json);//HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + String name = JsonHelper.getStringValue(rootnode,"UserName"); + System.out.println(name); + if(name==null) + return new RespEntity(RespCode.NOTEXIST); + + String state = JsonHelper.getStringValue(rootnode,"SIGN"); + System.out.println("SIGN:"+state); + if(state==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + FireStationBaseInfoEntity station = stationServices.queryStationBaseInfoByName(name); + if(station==null) + return new RespEntity(RespCode.NOTEXIST); + fireStationLiveManager.setStationSignState(station,state); + rel = new RespEntity(RespCode.SUCCESS); + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; +*/ + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + String state = JsonHelper.getStringValue(rootnode,"state"); + if(state==null) + return new RespEntity(RespCode.ERROR_REQUEST); + fireStationLiveManager.setStationSignState(station,state); + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2002); + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/alarm",method = RequestMethod.POST) + public RespEntity stationAlarm(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + + FireStationAlarmEntity alarm = (FireStationAlarmEntity) SQLTools.getEntityFromJson(rootnode, FireStationAlarmEntity.class); + + alarm.setStation(station.getName()); + alarm.setBrigade(station.getBrigade()); + alarm.setBorough(station.getBorough()); + alarm.setDetachment(station.getDetachment()); + alarm.setTimestamp(new Date()); + alarm.setState("notified"); + if(stationServices.addStationAlarm(alarm)) { + rel = new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.FAIL,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2003); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/ackrollcall",method = RequestMethod.POST) + public RespEntity ackRollCall(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + DeviceRequestEntity reqinfo = parseRequestCMD(json); + + FireStationRollCallAckEntity ack = (FireStationRollCallAckEntity) SQLTools.getEntityFromJson(reqinfo.getData(), FireStationRollCallAckEntity.class); + if (reqinfo != null && ack != null) { + { + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + if(ack.getStationname()==null||!ack.getStationname().equals(station.getName())) + ack.setStationname(station.getName()); + if(ack.getAcktime()==null) + ack.setAcktime(new Date(System.currentTimeMillis())); + if(ack.getState()==null) + ack.setState("ack"); + stationServices.addRollCallAck(ack); + rel = new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else + rel = new RespEntity(RespCode.ERROR_REQUEST); + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + private DeviceRequestEntity parseRequestCMD(String json){ + DeviceRequestEntity rel = null; + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode rootnode = mapper.readTree(json); + if(rootnode==null) + return null; + JsonNode m = rootnode.findValue("Mark"); + String mark = m.asText(); + + JsonNode u = rootnode.findValue("UserName"); + String username = null; + if(u!=null) + username = u.asText(); + + JsonNode d = rootnode.findValue("DeviceId"); + String deviceid = null; + if(d!=null) + deviceid = d.asText(); + + JsonNode c = rootnode.findValue("CID"); + int cid = 0; + if(c!=null) + cid = c.asInt(); + + JsonNode p = rootnode.findValue("PTS"); + long pts = 0; + if(p!=null) + pts = p.asLong(); + + JsonNode data = rootnode.findValue("data"); + + rel = new DeviceRequestEntity(); + rel.setCID(cid); + rel.setDeviceId(deviceid); + rel.setMark(mark); + rel.setPTS(pts); + rel.setUserName(username); + if(data!=null){ + rel.setData(data.asText()); + } + }catch (Exception e){ + + } + return rel; + + } + + private RespEntity executeOperateOnStation(HttpServletRequest request,IFireStationOperate op,int cmdid){ + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + + ObjectMapper mapper = new ObjectMapper(); + DeviceRequestEntity reqinfo = parseRequestCMD(json); + + if(reqinfo!=null){ + /* if(reqinfo.getCID()!=cmdid){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else*/{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + rel = op.ExecuteOperate(station,reqinfo); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + // e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + + @ResponseBody + @RequestMapping(value="/firectrl/addstaffinfo",method = RequestMethod.POST) + public RespEntity addFireStationStaffInfo(HttpServletRequest request) { + + return executeOperateOnStaff(request,new IStaffOperate(){ + public RespEntity ExecuteOperate(FireStationStaffInfoEntity staff, Object param){ + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + if(staff==null||staff.getStaffid()==null||staff.getStaffid().length()<=0|| + staff.getStationName()==null||!staff.getStationName().equals(reqinfo.getUserName())) + return new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + + String password = MD5Tools.md5("111111"); + password = MD5Tools.md5(staff.getStaffid()+password); + + staff.setPassword(password); + RespEntity rel = stationServices.addStationStaff(staff); + rel.setRequest(reqinfo.getCID()); + return rel; + } + },2021); + + } + + @ResponseBody + @RequestMapping(value="/firectrl/deletestaffinfo",method = RequestMethod.POST) + public RespEntity deleteFireStationStaffInfo(HttpServletRequest request) { + return executeOperateOnStaff(request,new IStaffOperate(){ + public RespEntity ExecuteOperate(FireStationStaffInfoEntity staff, Object param){ + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + if(staff==null||staff.getStaffid()==null||staff.getStaffid().length()<=0) + return new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + RespEntity rel = stationServices.deleteStationStaff(staff); + rel.setRequest(reqinfo.getCID()); + return rel; + } + },2022); + } + + //for devices pre-version + @ResponseBody + @RequestMapping(value="/firestation/getstaffinfo",method = RequestMethod.POST) + public RespEntity getFireStationStaffInfo(HttpServletRequest request) { + RespEntity rel = null; + String json = HttpTools.getBodyFromRequest(request); + if(json!=null){ + DeviceRequestEntity reqinfo = parseRequestCMD(json); + ObjectMapper mapper = new ObjectMapper(); + + if(reqinfo!=null){ + if(reqinfo.getCID()!=2006){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + + FireStationStaffInfoEntity st = new FireStationStaffInfoEntity(); + st.setStationName(station.getName()); + List staffs = st.queryList(dataSource,null,null); + for(SQLDataObject ob:staffs){ + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)ob; + if(staff!=null) + staff.setPassword(null); + } + rel = new RespEntity(RespCode.SUCCESS, staffs, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + return rel; + } + + //for devices last-version + @ResponseBody + @RequestMapping(value="/firectrl/getstaffinfo",method = RequestMethod.POST) + public RespEntity getFireCtrlStationStaffInfo(HttpServletRequest request) { + RespEntity rel = null; + String json = HttpTools.getBodyFromRequest(request); + if(json!=null){ + DeviceRequestEntity reqinfo = parseRequestCMD(json); + ObjectMapper mapper = new ObjectMapper(); + + if(reqinfo!=null){ + if(reqinfo.getCID()!=2006){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + FireStationStaffInfoEntity st = new FireStationStaffInfoEntity(); + st.setStationName(station.getName()); + List staffs = st.queryList(dataSource,null,null); + for(SQLDataObject ob:staffs){ + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)ob; + if(staff!=null) + staff.setPassword(null); + } + rel = new RespEntity(RespCode.SUCCESS, staffs, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/updatestaffinfo",method = RequestMethod.POST) + public RespEntity updateFireStationStaffInfo(HttpServletRequest request) { + return executeOperateOnStaff(request,new IStaffOperate(){ + public RespEntity ExecuteOperate(FireStationStaffInfoEntity staff, Object param){ + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + if(staff==null||staff.getStaffid()==null||staff.getStaffid().length()<=0||staff.getStationName()==null|| + staff.getStationName().length()<=0) + return new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + if(FireStationBaseInfoEntity.Query(dataSource,staff.getStationName())==null) + return new RespEntity(RespCode.NOTEXIST,reqinfo.getCID());; + staff.setPassword(null); + if(stationServices.updateStationStaff(staff)) + return new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + else + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + } + },2023); + } + + private RespEntity executeOperateOnStaff(HttpServletRequest request,IStaffOperate op,int cmdid){ + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + if (json != null) { + + ObjectMapper mapper = new ObjectMapper(); + DeviceRequestEntity reqinfo = parseRequestCMD(json); + + if(reqinfo!=null){ + if(reqinfo.getCID()!=cmdid){ + rel = new RespEntity(RespCode.ERROR_CMD,reqinfo.getCID()); + }else{ + FireStationBaseInfoEntity station = null; + if(reqinfo.getDeviceId()!=null) + station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,reqinfo.getDeviceId()); + else if(reqinfo.getUserName()!=null) + station = FireStationBaseInfoEntity.Query(dataSource,reqinfo.getUserName()); + if(station!=null) { + FireStationStaffInfoEntity staff = (FireStationStaffInfoEntity)SQLTools.getEntityFromJson(reqinfo.getData(),FireStationStaffInfoEntity.class); + rel = op.ExecuteOperate(staff,reqinfo); + }else + rel = new RespEntity(RespCode.NOTEXIST,reqinfo.getCID()); + } + }else{ + rel = new RespEntity(RespCode.ERROR_REQUEST); + } + } + }catch (Exception e){ + // e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getstationsensor",method = RequestMethod.POST) + public RespEntity getFireCtrlStationSensorList(HttpServletRequest request) { + + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String conditiondata = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(conditiondata); + SensorDeviceEntity sensor = (SensorDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + if(sensor!=null) { + + }else + sensor = new SensorDeviceEntity(); + sensor.setOwner(station.getName()); + + List sensors = SensorDeviceEntity.QueryByOwner(dataSource,station.getName()); + + rel = new RespEntity(RespCode.SUCCESS, sensors, reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2024); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/stopsmokingbuzevent",method = RequestMethod.POST) + public RespEntity stopSmokingBuzEvent(HttpServletRequest request) { + + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String conditiondata = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(conditiondata); + String sensorid = JsonHelper.getStringValue(rootnode,"deviceid"); + rel = sensorService.stopSmokingBuzEvent(sensorid); + rel.setRequest(reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2025); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/processsmokingbuzevent",method = RequestMethod.POST) + public RespEntity ProcessSmokingBuzEvent(HttpServletRequest request) { + + + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String conditiondata = reqinfo.getData(); + SmokingBuzEventEntity buzevent = (SmokingBuzEventEntity)SQLTools.getEntityFromJson(reqinfo.getData(),SmokingBuzEventEntity.class); + + rel = sensorService.ownerProcessSmokingBuzEvent(buzevent); + rel.setRequest(reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2028); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getsmokingbuzevent",method = RequestMethod.POST) + public RespEntity getSmokingBuzEvent(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String conditiondata = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(conditiondata); + String status = null; + if(rootnode!=null){ + status = JsonHelper.getStringValue(rootnode,"status"); + if(status==null||(!status.equals("stop")&&!status.equals("start"))) + status = "start"; + }else + status = "start"; + String sensorid = JsonHelper.getStringValue(rootnode,"deviceid"); + List eventlist = sensorService.querySatationSmokingBuzEvent(station.getName(),status); + rel = new RespEntity(RespCode.SUCCESS,eventlist,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2026); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getearthinductorbuzevent",method = RequestMethod.POST) + public RespEntity getEarthInductorBuzEvent(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String conditiondata = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(conditiondata); + String status = null; + if(rootnode!=null){ + status = JsonHelper.getStringValue(rootnode,"status"); + if(status==null||(!status.equals("stop")&&!status.equals("start"))) + status = "start"; + }else + status = "start"; + String sensorid = JsonHelper.getStringValue(rootnode,"deviceid"); + List eventlist = sensorService.querySatationEarthInductorBuzEvent(station.getName(),status); + rel = new RespEntity(RespCode.SUCCESS,eventlist,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2027); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/getstationbound",method = RequestMethod.POST) + public RespEntity getGetStationBound(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + FireStationBoundEntity bound = FireStationBoundEntity.Query(dataSource,station.getName()); + rel = new RespEntity(RespCode.SUCCESS,bound,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2029); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/message/read",method = RequestMethod.POST) + public RespEntity setStationNoticRead(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String data = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(data); + String noticeid = JsonHelper.getStringValue(rootnode,"noticeid"); + if(noticeid==null||noticeid.length()<=0) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + NoticeEntity noticeinfo = NoticeEntity.QueryNotice(dataSource,noticeid); + if(noticeinfo==null) + return new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + + NoticeStatusEntity status = new NoticeStatusEntity(); + status.setNoticeid(noticeid); + status.setId(noticeinfo.getId()); + status.setStation(station.getName()); + status.setReadtime(new Date()); + status.setState("read"); + + NoticeStatusNotify notify = new NoticeStatusNotify(); + notify.setNoticeid(noticeid); + notify.setStation(station.getName()); + notify.setReadtime(status.getReadtime()); + notify.setState(status.getState()); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(station.getName()); + pro.setBrigade(station.getBrigade()); + pro.setBorough(station.getBorough()); + pro.setDetachment(station.getDetachment()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + + status.extendName(""+noticeinfo.getId()); + if(!status.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2007); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/assignment/read",method = RequestMethod.POST) + public RespEntity setStationAssignmentRead(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String data = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(data); + String assignmentid = JsonHelper.getStringValue(rootnode,"assignmentid"); + if(assignmentid==null||assignmentid.length()<=0) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + AssignmentEntity assignmentinfo = AssignmentEntity.QueryAssignment(dataSource,assignmentid); + if(assignmentinfo==null) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + + AssignmentStatusEntity status = new AssignmentStatusEntity(); + status.setAssignmentid(assignmentid); + status.setId(assignmentinfo.getId()); + status.setStation(station.getName()); + status.setReceivetime(new Date()); + status.setState("received"); + status.extendName(""+assignmentinfo.getId()); + if(!status.UpdateState(dataSource)) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2008); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/assignment/start",method = RequestMethod.POST) + public RespEntity setStationAssignmentStart(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String data = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(data); + String assignmentid = JsonHelper.getStringValue(rootnode,"assignmentid"); + if(assignmentid==null||assignmentid.length()<=0) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + AssignmentEntity assignmentinfo = AssignmentEntity.QueryAssignment(dataSource,assignmentid); + if(assignmentinfo==null) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + + AssignmentStatusEntity status = AssignmentStatusEntity.QueryAssignmentStatus(dataSource,assignmentid,station.getName(),assignmentinfo.getId()); + if(status==null) + status = new AssignmentStatusEntity(); + status.setAssignmentid(assignmentid); + status.setId(assignmentinfo.getId()); + status.setStation(station.getName()); + /* status.setBrigade(station.getBrigade()); + status.setBorough(station.getBorough()); + status.setDetachment(station.getDetachment()); + */ + status.setProcesstime(new Date()); + status.setState("processed"); + status.extendName(""+assignmentinfo.getId()); + if(!status.UpdateState(dataSource)) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + // notify web client + + AssignmentStatusNotify notify = new AssignmentStatusNotify(); + notify.setAssignmentid(assignmentid); + notify.setStation(station.getName()); + notify.setBrigade(station.getBrigade()); + notify.setBorough(station.getBorough()); + notify.setDetachment(station.getDetachment()); + notify.setState("processed"); + notify.setReceivetime(status.getReceivetime()); + notify.setProcesstime(new Date()); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(station.getName()); + pro.setBrigade(station.getBrigade()); + pro.setBorough(station.getBorough()); + pro.setDetachment(station.getDetachment()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2009); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/assignment/end",method = RequestMethod.POST) + public RespEntity setStationAssignmentEnd(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String data = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(data); + String assignmentid = JsonHelper.getStringValue(rootnode,"assignmentid"); + if(assignmentid==null||assignmentid.length()<=0) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + AssignmentEntity assignmentinfo = AssignmentEntity.QueryAssignment(dataSource,assignmentid); + if(assignmentinfo==null) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + + AssignmentStatusEntity status = AssignmentStatusEntity.QueryAssignmentStatus(dataSource,assignmentid,station.getName(),assignmentinfo.getId()); + + if(status==null) + status = new AssignmentStatusEntity(); + status.setAssignmentid(assignmentid); + status.setId(assignmentinfo.getId()); + status.setStation(station.getName()); + /* status.setBrigade(station.getBrigade()); + status.setBorough(station.getBorough()); + status.setDetachment(station.getDetachment()); + */ + status.setCompletetime(new Date()); + status.setState("completed"); + status.extendName(""+assignmentinfo.getId()); + if(!status.UpdateState(dataSource)) + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + rel = new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + + AssignmentStatusNotify notify = new AssignmentStatusNotify(); + notify.setAssignmentid(assignmentid); + notify.setStation(station.getName()); + notify.setBrigade(station.getBrigade()); + notify.setBorough(station.getBorough()); + notify.setDetachment(station.getDetachment()); + notify.setState("completed"); + notify.setReceivetime(assignmentinfo.getTimestamp()); + notify.setProcesstime(status.getProcesstime()); + notify.setCompletetime(status.getCompletetime()); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(station.getName()); + pro.setBrigade(station.getBrigade()); + pro.setBorough(station.getBorough()); + pro.setDetachment(station.getDetachment()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2010); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/assignment/statechange",method = RequestMethod.POST) + public RespEntity changeAssignmentState(HttpServletRequest request) { + + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + String data = reqinfo.getData(); + JsonNode rootnode= JsonHelper.parseBodyLevel1(data); + String assignmentid = JsonHelper.getStringValue(rootnode,"assignmentid"); + if(assignmentid==null||assignmentid.length()<=0) + return new RespEntity(RespCode.NOTEXIST); + AssignmentEntity assignmentinfo = AssignmentEntity.QueryAssignment(dataSource,assignmentid); + if(assignmentinfo==null) + return new RespEntity(RespCode.NOTEXIST); + AssignmentEventEntity event = (AssignmentEventEntity) SQLTools.getEntityFromJson(rootnode, AssignmentEventEntity.class); + if(event==null) + return new RespEntity(RespCode.FAIL); + event.setStation(station.getName()); + if(event.getTimestamp()==null) + event.setTimestamp(new Date()); + if(event.Insert(dataSource)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2034); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/roundinspect/gettask",method = RequestMethod.POST) + public RespEntity getRoundInspectTask(HttpServletRequest request) { + RespEntity rel = null; + try { + + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if(rootnode==null) + return new RespEntity(RespCode.ERROR_REQUEST); + String station = JsonHelper.getStringValue(rootnode,"station"); + if(station==null||station.length()<=0||station.equals("null")) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = RoundInspectionTaskEntity.queryUnprocessTask(dataSource,station); + if(list!=null) { + for (RoundInspectionTaskEntity task : list) { + if (task.getStatus() == null || task.getStatus().equals("sent")) { + task.setStatus("received"); + task.UpdateStatus(dataSource); + } + } + } + rel = new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/roundinspect/reportresult",method = RequestMethod.POST) + public RespEntity reportRoundInspectTaskResult(HttpServletRequest request) { + RespEntity rel = null; + try { + + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if(rootnode==null) + return new RespEntity(RespCode.ERROR_REQUEST); + String station = JsonHelper.getStringValue(rootnode,"station"); + String deviceid = JsonHelper.getStringValue(rootnode,"deviceid"); + String username = JsonHelper.getStringValue(rootnode,"username"); + String userphone = JsonHelper.getStringValue(rootnode,"userphone"); + if(station==null||station.length()<=0||station.equals("null")) + return new RespEntity(RespCode.ERROR_REQUEST); + if(deviceid==null||deviceid.length()<=0||deviceid.equals("null")) + return new RespEntity(RespCode.ERROR_REQUEST); + + JsonNode tasklist = JsonHelper.getLevel2(rootnode,"tasklist"); + if(tasklist==null||!tasklist.isArray()) + return new RespEntity(RespCode.ERROR_REQUEST); + for(int i=0;i list = task.queryPage(dataSource,null,null,0,1000); + if(list==null||list.size()<=0) + return new RespEntity(RespCode.NOTEXIST); + + + for(SQLDataObject od:list){ + SoftwareUpdateTaskEntity t = (SoftwareUpdateTaskEntity) od; + if(t!=null&&t.getVersioncode()!=versioncode){ + boolean inscope = false; + List scopelist = ( List)SQLTools.getEntityListFromJson(task.getScope(), OrganiztionUri.class); + if(scopelist!=null&&scopelist.size()>0) { + for (OrganiztionUri s : scopelist) { + if (s != null) { + String stationname = null; + if (s.getStation() != null) { + stationname = s.getStation(); + if(stationname.equals(station.getName())) + inscope = true; + } else if (s.getDetachment() != null) { + if(s.getDetachment().equals(station.getDetachment())) + inscope = true; + } else if (s.getBorough() != null) { + if(s.getBorough().equals(station.getBorough())) + inscope = true; + } else if (s.getBrigade() != null) { + if(s.getBrigade().equals(station.getBrigade())) + inscope = true; + } + + } + if(inscope) + break; + } + + }else + inscope = true; + + if(inscope&&t.getMode().equals("L2H")){ + if(t.getVersioncode()>versioncode) + return new RespEntity(RespCode.SUCCESS,t,reqinfo.getCID()); + }else if(inscope&&t.getMode().equals("V2V")){ + if(t.getDevversioncode()==versioncode) + return new RespEntity(RespCode.SUCCESS,t,reqinfo.getCID()); + } + } + } + + return new RespEntity(RespCode.NOTEXIST); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2030); + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/property/add",method = RequestMethod.POST) + public RespEntity addStationProperty(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + String name = JsonHelper.getStringValue(rootnode,"name"); + String type = JsonHelper.getStringValue(rootnode,"type"); + String property = JsonHelper.getStringValue(rootnode,"property"); + if(name==null||name.length()<=0||type==null||type.length()<=0||property==null||property.length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST,reqinfo.getCID()); + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setStation(station.getName()); + pro.setName(name); + pro.setType(type); + pro.setProperty(property); + if(pro.addProperty(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.FAIL,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2031); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/property/delete",method = RequestMethod.POST) + public RespEntity deleteStationProperty(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + String name = JsonHelper.getStringValue(rootnode,"name"); + String type = JsonHelper.getStringValue(rootnode,"type"); + String property = JsonHelper.getStringValue(rootnode,"property"); + + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setStation(station.getName()); + pro.setName(name); + pro.setType(type); + pro.setProperty(property); + if(pro.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.FAIL,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2032); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/property/get",method = RequestMethod.POST) + public RespEntity getStationProperty(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + String type = JsonHelper.getStringValue(rootnode,"type"); + String name = JsonHelper.getStringValue(rootnode,"name"); + + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setStation(station.getName()); + pro.setName(name); + pro.setType(type); + List list = pro.queryList(dataSource,null,null); + + rel = new RespEntity(RespCode.SUCCESS,list, reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2033); + return rel; + /* + try{ + String url = "https://restapi.amap.com/v3/direction/walking?origin="; + try { + String key = "0ae6456395501ef661f282eb0093bdec"; + url += 121.12456+","+31.03452+"&destination="+121.0324+","+31.1343+ + "&extensions=all&output=json&key="+key; + HttpURLConnection connection = HttpTools.createHttpConnection(url); + connection.setRequestMethod("GET"); + connection.connect(); + + + int responseCode = connection.getResponseCode(); + if(responseCode == HttpURLConnection.HTTP_OK){ + String json = HttpTools.getBodyFromRespone(connection); + System.out.println(json); + } + + }catch (Exception e){ + + } + + }catch (Exception e){ + + } + return null; + */ + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/property/getacbeventcount",method = RequestMethod.POST) + public RespEntity getACBEventCount(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + + String deviceid = JsonHelper.getStringValue(rootnode, "deviceid"); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + String alarm = JsonHelper.getStringValue(rootnode, "alarm"); + if(deviceid==null) + return new RespEntity(RespCode.ERROR_REQUEST); + SensorDeviceEntity device = SensorDeviceEntity.Query(dataSource,deviceid); + if(device==null) + return new RespEntity(RespCode.ERROR_REQUEST, reqinfo.getCID()); + ACBEventEntity event = new ACBEventEntity(); + event.setDeviceid(deviceid); + event.setDevid(device.getId()); + event.setType(alarm); + + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst, reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2033); + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/property/getacbeventlist",method = RequestMethod.POST) + public RespEntity getACBEventList(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + + String deviceid = JsonHelper.getStringValue(rootnode, "deviceid"); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + String alarm = JsonHelper.getStringValue(rootnode, "alarm"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + if(deviceid==null) + return new RespEntity(RespCode.ERROR_REQUEST); + SensorDeviceEntity device = SensorDeviceEntity.Query(dataSource,deviceid); + if(device==null) + return new RespEntity(RespCode.ERROR_REQUEST); + ACBEventEntity event = new ACBEventEntity(); + event.setDeviceid(deviceid); + event.setDevid(device.getId()); + event.setType(alarm); + + List list= event.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS,list, reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2033); + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/media/add",method = RequestMethod.POST) + public RespEntity addStationMedia(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + FireMediaInfoEntity info = (FireMediaInfoEntity)SQLTools.getEntityFromJson(rootnode, FireMediaInfoEntity.class); + if(info==null) + return new RespEntity(RespCode.ERROR_REQUEST,reqinfo.getCID()); + info.setStation(station.getName()); + + if(info.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + }else + rel = new RespEntity(RespCode.FAIL,reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2034); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/media/getcount",method = RequestMethod.POST) + public RespEntity getStationMediaCount(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + FireMediaInfoEntity mediainfo = new FireMediaInfoEntity(); + mediainfo.setStation(station.getName()); + int count = mediainfo.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst, reqinfo.getCID()); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2035); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/media/getlist",method = RequestMethod.POST) + public RespEntity getStationMediaList(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + FireMediaInfoEntity mediainfo = new FireMediaInfoEntity(); + mediainfo.setStation(station.getName()); + + List list= mediainfo.queryPage(dataSource,startstr,endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS,list, reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2036); + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/getneighbourstation",method = RequestMethod.POST) + public RespEntity getNeigbourStations(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + + double longitude = JsonHelper.getDoubleValue(rootnode,"longitude"); + double latitude = JsonHelper.getDoubleValue(rootnode,"latitude"); + double radius = JsonHelper.getDoubleValue(rootnode,"radius"); + if(latitude<=0||longitude<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + if(radius<=0) + radius = 0.05; + String sql = "select * from firectrl_station_info_table where longitude>="+(longitude-radius)+" and longitude<="+(longitude+radius)+ + " and latitude>="+(latitude-radius)+" and latitude<="+(latitude+radius); + + try { + List list = SQLTools.ExecuteQuery(dataSource,sql,FireStationBaseInfoEntity.class); + + rel = new RespEntity(RespCode.SUCCESS,list,reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION,reqinfo.getCID()); + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2037); + return rel; + + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/saveruntimecache",method = RequestMethod.POST) + public RespEntity saveStationRuntimeCache(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + FireStationRuntimeStatusCacheEntity info = (FireStationRuntimeStatusCacheEntity)SQLTools.getEntityFromJson(rootnode, FireStationRuntimeStatusCacheEntity.class); + if(info==null) + return new RespEntity(RespCode.ERROR_REQUEST,reqinfo.getCID()); + if(info.QueryIt(dataSource)!=null) { + if(info.Update(dataSource)){ + return new RespEntity(RespCode.SUCCESS,reqinfo.getCID()); + }else{ + return new RespEntity(RespCode.FAIL,reqinfo.getCID()); + } + }else { + if (info.Insert(dataSource)) { + return new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + } else { + return new RespEntity(RespCode.FAIL, reqinfo.getCID()); + } + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2038); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/getruntimecache",method = RequestMethod.POST) + public RespEntity getStationRuntimeCache(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + FireStationRuntimeStatusCacheEntity info = (FireStationRuntimeStatusCacheEntity)SQLTools.getEntityFromJson(rootnode, FireStationRuntimeStatusCacheEntity.class); + if(info==null) + info = new FireStationRuntimeStatusCacheEntity(); + + if(rootnode.get("sum1")==null) + info.setSum1(-1); + + if(rootnode.get("sum2")==null) + info.setSum2(-1); + + info.setStation(station.getName()); + List list = info.queryList(dataSource,null,null); + return new RespEntity(RespCode.SUCCESS,list,reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2039); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/assignment/processinfo/add",method = RequestMethod.POST) + public RespEntity addStationAssignmentProcessInfo(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + AssignmentProcessInfoEntity info = (AssignmentProcessInfoEntity)SQLTools.getEntityFromJson(rootnode, AssignmentProcessInfoEntity.class); + if(info==null||info.getAssignmentid()==null) + return new RespEntity(RespCode.ERROR_REQUEST,reqinfo.getCID()); + + + if(info.QueryIt(dataSource)!=null) { + return new RespEntity(RespCode.EXIST,reqinfo.getCID()); + }else { + if (info.Insert(dataSource)) { + return new RespEntity(RespCode.SUCCESS, reqinfo.getCID()); + } else { + return new RespEntity(RespCode.FAIL, reqinfo.getCID()); + } + } + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2039); + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/station/assignment/processinfo/get",method = RequestMethod.POST) + public RespEntity getStationAssignmentProcessInfo(HttpServletRequest request) { + RespEntity rel = executeOperateOnStation(request,new IFireStationOperate(){ + @Override + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station,Object param) { + RespEntity rel = null; + try { + DeviceRequestEntity reqinfo = (DeviceRequestEntity)param; + JsonNode rootnode = JsonHelper.parseBodyLevel1(reqinfo.getData()); + String assignmentid = JsonHelper.getStringValue(rootnode,"assignmentid"); + String stationname = JsonHelper.getStringValue(rootnode,"station"); + AssignmentProcessInfoEntity info = new AssignmentProcessInfoEntity(); + if(assignmentid==null||assignmentid.length()<=0||stationname==null||stationname.length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST,reqinfo.getCID()); + + info = (AssignmentProcessInfoEntity)info.QueryIt(dataSource); + if(info!=null) + return new RespEntity(RespCode.SUCCESS, info,reqinfo.getCID()); + else + return new RespEntity(RespCode.NOTEXIST, reqinfo.getCID()); + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + },2039); + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationSWUpdateController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationSWUpdateController.java new file mode 100644 index 0000000..8a6bda9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/FireStationSWUpdateController.java @@ -0,0 +1,172 @@ +package com.jingyi.iotserver.firestationport.controller; + + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.update.SoftwareUpdateTaskEntity; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class FireStationSWUpdateController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private UserAuthorManager userAuthorManager; + + + @ResponseBody + @RequestMapping(value = "/firectrl/client/swupdate/addtask", method = RequestMethod.POST) + public RespEntity addSWUpdateTask(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + SoftwareUpdateTaskEntity task = (SoftwareUpdateTaskEntity) SQLTools.getEntityFromJson(rootnode, SoftwareUpdateTaskEntity.class); + + if (task == null || task.getTaskid() == null || task.getTaskid().length() <= 0 ) + return new RespEntity(RespCode.ERROR_REQUEST); + + + if (task.QueryTask(dataSource, task.getTaskid()) != null) + return new RespEntity(RespCode.EXIST); + + if(task.getScope()==null||task.getScope().length()<5){ + JsonNode scope = JsonHelper.getLevel2(rootnode,"scope"); + task.setScope(scope.toString()); + } + + try { + task.setStatus("active"); + task.setTimestamp(new Date()); + + + if (!task.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + if(SendUpdateNotify(task)) + rel = new RespEntity(RespCode.SUCCESS); + else + rel = new RespEntity(RespCode.FAIL); + userAuthorManager.AddUserOperate(request, UserAuthorManager.USER_OPERATE_TYPE_CREATE, "UPDATE", + "发送通知给微站", JsonHelper.convertObjectToStr(task), rel.getCode()); + } catch (Exception e) { + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + private boolean SendUpdateNotify(SoftwareUpdateTaskEntity task){ + try{ + String taskstr = JsonHelper.convertObjectToStr(task); + if(taskstr==null) + return false; + List list = ( List)SQLTools.getEntityListFromJson(task.getScope(), OrganiztionUri.class); + for(OrganiztionUri s:list){ + if(s!=null){ + String group = null; + String station = null; + if(s.getStation()!=null) { + station = s.getStation(); + }else if(s.getDetachment()!=null){ + group = s.getDetachment(); + }else if(s.getBorough()!=null){ + group = s.getBorough(); + }else if(s.getBrigade()!=null){ + group = s.getBrigade(); + } + try { + if(station!=null) { + JpushClientUtil.sendMessageToDevice("firectrl", station, "update", taskstr, 0); + + }else if (group != null) { + JpushClientUtil.sendMessageToGroup("firectrl", group, "update", taskstr, 0); + } + + + }catch (Exception e){ + + } + } + } + + }catch (Exception e){ + return false; + } + return true; + } + + @ResponseBody + @RequestMapping(value = "/firectrl/client/swupdate/gettask", method = RequestMethod.POST) + public RespEntity getSWUpdateTask(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + SoftwareUpdateTaskEntity task = (SoftwareUpdateTaskEntity) SQLTools.getEntityFromJson(rootnode, SoftwareUpdateTaskEntity.class); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + if (task == null ) + task = new SoftwareUpdateTaskEntity(); + + Listlist = task.queryPage(dataSource,startstr,endstr,0,1000); + rel = new RespEntity(RespCode.SUCCESS,list); + + } catch (Exception e) { + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value = "/firectrl/client/swupdate/closetask", method = RequestMethod.POST) + public RespEntity closeSWUpdateTask(HttpServletRequest request) { + RespEntity rel = null; + + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + String taskid = JsonHelper.getStringValue(rootnode,"taskid"); + if (taskid == null || taskid.length()<=0) + return new RespEntity(RespCode.NOTEXIST); + SoftwareUpdateTaskEntity task = new SoftwareUpdateTaskEntity(); + task = task.QueryTask(dataSource,taskid); + if(task==null) + return new RespEntity(RespCode.NOTEXIST); + task.setStatus("close"); + if(task.UpdateStatus(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + + } catch (Exception e) { + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/IFireStationOperate.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/IFireStationOperate.java new file mode 100644 index 0000000..264f8ad --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/IFireStationOperate.java @@ -0,0 +1,9 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; + + +public interface IFireStationOperate { + public RespEntity ExecuteOperate(FireStationBaseInfoEntity station, Object param); +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/ISensorOperate.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/ISensorOperate.java new file mode 100644 index 0000000..89e5e5d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/ISensorOperate.java @@ -0,0 +1,8 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; + +public interface ISensorOperate { + public RespEntity ExecuteOperate(SensorDeviceEntity sensor, Object param); +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/ISensorSubdevOperate.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/ISensorSubdevOperate.java new file mode 100644 index 0000000..291d78c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/ISensorSubdevOperate.java @@ -0,0 +1,8 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorSubDeviceEntity; + +public interface ISensorSubdevOperate { + public RespEntity ExecuteOperate(SensorSubDeviceEntity sensor, Object param); +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/IStaffOperate.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/IStaffOperate.java new file mode 100644 index 0000000..79ff8bd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/IStaffOperate.java @@ -0,0 +1,8 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationStaffInfoEntity; + +public interface IStaffOperate { + public RespEntity ExecuteOperate(FireStationStaffInfoEntity staff, Object param); +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/IntelEyeController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/IntelEyeController.java new file mode 100644 index 0000000..ede0c25 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/IntelEyeController.java @@ -0,0 +1,394 @@ +package com.jingyi.iotserver.firestationport.controller; + + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.analyze.WeekCount; +import com.jingyi.iotserver.firestationport.model.complexquery.SystemCountInfo; +import com.jingyi.iotserver.firestationport.model.school.*; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.sensor.ys.HikvisionIPCEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.PolicemanInfo; +import com.jingyi.iotserver.firestationport.model.statistics.BoroughMonthSummaryEntity; +import com.jingyi.iotserver.firestationport.services.userman.HouseOwnerLoginResult; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.userman.HouseOwnerManager; +import com.jingyi.iotserver.firestationport.services.userman.HouseOwnerRunningInfo; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.sql.DataSource; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class IntelEyeController { + @Autowired + private DataSource dataSource; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private SensorService sensorService; + + @Autowired + private HouseOwnerManager houseOwnerManager; + @ResponseBody + @RequestMapping(value = "/firectrl/eye/login", method = RequestMethod.POST) + public RespEntity appLogin(HttpServletRequest request, HttpServletResponse response, @CookieValue(value = "token", required = false) String token) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_CMD); + } + String phone = JsonHelper.getStringValue(rootnode, "phone"); + String password = JsonHelper.getStringValue(rootnode, "password"); + if (phone == null) { + return new RespEntity(RespCode.USER_PWD_ERROR); + } + HouseOwnerRunningInfo info = houseOwnerManager.getHouseOwner(phone); + if(info==null){ + HttpSession session = request.getSession(); + String sessionid = session.getId(); + session.setAttribute(session.getId(),phone); + houseOwnerManager.addHouseOwner(phone,sessionid); + info = houseOwnerManager.getHouseOwner(phone); + } + HouseOwnerLoginResult result = new HouseOwnerLoginResult(); + result.setSession(info.getSession()); + return new RespEntity(RespCode.SUCCESS,result); + }catch (Exception e){ + + } + return new RespEntity(RespCode.FAIL); + } + + + @RequestMapping(value="/firectrl/eye/getsensorlist",method = RequestMethod.POST) + public RespEntity getSensorList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String devtype = JsonHelper.getStringValue(rootnode,"devicetype"); + String phone = JsonHelper.getStringValue(rootnode,"phone"); + SensorDeviceEntity sensor = new SensorDeviceEntity(); + + sensor.setHouseowner(phone); + sensor.setDevicetype(devtype); + List list = sensorService.queryStationSensor(sensor); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @RequestMapping(value="/firectrl/eye/reportfault",method = RequestMethod.POST) + public RespEntity reportFault(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + System.out.println(json); + } catch (Exception e) { + + } + return new RespEntity(RespCode.SUCCESS); + } + + @RequestMapping(value="/firectrl/system/count",method = RequestMethod.POST) + public RespEntity getSystemCountInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SystemCountInfo systemCountInfo = (SystemCountInfo) SQLTools.getEntityFromJson(rootnode,SystemCountInfo.class); + + if(systemCountInfo== null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(systemCountInfo.getBrigade() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + try { + FireStationBaseInfoEntity station =new FireStationBaseInfoEntity(); + station.setBrigade(systemCountInfo.getBrigade()); + int count = station.queryCount(dataSource,null,null); + // List stations = station.queryPage(dataSource, null,null,0,1000); + // int studentTotal = 0; + // int count = stations.size(); + // for(int iSt = 0; iSt < stations.size(); iSt++){ + // FireStationBaseInfoEntity school = (FireStationBaseInfoEntity)stations.get(iSt); + // studentTotal += school.getStudentCount(); + // } + + systemCountInfo.setStation(count); + //systemCountInfo.setStudent(studentTotal); + }catch (Exception e){ + systemCountInfo.setStation(0); + } + + try { + BoroughEntity borough =new BoroughEntity(); + borough.setBrigade(systemCountInfo.getBrigade()); + int count = borough.queryCount(dataSource,null,null); + systemCountInfo.setBorough(count); + }catch (Exception e){ + systemCountInfo.setBorough(0); + } + + try { + PushAlarmPointEntity alarmPoint =new PushAlarmPointEntity(); + alarmPoint.setBrigade(systemCountInfo.getBrigade()); + int count = alarmPoint.queryCount(dataSource,null,null); + systemCountInfo.setAlarmPoint(count); + }catch (Exception e){ + systemCountInfo.setAlarmPoint(0); + } + + try { + HikvisionIPCEntity hikvisionIPC =new HikvisionIPCEntity(); + hikvisionIPC.setBrigade(systemCountInfo.getBrigade()); + int count = hikvisionIPC.queryCount(dataSource,null,null); + systemCountInfo.setIpc(count); + }catch (Exception e){ + systemCountInfo.setIpc(0); + } + + try { + BigDecimal count = FireStationBaseInfoEntity.querySumery(dataSource,systemCountInfo.getBrigade()); + systemCountInfo.setStudent(count.intValue()); + }catch (Exception e){ + systemCountInfo.setStudent(0); + } + + + + try { + PolicemanInfo registerCount =new PolicemanInfo(); + registerCount.setBrigade(systemCountInfo.getBrigade()); + int count = registerCount.queryCount(dataSource,null,null); + systemCountInfo.setSchoolGuardCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolGuardCount(0); + } + + try { + SchoolNewsEntity schoolNews =new SchoolNewsEntity(); + schoolNews.setBrigade(systemCountInfo.getBrigade()); + int count = schoolNews.queryCount(dataSource,null,null); + systemCountInfo.setSchoolNewsCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolNewsCount(0); + } + + try { + SchoolNewsEntity schoolNews =new SchoolNewsEntity(); + schoolNews.setBrigade(systemCountInfo.getBrigade()); + int count = schoolNews.queryCount(dataSource,null,null); + systemCountInfo.setSchoolNewsCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolNewsCount(0); + } + + try { + GuardSignEventEntity signEvent =new GuardSignEventEntity(); + signEvent.setBrigade(systemCountInfo.getBrigade()); + signEvent.setDay(-1); + signEvent.setYear(-1); + signEvent.setMonth(-1); + int count = signEvent.queryCount(dataSource,null,null); + systemCountInfo.setSchoolSignCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolSignCount(0); + } + + try { + SchoolSecurityCheckEntity checkRecord =new SchoolSecurityCheckEntity(); + checkRecord.setBrigade(systemCountInfo.getBrigade()); + int count = checkRecord.queryCount(dataSource,null,null); + systemCountInfo.setSchoolCheckCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolCheckCount(0); + } + + try { + SchoolStarRatingEntity starRating =new SchoolStarRatingEntity(); + starRating.setBrigade(systemCountInfo.getBrigade()); + starRating.setSchoolTime(systemCountInfo.getSchoolTime()); + int count = starRating.queryCount(dataSource,null,null); + systemCountInfo.setSchoolStarCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolStarCount(0); + } + + try { + SchoolColorRatingEntity colorRating =new SchoolColorRatingEntity(); + colorRating.setBrigade(systemCountInfo.getBrigade()); + colorRating.setSchoolTime(systemCountInfo.getSchoolTime()); + int count = colorRating.queryCount(dataSource,null,null); + systemCountInfo.setSchoolColorCount(count); + }catch (Exception e){ + systemCountInfo.setSchoolColorCount(0); + } + + return new RespEntity(RespCode.SUCCESS, systemCountInfo); + }catch (Exception e){ + // e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @RequestMapping(value="/firectrl/schoolnews/weeks",method = RequestMethod.POST) + public RespEntity getSchoolNewsWeeks(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + SchoolNewsEntity schoolNewsFilter = JSON.parseObject(json, SchoolNewsEntity.class); + if(schoolNewsFilter == null){ + schoolNewsFilter = new SchoolNewsEntity(); + } + + List newsWeekSummary = new ArrayList<>(); + + Calendar nowTime = Calendar.getInstance(); + int nDayofWeek = nowTime.get(Calendar.DAY_OF_WEEK); + long dayOffsetMS = (nDayofWeek-1)*24*3600000; + + long starMS = nowTime.getTimeInMillis() - dayOffsetMS; + Date startDay = new Date(starMS); + String strStartDay = SQLTools.formatDay(startDay); + strStartDay += " 00:00:00"; + + String endStr = SQLTools.formatDate(new Date()); + + WeekCount weekNow = new WeekCount(); + weekNow.setStartTime(strStartDay); + weekNow.setEndTime(endStr); + int newsCount = schoolNewsFilter.queryCount(dataSource,strStartDay, endStr); + weekNow.setCount(newsCount); + newsWeekSummary.add(0,weekNow); + + + Date week2Start = new Date(SQLTools.StrToDateTime(weekNow.getStartTime()).getTime() - 7*24*3600000); + Date week3Start = new Date(SQLTools.StrToDateTime(weekNow.getStartTime()).getTime() - 14*24*3600000); + Date week4Start = new Date(SQLTools.StrToDateTime(weekNow.getStartTime()).getTime() - 21*24*3600000); + + WeekCount week2 = new WeekCount(); + week2.setStartTime(SQLTools.formatDate(week2Start)); + week2.setEndTime(weekNow.getStartTime()); + newsCount = schoolNewsFilter.queryCount(dataSource,week2.getStartTime(), week2.getEndTime()); + week2.setCount(newsCount); + newsWeekSummary.add(0,week2); + + WeekCount week3 = new WeekCount(); + week3.setStartTime(SQLTools.formatDate(week3Start)); + week3.setEndTime(week2.getStartTime()); + newsCount = schoolNewsFilter.queryCount(dataSource,week3.getStartTime(), week3.getEndTime()); + week3.setCount(newsCount); + newsWeekSummary.add(0,week3); + + WeekCount week4 = new WeekCount(); + week4.setStartTime(SQLTools.formatDate(week4Start)); + week4.setEndTime(week3.getStartTime()); + newsCount = schoolNewsFilter.queryCount(dataSource,week4.getStartTime(), week4.getEndTime()); + week4.setCount(newsCount); + newsWeekSummary.add(0,week4); + return new RespEntity(RespCode.SUCCESS, newsWeekSummary); + } catch (Exception e) { + + } + return new RespEntity(RespCode.SUCCESS); + } + + @RequestMapping(value="/firectrl/schoolsign/weeks",method = RequestMethod.POST) + public RespEntity getSchoolSignWeeks(HttpServletRequest request) { + RespEntity rel = null; + try { + String json = HttpTools.getBodyFromRequest(request); + GuardSignEventEntity signEvent = JSON.parseObject(json, GuardSignEventEntity.class); + if(signEvent == null){ + signEvent = new GuardSignEventEntity(); + } + signEvent.setMonth(-1); + signEvent.setYear(-1); + signEvent.setDay(-1); + + List newsWeekSummary = new ArrayList<>(); + + Calendar nowTime = Calendar.getInstance(); + int nDayofWeek = nowTime.get(Calendar.DAY_OF_WEEK); + long dayOffsetMS = (nDayofWeek-1)*24*3600000; + + long starMS = nowTime.getTimeInMillis() - dayOffsetMS; + Date startDay = new Date(starMS); + String strStartDay = SQLTools.formatDay(startDay); + strStartDay += " 00:00:00"; + + String endStr = SQLTools.formatDate(new Date()); + + WeekCount weekNow = new WeekCount(); + weekNow.setStartTime(strStartDay); + weekNow.setEndTime(endStr); + int newsCount = signEvent.queryCount(dataSource,strStartDay, endStr); + weekNow.setCount(newsCount); + newsWeekSummary.add(0,weekNow); + + + Date week2Start = new Date(SQLTools.StrToDateTime(weekNow.getStartTime()).getTime() - 7*24*3600000); + Date week3Start = new Date(SQLTools.StrToDateTime(weekNow.getStartTime()).getTime() - 14*24*3600000); + Date week4Start = new Date(SQLTools.StrToDateTime(weekNow.getStartTime()).getTime() - 21*24*3600000); + + WeekCount week2 = new WeekCount(); + week2.setStartTime(SQLTools.formatDate(week2Start)); + week2.setEndTime(weekNow.getStartTime()); + newsCount = signEvent.queryCount(dataSource,week2.getStartTime(), week2.getEndTime()); + week2.setCount(newsCount); + newsWeekSummary.add(0,week2); + + WeekCount week3 = new WeekCount(); + week3.setStartTime(SQLTools.formatDate(week3Start)); + week3.setEndTime(week2.getStartTime()); + newsCount = signEvent.queryCount(dataSource,week3.getStartTime(), week3.getEndTime()); + week3.setCount(newsCount); + newsWeekSummary.add(0,week3); + + WeekCount week4 = new WeekCount(); + week4.setStartTime(SQLTools.formatDate(week4Start)); + week4.setEndTime(week3.getStartTime()); + newsCount = signEvent.queryCount(dataSource,week4.getStartTime(), week4.getEndTime()); + week4.setCount(newsCount); + newsWeekSummary.add(0,week4); + return new RespEntity(RespCode.SUCCESS, newsWeekSummary); + } catch (Exception e) { + + } + return new RespEntity(RespCode.SUCCESS); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/IoTPlugInfoController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/IoTPlugInfoController.java new file mode 100644 index 0000000..20cca43 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/IoTPlugInfoController.java @@ -0,0 +1,200 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.pluginfo.PlugInfoEntity; + +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.List; + +@RestController +@CrossOrigin +public class IoTPlugInfoController { + @Autowired + private DataSource dataSource; + + @ResponseBody + @RequestMapping(value="/iotserver/pluginfo/add",method = RequestMethod.POST) + public RespEntity addPlugInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + PlugInfoEntity info = (PlugInfoEntity) SQLTools.getEntityFromJson(rootnode, PlugInfoEntity.class); + if(info==null||info.getId()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + + if(info.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + + if(info.Insert(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + }else{ + return new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/pluginfo/delete",method = RequestMethod.POST) + public RespEntity deletePlugInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + PlugInfoEntity info = (PlugInfoEntity) SQLTools.getEntityFromJson(rootnode, PlugInfoEntity.class); + if(info==null||info.getId()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + + if(info.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(info.Delete(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + }else{ + return new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/pluginfo/update",method = RequestMethod.POST) + public RespEntity updatePlugInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + PlugInfoEntity info = (PlugInfoEntity) SQLTools.getEntityFromJson(rootnode, PlugInfoEntity.class); + if(info==null||info.getId()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + + if(info.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(info.Update(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + }else{ + return new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/pluginfo/get",method = RequestMethod.POST) + public RespEntity getPlugInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + PlugInfoEntity info = (PlugInfoEntity) SQLTools.getEntityFromJson(rootnode, PlugInfoEntity.class); + if(info==null||info.getId()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + info = (PlugInfoEntity)info.QueryIt(dataSource); + + + return new RespEntity(RespCode.SUCCESS,info); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/pluginfo/getcount",method = RequestMethod.POST) + public RespEntity getPlugInfoCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + PlugInfoEntity info = (PlugInfoEntity) SQLTools.getEntityFromJson(rootnode, PlugInfoEntity.class); + if(info==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int count = info.queryCount(dataSource,startstr,endstr); + + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/pluginfo/getlist",method = RequestMethod.POST) + public RespEntity getPlugInfoList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + PlugInfoEntity info = (PlugInfoEntity) SQLTools.getEntityFromJson(rootnode, PlugInfoEntity.class); + if(info==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = info.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/IoTSensorController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/IoTSensorController.java new file mode 100644 index 0000000..7cf74a5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/IoTSensorController.java @@ -0,0 +1,2800 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.complexquery.AICameraFaceInfo; +import com.jingyi.iotserver.firestationport.model.complexquery.ElectricSensorResult; +import com.jingyi.iotserver.firestationport.model.complexquery.RFIDData; +import com.jingyi.iotserver.firestationport.model.complexquery.RFIDResp; +import com.jingyi.iotserver.firestationport.model.partner.CityTruckOrderEntity; +import com.jingyi.iotserver.firestationport.model.school.*; +import com.jingyi.iotserver.firestationport.model.sensor.*; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCInvadeEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeAlarmEntity; +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeRoomEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmSummaryEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidStateEntity; +import com.jingyi.iotserver.firestationport.model.sensor.ys.*; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.services.DataStatisticsService; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.sensor.ACBSystemAgent; +import com.jingyi.iotserver.firestationport.services.sensor.SensorRunInfoManager; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.*; +import com.jingyi.iotserver.iotctrl.IoTCtrlMessage; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.io.*; +import java.net.HttpURLConnection; +import java.text.SimpleDateFormat; +import java.util.*; + +@RestController +@CrossOrigin +public class IoTSensorController { + @Autowired + private DataSource dataSource; + @Autowired + private SensorService sensorService; + + @Autowired + private StationServices stationServices; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + EnvConfigService envConfigService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private SensorRunInfoManager sensorRunInfoManager; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Autowired + private ACBSystemAgent acbSystemAgent; + + @Autowired + private DataStatisticsService dataStatisticsService; + + @Autowired + private MessagePublisher messagePublisher; + private final Logger logger = LoggerFactory.getLogger(IoTSensorController.class); + @ResponseBody + @RequestMapping(value="/iotserver/sensor/exit") + public RespEntity closeSystem(HttpServletRequest request) { + System.exit(0); + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/agent") + public RespEntity agentSensorReport(HttpServletRequest request) { + RespEntity rel = null; + String json = HttpTools.getBodyFromRequest(request); + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + String devicetype = JsonHelper.getStringValue(rootnode,"devicetype"); + JsonNode eventlist = JsonHelper.getLevel2(rootnode,"eventlist"); + if(devicetype.equals("smoking")) + parseSmokingEvent(eventlist); + else if(devicetype.equals("pipepressure")){ + parsePipePressureEvent(eventlist); + }else if(devicetype.equals("boxpressure")){ + + }else if(devicetype.equals("liquidgage")){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, LiquidGageEventEntity.class); + sensorService.processLiquidgageEvent(events); + }else if(devicetype.equals("gas")){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, GasSensorEventEntity.class); + sensorService.processGasEvent(events); + }else if(devicetype.equals("alerterhost")){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, AlerterHostEventEntity.class); + sensorService.processAlerterHostEvent(events); + }else if(devicetype.equals("alarmhost")){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, STVAlarmEventEntity.class); + sensorService.processAlarmHostEvent(events); + }else if(devicetype.equals("watermeter")){ + sensorService.processWaterMeterEvent(eventlist); + }else if(devicetype.equals("rfid")){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, RfidEventEntity.class); + System.out.println(json); + sensorService.processRfidEvent(events); + } + + }catch (Exception e){ + e.printStackTrace(); + } + return new RespEntity(RespCode.SUCCESS); + } + + private void parseSmokingEvent(JsonNode eventlist){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, SmokingEventEntity.class); + sensorService.processSmokingEvent(events); + + } + + private void parsePipePressureEvent(JsonNode eventlist){ + List events = SQLTools.getEntityListFromJsonArray(eventlist, PipePressureEventEntity.class); + sensorService.processPipePressureEvent(events); + + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/earthinductor") + public RespEntity earthinductorSensorReport(HttpServletRequest request) { + RespEntity rel = null; + String json = HttpTools.getBodyFromRequest(request); + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + String devid = JsonHelper.getStringValue(rootnode,"SN"); + String name = JsonHelper.getStringValue(rootnode,"Name"); + JsonNode tmstatus = JsonHelper.getLevel2(rootnode,"TMoteStatus"); + int status = JsonHelper.getIntValue(tmstatus,"Status"); + int count = JsonHelper.getIntValue(tmstatus,"Count"); + String ts = JsonHelper.getStringValue(tmstatus,"Time"); + Date lasttime = SQLTools.StrToDateTime(ts); + + EarthInductorEventEntity event = new EarthInductorEventEntity(); + event.setDeviceid(devid); + event.setTimestamp(new Date().getTime()); + event.setDevicetype("earthinductor"); + event.setChangetime(lasttime); + if(status==0) + event.setEvent("idle"); + else if(status==1) + event.setEvent("occupy"); + else if(status==2) + event.setEvent("idle-heartbeat"); + else if(status==3) + event.setEvent("occupy-heartbeat"); + sensorService.processEarthInductorEvent(event); + }catch (Exception e){ + + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/huaxtent/earthinductor") + public RespEntity huaxtentEarthInductor(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + logger.info("huaxtent earthinductor: " + json); + System.out.println("huaxtent earthinductor: "+json); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + + String deviceid = JsonHelper.getStringValue(rootnode,"macId"); + int carstatus = JsonHelper.getIntValue(rootnode,"carStatus"); + long changetime= JsonHelper.getLongValue(rootnode,"stopOrMoveTime"); + EarthInductorEventEntity event = new EarthInductorEventEntity(); + event.setDeviceid(deviceid); + event.setTimestamp(new Date().getTime()); + event.setDevicetype("earthinductor"); + event.setChangetime(new Date(changetime)); + if(carstatus==0) + event.setEvent("idle"); + else if(carstatus==1) + event.setEvent("occupy"); + sensorService.processEarthInductorEvent(event); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/huaxtent/smoking") + public RespEntity huaxtentSmoking(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + logger.info("huaxtent smoking: " + json); + System.out.println("huaxtent smoking: "+json); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + + String deviceid = JsonHelper.getStringValue(rootnode,"macId"); + int carstatus = JsonHelper.getIntValue(rootnode,"carStatus"); + long changetime= JsonHelper.getLongValue(rootnode,"stopOrMoveTime"); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/jysensor/ctrl") + public RespEntity ctrlJYGasSemspr(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + + String url = "http://127.0.0.1:7020/sensor/gas/ctrl"; + + HttpURLConnection connection = HttpTools.createHttpConnection(url); + connection.setRequestMethod("POST"); + connection.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); + writer.write(json); + writer.close(); + + int responseCode = connection.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + return new RespEntity(RespCode.FAIL); + } + + }catch (Exception e){ + e.printStackTrace(); + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS,new Date()); + } + + //https://open.snd02.com/apiDocs/index.html#channelMessagePush + private void addACBStatus(ACBStatusEntity s, String content){ + if(s==null||content==null) + return ; + + JsonNode root = JsonHelper.parseBodyLevel1(content); + + s.setMac(JsonHelper.getStringValue(root,"mac")); + s.setAddr(JsonHelper.getIntValue(root,"addr")); + s.setOnline(JsonHelper.getStringValue(root,"online")); + s.setValidity(JsonHelper.getStringValue(root,"validity")); + s.setOc(JsonHelper.getStringValue(root,"oc")); + s.setEnablenetctrl(JsonHelper.getStringValue(root,"enablenetctrl")); + s.setPower(JsonHelper.getDoubleValue(root,"power")); + s.setLinetype(JsonHelper.getStringValue(root,"lineType")); + s.setAlarm(JsonHelper.getIntValue(root,"alarm")); + + s.setAld(JsonHelper.getDoubleValue(root,"aLd")); + s.setAa(JsonHelper.getDoubleValue(root,"aA")); + s.setAt(JsonHelper.getDoubleValue(root,"aT")); + s.setAv(JsonHelper.getDoubleValue(root,"aV")); + s.setAw(JsonHelper.getDoubleValue(root,"aW")); + s.setApf(JsonHelper.getDoubleValue(root,"aPF")); + + s.setGld(JsonHelper.getDoubleValue(root,"gLd")); + s.setGa(JsonHelper.getDoubleValue(root,"gA")); + s.setGt(JsonHelper.getDoubleValue(root,"gT")); + s.setGv(JsonHelper.getDoubleValue(root,"gV")); + s.setGw(JsonHelper.getDoubleValue(root,"gW")); + s.setGpf(JsonHelper.getDoubleValue(root,"gPF")); + + s.setBa(JsonHelper.getDoubleValue(root,"bA")); + s.setBt(JsonHelper.getDoubleValue(root,"bT")); + s.setBv(JsonHelper.getDoubleValue(root,"bV")); + s.setBw(JsonHelper.getDoubleValue(root,"bW" )); + s.setBpf(JsonHelper.getDoubleValue(root,"bPF")); + + s.setCa(JsonHelper.getDoubleValue(root,"cA")); + s.setCt(JsonHelper.getDoubleValue(root,"cT")); + s.setCv(JsonHelper.getDoubleValue(root,"cV")); + s.setCw(JsonHelper.getDoubleValue(root,"cPF")); + + s.Insert(dataSource); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/electric/heartbeat",method=RequestMethod.POST, + produces = {"application/x-www-form-urlencoded;charset=UTF-8"}, + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) + public Object electricHearbeat(@RequestParam Map params) { + ElectricSensorResult rel = new ElectricSensorResult(); + SensorDeviceEntity sensor = null; + try { + String content = null; + for(Map.Entry entry: params.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + System.out.println("key:"+key+" value:"+value); + if(key!=null&&key.equals("detect")){ + if(!value.equals("0")){ + rel.setMsg(value); + } + }else if(key!=null&&key.equals("mac")){ + JsonNode root = JsonHelper.parseBodyLevel1(value); + String mac = JsonHelper.getStringValue(root,"mac"); + sensor = SensorDeviceEntity.Query(dataSource,mac); + }else if(key!=null&&key.equals("content")){ + content = value; + } + } + rel.setCode("0"); + if(rel.getMsg()==null) + rel.setMsg("success"); + if(sensor==null&&content!=null){ + try{ + JsonNode root = JsonHelper.parseBodyLevel1(content); + String mac = JsonHelper.getStringValue(root,"mac"); + sensor = SensorDeviceEntity.Query(dataSource,mac); + }catch (Exception e){ + + } + } + if(sensor!=null) { + String frame = JsonHelper.convertObjectToStr(params); + sensorRunInfoManager.setSensorActive(sensor); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "acb", content, 0); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("sensor-event-notify"); + msg.setData(content); + msg.setTitle("acb"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( sensor.getOwner(),str); + + ACBEventEntity info = new ACBEventEntity(); + info.setDeviceid(sensor.getDeviceid()); + info.setDevid(sensor.getId()); + info.setTimestamp(new Date()); + info.setType("status"); + info.setContent(Base64.encodeBase64String(frame.getBytes("UTF8"))); + info.setOwner(sensor.getOwner()); + info.Insert(dataSource); + + ACBStatusEntity status = new ACBStatusEntity(); + status.setDeviceid(info.getDeviceid()); + status.setDevid(info.getDevid()); + status.setTimestamp(info.getTimestamp()); + status.setType(info.getType()); + status.setOwner(info.getOwner()); + + addACBStatus(status,content); + } + }catch (Exception e){ + rel.setCode("10"); + rel.setMsg("fail"); + } + + if(envConfigService.IsDataPortServer()){ + + } + return JsonHelper.convertObjectToStr(rel); + } +// + @ResponseBody + @RequestMapping(value="/iotserver/sensor/electric/alarm",method=RequestMethod.POST, + produces = {"application/x-www-form-urlencoded;charset=UTF-8"}, + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) + public Object electricAlarm(@RequestParam Map params) { + ElectricSensorResult rel = new ElectricSensorResult(); + SensorDeviceEntity sensor = null; + try { + String content = null; + for(Map.Entry entry: params.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + System.out.println("key:"+key+" value:"+value); + if(key!=null&&key.equals("detect")){ + if(!value.equals("0")){ + rel.setMsg(value); + } + }else if(key!=null&&key.equals("mac")){ + sensor = SensorDeviceEntity.Query(dataSource,value); + }else if(key!=null&&key.equals("content")){ + content = value; + } + } + rel.setCode("0"); + if(rel.getMsg()==null) + rel.setMsg("success"); + + if(sensor==null&&content!=null){ + try{ + JsonNode root = JsonHelper.parseBodyLevel1(content); + String mac = JsonHelper.getStringValue(root,"mac"); + sensor = SensorDeviceEntity.Query(dataSource,mac); + }catch (Exception e){ + + } + } + + if(sensor!=null) { + sensorRunInfoManager.setSensorActive(sensor); + String frame = JsonHelper.convertObjectToStr(params); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "acbalarm", content, 0); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("sensor-event-notify"); + msg.setData(content); + msg.setTitle("acbalarm"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( sensor.getOwner(),str); + + ACBEventEntity info = new ACBEventEntity(); + info.setDeviceid(sensor.getDeviceid()); + info.setDevid(sensor.getId()); + info.setTimestamp(new Date()); + info.setContent(Base64.encodeBase64String(frame.getBytes("UTF8"))); + info.setType("alarm"); + info.setOwner(sensor.getOwner()); + info.Insert(dataSource); +/* + ACBStatusEntity status = new ACBStatusEntity(); + status.setDeviceid(info.getDeviceid()); + status.setDevid(info.getDevid()); + status.setTimestamp(info.getTimestamp()); + status.setType(info.getType()); + status.setOwner(info.getOwner()); + + addACBStatus(status,content); +*/ + ACBStatusNotify notify = new ACBStatusNotify(); + + notify.setDeviceid(sensor.getDeviceid()); + notify.setStation(sensor.getOwner()); + notify.setStatus("alarm"); + notify.setInfo(frame); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource,notify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + } + }catch (Exception e){ + rel.setCode("10"); + rel.setMsg("fail"); + } + return JsonHelper.convertObjectToStr(rel); + //return rel; + } + + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/ain100/report") + public RespEntity ai100Report(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + logger.info("ai100 report: " + json); + + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + String dev_id = JsonHelper.getStringValue(rootnode,"dev_id"); + if(dev_id!=null){ + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, dev_id); + if (sensor != null) { + sensorRunInfoManager.setSensorActive(sensor); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "aicamera", json, 0); + } + return new RespEntity(RespCode.SUCCESS); + } + + JsonNode face = JsonHelper.getLevel2(rootnode,"FaceResults"); + if(face!=null&&face.isArray()&&face.size()>0){ + for(int i=0;i0){ + for(int i=0;i=1) + { + SmokingEventEntity evnet = new SmokingEventEntity(); + evnet.setDeviceid(dev_id); + evnet.setEvent("alarm"); + evnet.setDevicetype("smoking"); + List events = new ArrayList(); + events.add(evnet); + sensorService.processSmokingEvent(events); + }else if(SMOKE_STATE==0) + {// + sensorService.stopSmokingBuzEvent(dev_id); + } + } + + } + + + + String dev_id = JsonHelper.getStringValue(rootnode,"IMEI"); + if(dev_id!=null){ + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, dev_id); + if (sensor != null) { + sensorRunInfoManager.setSensorActive(sensor); + // if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + { + MessageToStation msg = new MessageToStation(); + msg.setMessage("smokingtest"); + msg.setData(json); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( sensor.getOwner(),str); + } + } + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + e.printStackTrace(); + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS,new Date()); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/gas/test/report") + public RespEntity testGasReport(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + + System.out.println("gas: "+json); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + String dev_id = JsonHelper.getStringValue(rootnode,"IMEI"); + int serviceId = JsonHelper.getIntValue(rootnode,"serviceId"); + double co = 0.0f; + int ch4 = 0; + if(dev_id==null) + return new RespEntity(RespCode.FAIL); + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, dev_id); + if(sensor==null) + return new RespEntity(RespCode.NOTEXIST); + + sensorRunInfoManager.setSensorActive(sensor); + + GasSensorEventEntity event = new GasSensorEventEntity(); + event.setDeviceid(sensor.getDeviceid()); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + event.setTimestamp(new Date()); + if(serviceId==100||serviceId==101) + { + JsonNode payload = JsonHelper.getLevel2(rootnode,"payload"); + if(payload==null) + return new RespEntity(RespCode.FAIL); + co = JsonHelper.getIntValue(payload,"SENSOR_VALUE"); + event.setCo(co); + event.setEvent("heartbeat"); + }else if(serviceId==1300) + { + JsonNode content = JsonHelper.getLevel2(rootnode,"eventContent"); + if(content==null) + return new RespEntity(RespCode.FAIL); + int state = JsonHelper.getIntValue(content,"ALARM_STATE"); + if(state==7) + { + event.setAlarmtype("gasleak"); + } + else if(state==0) + { + event.setAlarmtype("alarmease"); + } + event.setEvent("alarm"); + }else + return new RespEntity(RespCode.NOTEXIST); + + event.Insert(dataSource); + + GasSensorNotify notify = new GasSensorNotify(); + notify.setStation(sensor.getOwner()); + notify.setDeviceid(sensor.getDeviceid()); + notify.setTimestamp(event.getTimestamp()); + notify.setCo(event.getCo()); + notify.setEvent(event.getEvent()); + notify.setAlarmtype(event.getAlarmtype()); + notify.setDevicetype(sensor.getDevicetype()); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, notify.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(sensor.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + // if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + { + MessageToStation msg = new MessageToStation(); + msg.setMessage("gastest"); + msg.setData(json); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( sensor.getOwner(),str); + } + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + e.printStackTrace(); + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/aiipc/test/report") + public RespEntity testReport(HttpServletRequest request) { + try { + String xml = HttpTools.getBodyFromRequest(request); + JsonNode rootnode = JsonHelper.parseBodyLevel1(xml); + JsonNode node = JsonHelper.getLevel2(rootnode,"snapshot"); + String devname = JsonHelper.getStringValue(node,"cameraName"); + JsonNode events = JsonHelper.getLevel2(node,"events"); + if(events!=null&&events.size()>0) + { + for(int i=0;i 10) { + invade.setTimestamp(SQLTools.StrToDateTime(time)); + if (invade.getTimestamp() == null) { + invade.setTimestamp(new Date()); + } + } else { + invade.setTimestamp(new Date()); + } + String pic = JsonHelper.getStringValue(node, "base64Image"); + try { + String path = "./aiipc"; + File dir = new File(path); + if (!dir.exists()) { + dir.mkdir(); + } + path += "/" + devname; + dir = new File(path); + if (!dir.exists()) { + dir.mkdir(); + } + String filename = "invade_" + invade.getTimestamp().getTime() + ".jpg"; + path += "/" + filename; + try { + + byte[] buffer = java.util.Base64.getDecoder().decode(pic); + if (buffer != null && buffer.length > 0) { + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(new File(path))); + out.write(buffer, 0, buffer.length); + out.flush(); + out.close(); + invade.setPicture(filename); + } + + } catch (FileNotFoundException e) { + + } catch (IOException e) { + + } + } catch (Exception e) { + + } + + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, invade.getDeviceid()); + if (sensor != null) { + invade.setOwner(sensor.getOwner()); + invade.Insert(dataSource); + sensorRunInfoManager.setSensorActive(sensor); + AIIPCInvadeEventNotify notify = new AIIPCInvadeEventNotify(); + notify.setStation(sensor.getOwner()); + notify.setDeviceid(sensor.getDeviceid()); + notify.setPicture(invade.getPicture()); + notify.setTimestamp(invade.getTimestamp()); + notify.setConfidence(invade.getConfidence()); + notify.setType(invade.getType()); + + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, notify.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(sensor.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + break; + } + } + } + } + } + System.out.println("aiipc name:"+devname); + messagePublisher.sendMessage( devname,xml); + + if(xml!=null){ + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, devname); + if (sensor != null) { + sensorRunInfoManager.setSensorActive(sensor); + // if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + { + MessageToStation msg = new MessageToStation(); + msg.setMessage("testaiipc"); + msg.setData(xml); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( sensor.getOwner(),str); + } + } + } + + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/pushbutton/report") + public RespEntity pushButtonReport(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + sensorService.addPushButtonMessage(json); + // System.out.println("pushbutton: "+json); + logger.info("pushbutton receive: " + json); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, json, "/iotserver/sensor/pushbutton/report"); + } +/* + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + int serviceId = JsonHelper.getIntValue(rootnode,"serviceId"); + + if(serviceId==1300) + { + String dev_id = JsonHelper.getStringValue(rootnode,"IMEI"); + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, dev_id); + + JsonNode payload = JsonHelper.getLevel2(rootnode,"eventContent"); + if(payload==null) + return new RespEntity(RespCode.FAIL,new Date()); + int alarmstate = JsonHelper.getIntValue(payload,"ALARM_STATE"); + if (sensor != null) { + sensorRunInfoManager.setSensorActive(sensor); + + PushButtonEventEntity event = new PushButtonEventEntity(); + event.setDeviceid(sensor.getDeviceid()); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + event.setTimestamp(new Date()); + event.setReadstate("unread"); + if(alarmstate==6){ + event.setAlarmstate("press"); + if(sensor.getAlarm() != null){ + if(sensor.getAlarm().equalsIgnoreCase("open")){ + return new RespEntity(RespCode.SUCCESS,new Date()); + }else{ + sensor.setAlarm("open"); + sensorService.updateSensor(sensor); + } + } + } + else if(alarmstate==0) { + event.setAlarmstate("rid"); + if(sensor.getAlarm() != null){ + if(sensor.getAlarm().equalsIgnoreCase("close")){ + return new RespEntity(RespCode.SUCCESS,new Date()); + }else{ + sensor.setAlarm("close"); + sensorService.updateSensor(sensor); + } + } + } + + event.Insert(dataSource); + + PushButtonEventNotify notify = new PushButtonEventNotify(); + notify.setStation(sensor.getOwner()); + notify.setDeviceid(sensor.getDeviceid()); + notify.setTimestamp(event.getTimestamp()); + notify.setAlarmstate(event.getAlarmstate()); + notify.setDevicetype(sensor.getDevicetype()); + notify.setReadstate(event.getReadstate()); + + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, notify.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(sensor.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + // if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + { + MessageToStation msg = new MessageToStation(); + msg.setMessage("pushbutton"); + msg.setData(json); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(sensor.getOwner(),str); + // messagePublisher.sendMessage(from.topic(),str); + } + } + + } +*/ + + }catch (Exception e){ + e.printStackTrace(); + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS,new Date()); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/pushbutton/dahua") + public RespEntity pushButtonDahuaReport(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + System.out.println("pushbutton dahua data: " + json); + if(FireCtrlSystemInit.netMode == 1){ + // ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, json, "/iotserver/sensor/pushbutton/report"); + } + + JSONObject rootnode = JSON.parseObject(json); + int serviceId = rootnode.getIntValue("serviceId"); + + if(serviceId==1001) { + String dev_id = rootnode.getString("IMEI"); + System.out.println("pushbutton dahua data: " + dev_id); + PushAlarmPointEntity alarmPoint = new PushAlarmPointEntity(); + alarmPoint.setPointId(dev_id); + alarmPoint = (PushAlarmPointEntity)alarmPoint.QueryIt(dataSource); + if(alarmPoint == null){ + System.out.println("pushbutton dahua data no device"); + return new RespEntity(RespCode.NOTEXIST); + } + + JSONObject eventContent = rootnode.getJSONObject("eventContent"); + if(eventContent==null){ + System.out.println("pushbutton dahua data err 2"); + return new RespEntity(RespCode.FAIL,new Date()); + } + + try { + String dahuaPayload = eventContent.getString("payload"); + if(dahuaPayload == null){ + System.out.println("pushbutton dahua data err 3"); + return new RespEntity(RespCode.SUCCESS); + } + if(dahuaPayload.length() < 10){ + return new RespEntity(RespCode.SUCCESS); + } + String dahuaStart = dahuaPayload.substring(0,4); + System.out.println("pushbutton dahua start: " + dahuaStart); + if(!dahuaStart.equalsIgnoreCase("55AA")){ + return new RespEntity(RespCode.SUCCESS); + } + String dahuaAlarm = dahuaPayload.substring(6,8); + + System.out.println("pushbutton dahua alarm: " + dahuaAlarm); + int voltage = eventContent.getIntValue("voltage", 3000); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,dev_id); + if(dahuaAlarm.equalsIgnoreCase("01")){ + sensorService.addAlarmPointEvent(dev_id); + } + + if(sensor != null){ + sensor.setPower(voltage); + sensor.Update(dataSource); + } + } catch (Exception e){ + + } + + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS,new Date()); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/mucktruck/report") + public String mucktruckReport(HttpServletRequest request) { + try { + String json = HttpTools.getBodyFromRequest(request); + + System.out.println("mucktruck: " + json); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + String appkey = JsonHelper.getStringValue(rootnode,"appkey"); + String deviceid = JsonHelper.getStringValue(rootnode,"FenceName"); + + SensorDeviceEntity sensor = null; + sensor = SensorDeviceEntity.Query(dataSource, deviceid); + if(sensor==null){ + return "OK"; + } + + MuckTruckEventEntity event = new MuckTruckEventEntity(); + + event.setDeviceid(sensor.getDeviceid()); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + event.setTimestamp(new Date()); + event.setEvent("alarm"); + event.setStatus("unread"); + event.setEventname(JsonHelper.getStringValue(rootnode,"EventName")); + event.setCompanyname(JsonHelper.getStringValue(rootnode,"CompanyName")); + event.setPlatenumber(JsonHelper.getStringValue(rootnode,"PlateNumber")); + event.setFencetype(JsonHelper.getStringValue(rootnode,"FenceType")); + event.setBidarea(JsonHelper.getStringValue(rootnode,"BidArea")); + event.setGeoindata(SQLTools.StrToDateTime(JsonHelper.getStringValue(rootnode,"GeoInData"))); + event.setGeoinfencedata(SQLTools.StrToDateTime(JsonHelper.getStringValue(rootnode,"GeoInFenceData"))); + event.setGeooutfencedata(SQLTools.StrToDateTime(JsonHelper.getStringValue(rootnode,"GeoOutFenceData"))); + event.Insert(dataSource); + + MuckTruckEventNotify notify = new MuckTruckEventNotify(); + notify.setStation(sensor.getOwner()); + notify.setDeviceid(sensor.getDeviceid()); + notify.setTimestamp(event.getTimestamp()); + notify.setEvent(event.getEvent()); + notify.setDevicetype(sensor.getDevicetype()); + notify.setEventname(event.getEventname()); + notify.setCompanyname(event.getCompanyname()); + notify.setPlatenumber(event.getPlatenumber()); + notify.setFencetype(event.getFencetype()); + notify.setBidarea(event.getBidarea()); + notify.setGeoindata(event.getGeoindata()); + notify.setGeoinfencedata(event.getGeoinfencedata()); + notify.setGeooutfencedata(event.getGeooutfencedata()); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, notify.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(sensor.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + MessageToStation msg = new MessageToStation(); + msg.setMessage("mucktruckalarm"); + msg.setData(json); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( sensor.getOwner(),str); + + } catch (Exception e) { + + } + return "OK"; + } + + private static final String PUSH_BUTTON_SE = "gpioalarm1"; + private static final String PUSH_BUTTON_DATA_TYPE = "1"; + @ResponseBody + @RequestMapping(value="/iotserver/sensor/pushbutton2/report") + public RFIDResp newPushButtonEventReport(HttpServletRequest request) { + RFIDResp res = new RFIDResp(); + res.setCode(0); + res.setMsg("ok"); + try { + String pushButtonData = HttpTools.getBodyFromRequest(request); + + // System.out.println("pushbutton2: " + pushButtonData); + + JSONObject jsonData = JSON.parseObject(pushButtonData); + String seNo = jsonData.getString("seNo"); + String buNo = jsonData.getString("buNo"); + String deviceId = jsonData.getString("dvNo"); + + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, deviceId); + if (sensor == null) + return res; + + String type = jsonData.getString("type"); + JSONArray jDatas = jsonData.getJSONArray("datas"); + + if(!PUSH_BUTTON_SE.equalsIgnoreCase(seNo)){ + return res; + } + if(PUSH_BUTTON_DATA_TYPE.equalsIgnoreCase(type)){ + if(jDatas == null){ + return res; + } + + String sPower = "0", sSignal = "0", sAlarm = "0"; + for(int i = 0; i < jDatas.size(); i++){ + JSONObject jData = jDatas.getJSONObject(i); + if(jData.containsKey("power")){ + sPower = jData.getString("power"); + }else if(jData.containsKey("signal")){ + sSignal = jData.getString("signal"); + }else if(jData.containsKey("gpioalarm")){ + sAlarm = jData.getString("gpioalarm"); + } + } + int nPower = 0; + try { + nPower = Integer.parseInt(sPower); + }catch (Exception e){ + } + + sensor.setPower(nPower); + + PushButtonEventEntity event = new PushButtonEventEntity(); + event.setDeviceid(sensor.getDeviceid()); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + event.setTimestamp(new Date()); + event.setReadstate("unread"); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, sensor.getOwner()); + + // System.out.println("pushbutton2: alarm " + sAlarm); + if(sAlarm.equals("0")) { + //release + event.setAlarmstate("rid"); + if(sensor.getAlarm() != null){ + if(sensor.getAlarm().equalsIgnoreCase("close")){ + return res; + }else{ + sensor.setAlarm("close"); + sensorService.updateSensor(sensor); + } + } + }else if(sAlarm.equals("1")) { + //push + event.setAlarmstate("press"); + if(sensor.getAlarm() != null){ + if(sensor.getAlarm().equalsIgnoreCase("open")){ + return res; + }else{ + sensor.setAlarm("open"); + sensorService.updateSensor(sensor); + if (from != null) { + dataStatisticsService.addPushAlarmEvent(from); + } + } + } + } + sensorRunInfoManager.setSensorActive(sensor); + sensor.Update(dataSource); + event.Insert(dataSource); + + PushButtonEventNotify notify = new PushButtonEventNotify(); + notify.setStation(sensor.getOwner()); + notify.setDeviceid(sensor.getDeviceid()); + notify.setTimestamp(event.getTimestamp()); + notify.setAlarmstate(event.getAlarmstate()); + notify.setDevicetype(sensor.getDevicetype()); + notify.setReadstate(event.getReadstate()); + + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(sensor.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + MessageToStation msg = new MessageToStation(); + msg.setMessage("pushbuttonext"); + msg.setData(JsonHelper.convertObjectToStr(event)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(sensor.getOwner(),str); + messagePublisher.sendMessage(from.topic(),str); + + } + + + }catch (Exception e){ + // e.printStackTrace(); + res.setCode(20); + res.setMsg("fail"); + + } + + return res; + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/rfid/report") + public RFIDResp rfidEventReport(HttpServletRequest request) { + RFIDResp res = new RFIDResp(); + try { + String json = HttpTools.getBodyFromRequest(request); + + // System.out.println("rfid: " + json); + JsonNode rootnode = JsonHelper.parseBodyLevel1(json); + int testFlag = JsonHelper.getIntValue(rootnode,"testFlag"); + String key = JsonHelper.getStringValue(rootnode,"key"); + String contentstr = JsonHelper.getStringValue(rootnode,"content"); + + res.setCode(0); + res.setMsg("ok"); + if(testFlag>0) { + RFIDData data = new RFIDData(); + data.setTestFlag(testFlag); + res.setData(data); + }else { + int type = JsonHelper.getIntValue(rootnode,"type"); + if(type!=1) + return res; + JsonNode content = JsonHelper.parseBodyLevel1(contentstr); + if(content==null) + return res; + String seNo = JsonHelper.getStringValue(content,"seNo"); + if(seNo==null) + return res; + + String dvNo = JsonHelper.getStringValue(content,"dvNo"); + if(dvNo==null) + return res; + + if(seNo.equals("gpioalarm1")) { + convertRfidToPushButton(content); + return res; + } + + if(!seNo.equals("rfidebikelabel")) + return res; + + RfidStateEntity rfid = new RfidStateEntity(); + rfid.setRfid(dvNo); + RfidStateEntity reg = (RfidStateEntity)rfid.QueryIt(dataSource); + if(reg==null) + return res; + JsonNode datas = JsonHelper.getLevel2(content,"datas"); + if(!datas.isArray()||datas.size()<=0) + return res; + + RfidEventEntity event = new RfidEventEntity(); + event.setDeviceid(dvNo); + event.setOwner(reg.getOwner()); + event.setCommunity(reg.getCommunity()); + for(int i=0;i yinshiReport(HttpServletRequest request) { + try { + String ysData = HttpTools.getBodyFromRequest(request); + + // System.out.println("yinshi: event " + ysData); + + JSONObject jsonObject = JSON.parseObject(ysData); + if(!jsonObject.containsKey("header")){ + return ResponseEntity.ok(""); + } + + YsHeader jsHeader = jsonObject.getObject("header", YsHeader.class); + if(jsHeader == null){ + return ResponseEntity.ok(""); + } + if(jsHeader.getMessageId() == null){ + return ResponseEntity.ok(""); + } + //必须进行返回 + Map result = new HashMap<>(1); + String messageId = jsHeader.getMessageId(); + result.put("messageId", messageId); + ResponseEntity resp = ResponseEntity.ok(JSON.toJSONString(result)); + + System.out.println("yinshi: event " + jsHeader.getDeviceId()); + YsIPCEntity ysIPC = new YsIPCEntity(); + ysIPC.setDeviceId(jsHeader.getDeviceId()); + YsIPCEntity ipcInData = (YsIPCEntity)ysIPC.QueryIt(dataSource); + if(ipcInData == null){ + return resp; + } + try { + if(!jsHeader.getType().equalsIgnoreCase("ys.alarm")){ + return resp; + } + YsAlarmBody jsBody = jsonObject.getObject("body", YsAlarmBody.class); + if(jsBody == null){ + return resp; + } + + // System.out.println("yinshi: event " + jsBody.getAlarmId()); + YsAlarmEntity newAlarm = new YsAlarmEntity(jsHeader, jsBody); + newAlarm.setStation(ipcInData.getStation()); + newAlarm.setBrigade(ipcInData.getBrigade()); + newAlarm.setBorough(ipcInData.getBorough()); + newAlarm.setDetachment(ipcInData.getDetachment()); + newAlarm.setAddress(ipcInData.getAddress()); + newAlarm.setLatitude(ipcInData.getLatitude()); + newAlarm.setLongitude(ipcInData.getLongitude()); + + ipcInData.setPictureUrl(newAlarm.getPictureUrl()); + ipcInData.setPictureTime(new Date()); + ipcInData.Update(dataSource); + + if(newAlarm.QueryIt(dataSource) == null){ + newAlarm.Insert(dataSource); + } + + YsAlarmCutoutEntity newCutout = new YsAlarmCutoutEntity(newAlarm, ysIPC); + YsAlarmCutoutEntity oldCutout = (YsAlarmCutoutEntity)newCutout.QueryIt(dataSource); + if(oldCutout == null){ + newCutout.Insert(dataSource); + }else{ + newCutout.Update(dataSource); + } + + YsAlarmNotify eventNotify = new YsAlarmNotify(newAlarm); + + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, newAlarm.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(eventNotify.getDeviceId()); + pro.setDevice_type("ys"); + eventNotify.attachProperty(pro); + clientWebsocketManager.addWebNotify(eventNotify); + } + + }catch (Exception e){ + } + return resp; + } catch (Exception e) { + + } + + Map result = new HashMap<>(1); + result.put("messageId", ""); + return ResponseEntity.ok(JSON.toJSONString(result)); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/pushbutton/de_shang_an") + public RespEntity addDeShangAnAlarm(HttpServletRequest request) { + try { + String bodyStr = HttpTools.getBodyFromRequest(request); + System.out.println("addDeShangAnAlarm: " + bodyStr); + DeShangAnData shangAnData = JSON.parseObject(bodyStr, DeShangAnData.class); + if(shangAnData == null){ + new RespEntity(RespCode.ERROR_REQUEST); + } + if(shangAnData.getAccount() == null || shangAnData.getDefenceAreaNumber() == null){ + new RespEntity(RespCode.ERROR_REQUEST); + } + + PushAlarmPointEntity alarmPoint = new PushAlarmPointEntity(); + alarmPoint.setPointId(shangAnData.getAccount() + "_" + shangAnData.getDefenceAreaNumber()); + + alarmPoint = (PushAlarmPointEntity)alarmPoint.QueryIt(dataSource); + if(alarmPoint == null){ + return new RespEntity(RespCode.NOTEXIST); + } + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date timestamp = null; + if(shangAnData.getTime() == null){ + timestamp = new Date(); + }else{ + try { + timestamp = format.parse(shangAnData.getTime()); + } catch (Exception e) { + timestamp = new Date(); + } + } + + String eventId = alarmPoint.getPointId() + "_" + timestamp.getTime(); + + SensorAlarmEventEntity alarmEvent = new SensorAlarmEventEntity(); + alarmEvent.setEventId(eventId); + alarmEvent.setDeviceId(alarmPoint.getPointId()); + alarmEvent.setDevicetype(alarmPoint.getDeviceType()); + alarmEvent.setAlarmSource(alarmPoint.getDwmc()); + alarmEvent.setAddress(alarmPoint.getDwdz()); + alarmEvent.setLatitude(alarmPoint.getLatitude()); + alarmEvent.setLongitude(alarmPoint.getLongitude()); + alarmEvent.setSubAddress(alarmPoint.getPointAddress()); + alarmEvent.setStation(alarmPoint.getStation()); + alarmEvent.setDetachment(alarmPoint.getDetachment()); + alarmEvent.setBorough(alarmPoint.getBorough()); + alarmEvent.setBrigade(alarmPoint.getBrigade()); + alarmEvent.setTimestamp(timestamp); + alarmEvent.setAlarmType(SensorAlarmEventEntity.Alarm_Type_SOS_PushBotton); + alarmEvent.setAlarmCode("一键报警"); + alarmEvent.setState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setReadState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setEventData(""); + alarmEvent.setAlarmTarget(alarmPoint.getPointName()); + + SensorAlarmEventEntity oldEvent = (SensorAlarmEventEntity)alarmEvent.QueryIt(dataSource); + if(oldEvent != null){ + return new RespEntity(RespCode.EXIST); + } + alarmEvent.Insert(dataSource); + + alarmEvent.setUser1Name(alarmPoint.getUserName()); + alarmEvent.setUser2Name(alarmPoint.getUser2Name()); + alarmEvent.setUser3Name(alarmPoint.getUser3Name()); + alarmEvent.setUser1Phone(alarmPoint.getUserPhone()); + alarmEvent.setUser2Phone(alarmPoint.getUser2Phone()); + alarmEvent.setUser3Phone(alarmPoint.getUser3Phone()); + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmPoint.getBrigade()); + pro.setBorough(alarmPoint.getBorough()); + pro.setDetachment(alarmPoint.getDetachment()); + pro.setStation(alarmPoint.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmPoint.getDeviceType()); + notify.attachProperty(pro); + // System.out.println("websocket send sensor event 一键报警: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + if(FireCtrlSystemInit.netMode == 1){ + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmPoint.getStation(),str); + } + } catch (Exception e) { + new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/voice/alarm") + public RespEntity addVoiceAlarm(HttpServletRequest request) { + try { + String bodyStr = HttpTools.getBodyFromRequest(request); + System.out.println("addVoiceAlarm: " + bodyStr); +/* + SensorAlarmEventEntity alarmEvent = JSON.parseObject(bodyStr, SensorAlarmEventEntity.class); + + Date ts = new Date(); + alarmEvent.setAlarmType(SensorAlarmEventEntity.Alarm_Type_SOS_MDEV); + alarmEvent.setAlarmCode("移动报警"); + alarmEvent.setTimestamp(ts); + alarmEvent.setReadState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setDevicetype("mdev"); + SensorAlarmEventEntity oldEvent = (SensorAlarmEventEntity)alarmEvent.QueryIt(dataSource); + if(oldEvent != null){ + return new RespEntity(RespCode.EXIST); + } + alarmEvent.Insert(dataSource); + + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(ts); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmEvent.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmEvent.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(0); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(1); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = alarmSummaryDB.getMdevCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setMdevCount(1+oldMDevCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmEvent.getBrigade()); + pro.setBorough(alarmEvent.getBorough()); + pro.setDetachment(alarmEvent.getDetachment()); + pro.setStation(alarmEvent.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmEvent.getDevicetype()); + notify.attachProperty(pro); + // System.out.println("websocket send sensor event 一键报警: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + if(FireCtrlSystemInit.netMode == 1){ + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmEvent.getStation(),str); + } +*/ + + } catch (Exception e) { + new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/mdev/alarm") + public RespEntity addMDevAlarm(HttpServletRequest request) { + try { + String bodyStr = HttpTools.getBodyFromRequest(request); + System.out.println("addMDevAlarm: " + bodyStr); + + SensorAlarmEventEntity alarmEvent = JSON.parseObject(bodyStr, SensorAlarmEventEntity.class); + + Date ts = new Date(); + alarmEvent.setAlarmType(SensorAlarmEventEntity.Alarm_Type_SOS_MDEV); + alarmEvent.setAlarmCode("移动报警"); + alarmEvent.setTimestamp(ts); + alarmEvent.setReadState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setDevicetype("mdev"); + SensorAlarmEventEntity oldEvent = (SensorAlarmEventEntity)alarmEvent.QueryIt(dataSource); + if(oldEvent != null){ + return new RespEntity(RespCode.EXIST); + } + alarmEvent.Insert(dataSource); + + /* + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(ts); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmEvent.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmEvent.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(0); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(1); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = alarmSummaryDB.getMdevCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setMdevCount(1+oldMDevCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + */ + addNewMDevAlarmEventSummary(alarmEvent); + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmEvent.getBrigade()); + pro.setBorough(alarmEvent.getBorough()); + pro.setDetachment(alarmEvent.getDetachment()); + pro.setStation(alarmEvent.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmEvent.getDevicetype()); + notify.attachProperty(pro); + // System.out.println("websocket send sensor event 一键报警: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + if(FireCtrlSystemInit.netMode == 1){ + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("mdev_alarm"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmEvent.getStation(),str); + } + + + } catch (Exception e) { + new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } + + private void addNewMDevAlarmEventSummary(SensorAlarmEventEntity alarmEvent){ + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(alarmEvent.getTimestamp()); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmEvent.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmEvent.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(0); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(1); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = alarmSummaryDB.getMdevCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setMdevCount(1+oldMDevCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + SensorAlarmSummaryEntity boroughSummary = new SensorAlarmSummaryEntity(); + boroughSummary.setRecordId(alarmEvent.getBorough() + "-" + strDay); + SensorAlarmSummaryEntity boroughSummaryDB = (SensorAlarmSummaryEntity)boroughSummary.QueryIt(dataSource); + if(boroughSummaryDB == null){ + boroughSummaryDB = new SensorAlarmSummaryEntity(); + boroughSummaryDB.setRecordId(alarmSummary.getRecordId()); + boroughSummaryDB.setBrigade(alarmEvent.getBorough()); + boroughSummaryDB.setYear(strY); + boroughSummaryDB.setMonth(strM); + boroughSummaryDB.setWeek(strWeek); + boroughSummaryDB.setDay(strD); + boroughSummaryDB.setPushCount(0); + boroughSummaryDB.setAlarmTotal(1); + boroughSummaryDB.setAiCount(0); + boroughSummaryDB.setSkynetCount(0); + boroughSummaryDB.setMdevCount(1); + boroughSummaryDB.setTimestamp(new Date()); + boroughSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = boroughSummaryDB.getMdevCount(); + int oldTotalCount = boroughSummaryDB.getAlarmTotal(); + boroughSummaryDB.setMdevCount(1+oldMDevCount); + boroughSummaryDB.setAlarmTotal(1+oldTotalCount); + boroughSummaryDB.Update(dataSource); + } + + SensorAlarmSummaryEntity detachmentSummary = new SensorAlarmSummaryEntity(); + detachmentSummary.setRecordId(alarmEvent.getDetachment() + "-" + strDay); + SensorAlarmSummaryEntity detachmentSummaryDB = (SensorAlarmSummaryEntity)detachmentSummary.QueryIt(dataSource); + if(detachmentSummaryDB == null){ + detachmentSummaryDB = new SensorAlarmSummaryEntity(); + detachmentSummaryDB.setRecordId(alarmSummary.getRecordId()); + detachmentSummaryDB.setBrigade(alarmEvent.getDetachment()); + detachmentSummaryDB.setYear(strY); + detachmentSummaryDB.setMonth(strM); + detachmentSummaryDB.setWeek(strWeek); + detachmentSummaryDB.setDay(strD); + detachmentSummaryDB.setPushCount(0); + detachmentSummaryDB.setAlarmTotal(1); + detachmentSummaryDB.setAiCount(0); + detachmentSummaryDB.setSkynetCount(0); + detachmentSummaryDB.setMdevCount(1); + detachmentSummaryDB.setTimestamp(new Date()); + detachmentSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = detachmentSummaryDB.getMdevCount(); + int oldTotalCount = detachmentSummaryDB.getAlarmTotal(); + detachmentSummaryDB.setMdevCount(1+oldMDevCount); + detachmentSummaryDB.setAlarmTotal(1+oldTotalCount); + detachmentSummaryDB.Update(dataSource); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/color/build") + public RespEntity onSensorColorBuild(HttpServletRequest request) { + try { + // String json = HttpTools.getBodyFromRequest(request); + // System.out.println("legacybutton: " + json); + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SchoolColorDetailEntity colorDetail = (SchoolColorDetailEntity) SQLTools.getEntityFromJson(rootnode, SchoolColorDetailEntity.class); + + //colorDetail.setSchoolTime("2022年上半年"); + if(colorDetail == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(colorDetail.getSchoolTime() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + List list = colorDetail.queryPage(dataSource, null, null, 0, 1000); + if(list == null){ + return new RespEntity(RespCode.SUCCESS); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS); + } + System.out.println("legacybutton: " + schoolSize); + for(int iSchool = 0; iSchool < schoolSize; iSchool++) { + SchoolColorDetailEntity starDetail = (SchoolColorDetailEntity) list.get(iSchool); + FireStationBaseInfoEntity stationBaseInfo = FireStationBaseInfoEntity.Query(dataSource, starDetail.getStation()); + if (stationBaseInfo != null){ + //starDetail.setSchoolTime("2023年上半年"); + + starDetail.calcScore(); + + SchoolColorRatingEntity ratingEntity = new SchoolColorRatingEntity(); + ratingEntity.setBrigade(starDetail.getBrigade()); + ratingEntity.setBorough(starDetail.getBorough()); + ratingEntity.setDetachment(starDetail.getDetachment()); + ratingEntity.setStation(starDetail.getStation()); + ratingEntity.setTimestamp(starDetail.getTimestamp()); + ratingEntity.setScoreCase(starDetail.getScoreCase()); + ratingEntity.setScoreDesire(starDetail.getScoreDesire()); + ratingEntity.setScoreDevices(starDetail.getScoreDevices()); + ratingEntity.setScoreHuman(starDetail.getScoreHuman()); + ratingEntity.setScoreScheme(starDetail.getScoreScheme()); + ratingEntity.setScoreTech(starDetail.getScoreTech()); + ratingEntity.setScoreTotal(starDetail.getScoreTotal()); + ratingEntity.setSchoolTime(starDetail.getSchoolTime()); + + // ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_ColorDetail, JSON.toJSONString(starDetail), "/iotserver/school/color_detail/add"); + // ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_StarDetail, JSON.toJSONString(starDetail), "/iotserver/school/star_detail/add"); + + SchoolColorRatingEntity oldRating = (SchoolColorRatingEntity)ratingEntity.QueryIt(dataSource); + if(oldRating==null){ + if (!ratingEntity.Insert(dataSource)) { + } + }else{ + if (!ratingEntity.Update(dataSource)) { + } + } + + }else{ + System.out.println("legacybutton: " + starDetail.getStation()); + } + } + + } catch (Exception e) { + new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/star/build") + public RespEntity onSensorStarBuild(HttpServletRequest request) { + try { + // String json = HttpTools.getBodyFromRequest(request); + // System.out.println("legacybutton: " + json); + + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SchoolStarDetailEntity colorDetail = (SchoolStarDetailEntity) SQLTools.getEntityFromJson(rootnode, SchoolStarDetailEntity.class); + //colorDetail.setSchoolTime("2022年上半年"); + if(colorDetail == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(colorDetail.getSchoolTime() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + List list = colorDetail.queryPage(dataSource, null, null, 0, 1000); + if(list == null){ + return new RespEntity(RespCode.SUCCESS); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS); + } + System.out.println("legacybutton: " + schoolSize); + for(int iSchool = 0; iSchool < schoolSize; iSchool++) { + SchoolStarDetailEntity starDetail = (SchoolStarDetailEntity) list.get(iSchool); + FireStationBaseInfoEntity stationBaseInfo = FireStationBaseInfoEntity.Query(dataSource, starDetail.getStation()); + if (stationBaseInfo != null){ + //starDetail.setSchoolTime("2023年上半年"); + + starDetail.calcScore(); + + SchoolStarRatingEntity ratingEntity = new SchoolStarRatingEntity(); + ratingEntity.setBrigade(starDetail.getBrigade()); + ratingEntity.setBorough(starDetail.getBorough()); + ratingEntity.setDetachment(starDetail.getDetachment()); + ratingEntity.setStation(starDetail.getStation()); + ratingEntity.setTimestamp(starDetail.getTimestamp()); + ratingEntity.setScoreBonus(starDetail.getScoreBonus()); + ratingEntity.setScoreEmcManage(starDetail.getScoreEmcManage()); + ratingEntity.setScoreInsideManage(starDetail.getScoreInsideManage()); + ratingEntity.setScoreOutsideManage(starDetail.getScoreOutsideManage()); + ratingEntity.setScoreRiskManage(starDetail.getScoreRiskManage()); + ratingEntity.setScoreLawEducation(starDetail.getScoreLawEducation()); + ratingEntity.setScoreTotal(starDetail.getScoreTotal()); + ratingEntity.setSchoolTime(starDetail.getSchoolTime()); + + // ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_ColorDetail, JSON.toJSONString(starDetail), "/iotserver/school/color_detail/add"); + // ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_StarDetail, JSON.toJSONString(starDetail), "/iotserver/school/star_detail/add"); + + SchoolStarRatingEntity oldRating = (SchoolStarRatingEntity)ratingEntity.QueryIt(dataSource); + if(oldRating==null){ + if (!ratingEntity.Insert(dataSource)) { + } + }else{ + if (!ratingEntity.Update(dataSource)) { + } + } + + }else{ + System.out.println("legacybutton: " + starDetail.getStation()); + } + } + + } catch (Exception e) { + new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } + + + + + private static final String DATA_TYPE = "1"; + @ResponseBody + @RequestMapping(value="/iotserver/sensor/water/report") + public RFIDResp newYimuWaterReport(HttpServletRequest request) { + RFIDResp res = new RFIDResp(); + res.setCode(0); + res.setMsg("ok"); + try { + String pushButtonData = HttpTools.getBodyFromRequest(request); + + if(pushButtonData == null){ + return res; + } + if(!pushButtonData.contains("timestamp")){ + return res; + } + // System.out.println("YimuWater: " + pushButtonData); + + JSONObject jsonData = JSON.parseObject(pushButtonData); + String seNo = jsonData.getString("seNo"); + String buNo = jsonData.getString("buNo"); + String deviceId = jsonData.getString("dvNo"); + + if(seNo == null){ + return res; + } + if(!seNo.equalsIgnoreCase("watercheck2")){ + return res; + } + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, deviceId); + if (sensor == null) { + return res; + } + + String type = jsonData.getString("type"); + JSONArray jDatas = jsonData.getJSONArray("datas"); + + if(PUSH_BUTTON_DATA_TYPE.equalsIgnoreCase(type)){ + if(jDatas == null){ + return res; + } + sensorRunInfoManager.setSensorActive(sensor); + try { + sensor.setStatus("normal"); + sensor.setActivetime(new Date()); + sensor.setLineState("online"); + sensor.Update(dataSource); + } + catch (Exception e){ + } + + WaterCheckDataEntity checkDataEntity = new WaterCheckDataEntity(); + checkDataEntity.setRecordId(UUID.randomUUID().toString()); + checkDataEntity.setDeviceid(deviceId); + checkDataEntity.setOwner(sensor.getOwner()); + checkDataEntity.setCheckTimestamp(new Date()); + checkDataEntity.setBuNo(buNo); + + for(int i = 0; i < jDatas.size(); i++){ + JSONObject jData = jDatas.getJSONObject(i); + try { + String itemValue="0"; + if(jData.containsKey("orgtimestamp")){ + itemValue = jData.getString("orgtimestamp"); + checkDataEntity.setOrgTimestamp(itemValue); + }else if(jData.containsKey("temp")){ + itemValue = jData.getString("temp"); + checkDataEntity.setTemp(Double.parseDouble(itemValue)); + }else if(jData.containsKey("tds")){ + itemValue = jData.getString("tds"); + checkDataEntity.setTds(Double.parseDouble(itemValue)); + } else if(jData.containsKey("orgtoc")){ + itemValue = jData.getString("orgtoc"); + checkDataEntity.setOrgtoc(Double.parseDouble(itemValue)); + }else if(jData.containsKey("orgcod")){ + itemValue = jData.getString("orgcod"); + checkDataEntity.setOrgcod(Double.parseDouble(itemValue)); + }else if(jData.containsKey("toc")){ + itemValue = jData.getString("toc"); + checkDataEntity.setToc(Double.parseDouble(itemValue)); + }else if(jData.containsKey("cod")){ + itemValue = jData.getString("cod"); + checkDataEntity.setCod(Double.parseDouble(itemValue)); + }else if(jData.containsKey("checkstatus")){ + itemValue = jData.getString("checkstatus"); + checkDataEntity.setCheckstatus(itemValue); + }else if(jData.containsKey("timestamp")){ + itemValue = jData.getString("timestamp"); + checkDataEntity.setTimestamp(itemValue); + }else if(jData.containsKey("orgtds")){ + itemValue = jData.getString("orgtds"); + checkDataEntity.setOrgtds(Double.parseDouble(itemValue)); + } + }catch (Exception e){ + } + } + checkDataEntity.Insert(dataSource); + + } + }catch (Exception e){ + res.setCode(20); + res.setMsg("fail"); + } + return res; + } + + @ResponseBody + @RequestMapping(value="/iotserver/sensor/freshair/report") + public RFIDResp newAirReport(HttpServletRequest request) { + RFIDResp res = new RFIDResp(); + res.setCode(0); + res.setMsg("ok"); + try { + String pushButtonData = HttpTools.getBodyFromRequest(request); + + // System.out.println("freshair data: " + pushButtonData); + + JSONObject jsonData = JSON.parseObject(pushButtonData); + String seNo = jsonData.getString("seNo"); + String buNo = jsonData.getString("buNo"); + String deviceId = jsonData.getString("dvNo"); + + if(seNo == null){ + return res; + } + if(!seNo.equalsIgnoreCase("gasjy14")){ + return res; + } + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, deviceId); + if (sensor == null) + return res; + + String type = jsonData.getString("type"); + JSONArray jDatas = jsonData.getJSONArray("datas"); + + if(PUSH_BUTTON_DATA_TYPE.equalsIgnoreCase(type)){ + if(jDatas == null){ + return res; + } + + GasSensorEventEntity newGasData = new GasSensorEventEntity(); + newGasData.setDeviceid(deviceId); + newGasData.setOwner(sensor.getOwner()); + newGasData.setTimestamp(new Date()); + newGasData.setDevicetype(sensor.getDevicetype()); + newGasData.setStatus(""); + newGasData.setAlarmtype(""); + for(int i = 0; i < jDatas.size(); i++){ + JSONObject jData = jDatas.getJSONObject(i); + try { + String itemValue="0"; + if(jData.containsKey("power")){ + itemValue = jData.getString("power"); + newGasData.setPower(Integer.parseInt(itemValue)); + }else if(jData.containsKey("tvoc")){ + itemValue = jData.getString("tvoc"); + newGasData.setTvoc(Double.parseDouble(itemValue)); + }else if(jData.containsKey("co2")){ + itemValue = jData.getString("co2"); + newGasData.setCo2(Double.parseDouble(itemValue)); + } else if(jData.containsKey("temperature")){ + itemValue = jData.getString("temperature"); + newGasData.setTemperature(Double.parseDouble(itemValue)); + }else if(jData.containsKey("pm10")){ + itemValue = jData.getString("pm10"); + newGasData.setPm10(Double.parseDouble(itemValue)); + }else if(jData.containsKey("humidity")){ + itemValue = jData.getString("humidity"); + newGasData.setHumidity(Double.parseDouble(itemValue)); + }else if(jData.containsKey("pm2d5")){ + itemValue = jData.getString("pm2d5"); + newGasData.setPm2d5(Double.parseDouble(itemValue)); + }else if(jData.containsKey("pm1d0")){ + itemValue = jData.getString("pm1d0"); + newGasData.setPm1d0(Double.parseDouble(itemValue)); + }else if(jData.containsKey("ch2o")){ + itemValue = jData.getString("ch2o"); + newGasData.setCh2o(Double.parseDouble(itemValue)); + } + }catch (Exception e){ + } + } + newGasData.setStatus("heartbeat"); + // newGasData.Insert(dataSource); + + List events = new ArrayList<>(); + events.add(newGasData); + sensorService.processGasEvent(events); + } + }catch (Exception e){ + res.setCode(20); + res.setMsg("fail"); + } + return res; + } + + + + + +} + + diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/IotSensorDataController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/IotSensorDataController.java new file mode 100644 index 0000000..ef3b228 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/IotSensorDataController.java @@ -0,0 +1,362 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.school.StudentVipEntity; +import com.jingyi.iotserver.firestationport.model.sensor.GasSensorEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.WaterCheckDataEntity; +import com.jingyi.iotserver.firestationport.model.sensor.WaterCheckReportEntity; +import com.jingyi.iotserver.firestationport.model.sensor.gas.DataDescriptionEntity; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.List; + +@RestController +@CrossOrigin +public class IotSensorDataController { + @Autowired + private DataSource dataSource; + + @Autowired + private SensorService sensorService; + + @ResponseBody + @RequestMapping(value="/iot/sensor/data/desc/list",method = RequestMethod.POST) + public RespEntity getSensorDataDesc(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + DataDescriptionEntity sensorDesc = (DataDescriptionEntity) SQLTools.getEntityFromJson(rootnode,DataDescriptionEntity.class); + if(sensorDesc == null){ + sensorDesc = new DataDescriptionEntity(); + } + + List dataList = sensorDesc.queryPage(dataSource,null,null,0, 1000); + return new RespEntity(RespCode.SUCCESS,dataList); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/data/desc/add",method = RequestMethod.POST) + public RespEntity addSensorDataDesc(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + DataDescriptionEntity sensorDesc = (DataDescriptionEntity) SQLTools.getEntityFromJson(rootnode,DataDescriptionEntity.class); + if(sensorDesc == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sensorDesc.getName() == null || sensorDesc.getType() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sensorDesc.QueryIt(dataSource) != null){ + return new RespEntity(RespCode.EXIST); + } + if(sensorDesc.Insert(dataSource)){ + return new RespEntity(RespCode.SUCCESS); + }else{ + return new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/count",method = RequestMethod.POST) + public RespEntity getSensorCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorDeviceEntity sensor = (SensorDeviceEntity) SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + int count = sensorService.querySensorCount(sensor); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/list",method = RequestMethod.POST) + public RespEntity getSensorPage(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + SensorDeviceEntity sensor = (SensorDeviceEntity)SQLTools.getEntityFromJson(rootnode,SensorDeviceEntity.class); + List list = sensorService.querySensorPage(pagesize,pageindex,sensor); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/water/getinfo/qrcode",method = RequestMethod.POST) + public RespEntity getSensorWithQicode(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String qrcode = JsonHelper.getStringValue(rootnode,"qrcode"); + + SensorDeviceEntity sensor = SensorDeviceEntity.QueryQrcode(dataSource,qrcode); + + return new RespEntity(RespCode.SUCCESS,sensor); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/clean_water/last",method = RequestMethod.POST) + public RespEntity getWaterDeviceLastData(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + WaterCheckDataEntity sensorData = (WaterCheckDataEntity)SQLTools.getEntityFromJson(rootnode,WaterCheckDataEntity.class); + if(sensorData == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sensorData.getDeviceid() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + WaterCheckDataEntity lastData = (WaterCheckDataEntity)sensorData.QueryLast(dataSource); + if(lastData == null){ + lastData = new WaterCheckDataEntity(); + } + return new RespEntity(RespCode.SUCCESS,lastData); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/clean_water/data_list",method = RequestMethod.POST) + public RespEntity getWaterDeviceDataList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + WaterCheckDataEntity sensorData = (WaterCheckDataEntity)SQLTools.getEntityFromJson(rootnode,WaterCheckDataEntity.class); + if(sensorData == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sensorData.getDeviceid() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + List dataList = sensorData.queryPage(dataSource,startstr,endstr,pageindex, pagesize); + if(dataList == null){ + dataList = new ArrayList<>(); + } + return new RespEntity(RespCode.SUCCESS, dataList); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/air/last",method = RequestMethod.POST) + public RespEntity getGasDeviceLastData(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + GasSensorEventEntity sensorData = (GasSensorEventEntity)SQLTools.getEntityFromJson(rootnode,GasSensorEventEntity.class); + if(sensorData == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sensorData.getDeviceid() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + GasSensorEventEntity lastData = (GasSensorEventEntity)sensorData.QueryLast(dataSource); + if(lastData == null){ + lastData = new GasSensorEventEntity(); + } + return new RespEntity(RespCode.SUCCESS,lastData); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/air/data_list",method = RequestMethod.POST) + public RespEntity getGasDeviceDataList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + GasSensorEventEntity sensorData = (GasSensorEventEntity)SQLTools.getEntityFromJson(rootnode,GasSensorEventEntity.class); + if(sensorData == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(sensorData.getDeviceid() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + List dataList = sensorData.queryPage(dataSource,startstr,endstr,pageindex, pagesize); + if(dataList == null){ + dataList = new ArrayList<>(); + } + return new RespEntity(RespCode.SUCCESS, dataList); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + + @ResponseBody + @RequestMapping(value="/iot/sensor/clean_water/fly/getlist",method = RequestMethod.POST) + public RespEntity getStudentList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + WaterCheckReportEntity waterCheckReport = (WaterCheckReportEntity)SQLTools.getEntityFromJson(rootnode,WaterCheckReportEntity.class); + + if(waterCheckReport==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(waterCheckReport.getBrigade()==null && waterCheckReport.getBorough()==null && waterCheckReport.getDetachment()==null && waterCheckReport.getOwner()==null && waterCheckReport.getTargetDeviceid()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = waterCheckReport.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/clean_water/fly/add",method = RequestMethod.POST) + public RespEntity addStudentInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + WaterCheckReportEntity waterCheckReport = (WaterCheckReportEntity) SQLTools.getEntityFromJson(rootnode, WaterCheckReportEntity.class); + if (waterCheckReport == null) + return new RespEntity(RespCode.ERROR_CMD); + if (waterCheckReport.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(waterCheckReport.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + + if (waterCheckReport.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/iot/sensor/clean_water/fly/delete",method = RequestMethod.POST) + public RespEntity deleteStudentInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + WaterCheckReportEntity waterCheckReport = (WaterCheckReportEntity) SQLTools.getEntityFromJson(rootnode, WaterCheckReportEntity.class); + if (waterCheckReport == null) + return new RespEntity(RespCode.ERROR_CMD); + if (waterCheckReport.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(waterCheckReport.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (waterCheckReport.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/MultiAlarmPlatformController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/MultiAlarmPlatformController.java new file mode 100644 index 0000000..2c51f16 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/MultiAlarmPlatformController.java @@ -0,0 +1,84 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.multiPlatform.MultiAlarmPoint; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.util.ArrayList; +import java.util.List; + +@RestController +@CrossOrigin +public class MultiAlarmPlatformController { + @Autowired + private DataSource dataSource; + + + @ResponseBody + @RequestMapping(value="/firectrl/platform/alarm_point/sync",method = RequestMethod.POST) + public RespEntity getPushAlarmPointList(HttpServletRequest request) { + RespEntity rel = null; + try { + PushAlarmPointEntity alarmPointEntity = new PushAlarmPointEntity(); + List list = alarmPointEntity.queryPage(dataSource, null, null, 0, 100000); + + if(list == null || list.isEmpty()){ + return new RespEntity(RespCode.SUCCESS); + } + List multiAlarmPointList = new ArrayList<>(); + for(int iP = 0; iP < list.size(); iP++){ + PushAlarmPointEntity alarmPoint = (PushAlarmPointEntity)list.get(iP); + MultiAlarmPoint tmpPoint = MultiAlarmPoint.copyFromPushPoint(alarmPoint); + multiAlarmPointList.add(tmpPoint); + } + + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://175.6.124.250:8082/multialarm/alarm_points/sync" ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("platKey", "LS0001"); + connLogin.setRequestProperty("platToken", "LS0001"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(JSON.toJSONString(multiAlarmPointList)); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("alarm_point sync: fail = " + responseCode); + }else{ + System.out.println("alarm_point sync: ok = " + responseCode); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("alarm_point sync: fail = " + e.getMessage()); + }finally { + + } + + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/ProcessAlarmTaskController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/ProcessAlarmTaskController.java new file mode 100644 index 0000000..75a2cd2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/ProcessAlarmTaskController.java @@ -0,0 +1,388 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.AlarmTaskNewResult; +import com.jingyi.iotserver.firestationport.model.sensor.event.ProcessAlarmEventOpRecord; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.station.ProcessAlarmTaskEntity; +import com.jingyi.iotserver.firestationport.model.station.ProcessAlarmTaskOpRecord; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.*; +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class ProcessAlarmTaskController { + @Autowired + private DataSource dataSource; + @Autowired + private SensorService sensorService; + + @Autowired + private StationServices stationServices; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + EnvConfigService envConfigService; + + @Autowired + private MessagePublisher messagePublisher; + + private final Logger logger = LoggerFactory.getLogger(ProcessAlarmTaskController.class); + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/add",method = RequestMethod.POST) + public RespEntity createAlarmTask(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = (ProcessAlarmTaskEntity) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskEntity.class); + JsonNode opnode = JsonHelper.getLevel2(rootnode,"operator"); + + if(task==null||task.getReceiver()==null||task.getRelatealarmid()==null||opnode==null) + return new RespEntity(RespCode.ERROR_REQUEST); + String [] rvcs = task.getReceiver().split("##"); + if(rvcs==null||rvcs.length<=0||rvcs[0].length()<=0) + return new RespEntity(RespCode.ERROR_REQUEST); + ArrayList results = new ArrayList(); + for(int i=0;i 10) { + return new RespEntity(RespCode.FAIL); + } + try { + Thread.sleep(10); + count++; + } catch (Exception e) { + + } + task.setTaskid(GUIDUtil.GeneralAppkey()); + } + if (!task.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + ProcessAlarmTaskOpRecord op = (ProcessAlarmTaskOpRecord) SQLTools.getEntityFromJson(opnode, ProcessAlarmTaskOpRecord.class); + if (op != null) { + op.setOperation("create"); + op.setTaskid(task.getTaskid()); + op.setRelatealarmid(task.getRelatealarmid()); + op.setTimestamp(new Date()); + op.setReceiver(task.getReceiver()); + try { + op.setResult(Base64.encodeBase64String(rootnode.toString().getBytes("UTF8"))); + }catch (Exception e){ + + } + op.Insert(dataSource); + } + AlarmTaskNewResult r = new AlarmTaskNewResult(); + r.setReceiver(task.getReceiver()); + r.setTaskid(task.getTaskid()); + results.add(r); + } + return new RespEntity(RespCode.SUCCESS,results); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/update",method = RequestMethod.POST) + public RespEntity updateAlarmTask(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = new ProcessAlarmTaskEntity(); + JsonNode opnode = JsonHelper.getLevel2(rootnode,"operator"); + + task.setTaskid(JsonHelper.getStringValue(rootnode,"taskid")); + task.setLongitude(JsonHelper.getDoubleValue(rootnode,"longitude")); + task.setLatitude(JsonHelper.getDoubleValue(rootnode,"latitude")); + task.setContent(JsonHelper.getStringValue(rootnode,"content")); + task.setType(JsonHelper.getStringValue(rootnode,"type")); + task.setAddress(JsonHelper.getStringValue(rootnode,"address")); + task.setTitle(JsonHelper.getStringValue(rootnode,"title")); + if(task.getTaskid()==null||opnode==null) + return new RespEntity(RespCode.ERROR_REQUEST); + ProcessAlarmTaskEntity orgtask = (ProcessAlarmTaskEntity)task.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if (task.Update(dataSource)) { + ProcessAlarmTaskOpRecord op = (ProcessAlarmTaskOpRecord) SQLTools.getEntityFromJson(opnode,ProcessAlarmTaskOpRecord.class); + if(op!=null){ + op.setOperation("updateinfo"); + try { + op.setResult(Base64.encodeBase64String(rootnode.toString().getBytes("UTF8"))); + }catch (Exception e){ + + } + op.setTaskid(orgtask.getTaskid()); + op.setRelatealarmid(orgtask.getRelatealarmid()); + op.setTimestamp(new Date()); + op.setReceiver(orgtask.getReceiver()); + op.Insert(dataSource); + } + }else + return new RespEntity(RespCode.FAIL); + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/setstatus",method = RequestMethod.POST) + public RespEntity setAlarmTaskStatus(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = new ProcessAlarmTaskEntity(); + JsonNode opnode = JsonHelper.getLevel2(rootnode,"operator"); + + task.setTaskid(JsonHelper.getStringValue(rootnode,"taskid")); + task.setStatus(JsonHelper.getStringValue(rootnode,"status")); + if(task.getStatus()!=null&&task.getStatus().equals("closed")){ + task.setClosetime(new Date()); + } + if(task.getTaskid()==null||opnode==null) + return new RespEntity(RespCode.ERROR_REQUEST); + ProcessAlarmTaskEntity orgtask = (ProcessAlarmTaskEntity)task.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if (task.Update(dataSource)) { + ProcessAlarmTaskOpRecord op = (ProcessAlarmTaskOpRecord) SQLTools.getEntityFromJson(opnode,ProcessAlarmTaskOpRecord.class); + if(op!=null){ + op.setOperation("updatestatus"); + try { + op.setResult(Base64.encodeBase64String(task.getStatus().getBytes("UTF8"))); + }catch (Exception e){ + + } + op.setTaskid(orgtask.getTaskid()); + op.setRelatealarmid(orgtask.getRelatealarmid()); + op.setTimestamp(new Date()); + op.setReceiver(orgtask.getReceiver()); + op.Insert(dataSource); + } + }else + return new RespEntity(RespCode.FAIL); + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/gettaskcount",method = RequestMethod.POST) + public RespEntity getAlarmTaskCount(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = (ProcessAlarmTaskEntity) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskEntity.class); + + if(task==null) + task = new ProcessAlarmTaskEntity(); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int count = task.queryCount(dataSource, startstr, endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/gettasklist",method = RequestMethod.POST) + public RespEntity getAlarmTaskList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = (ProcessAlarmTaskEntity) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskEntity.class); + + if(task==null) + task = new ProcessAlarmTaskEntity(); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/gettaskcount_diffstatus",method = RequestMethod.POST) + public RespEntity getAlarmTaskCountDiffstatus(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = (ProcessAlarmTaskEntity) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskEntity.class); + task.addDiffCond("status"); + if(task.getStatus()==null) + return new RespEntity(RespCode.FAIL); + if(task==null) + task = new ProcessAlarmTaskEntity(); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int count = task.queryCount(dataSource, startstr, endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/gettasklist_diffstatus",method = RequestMethod.POST) + public RespEntity getAlarmTaskListDiffstatus(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskEntity task = (ProcessAlarmTaskEntity) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskEntity.class); + if(task.getStatus()==null) + return new RespEntity(RespCode.FAIL); + if(task==null) + task = new ProcessAlarmTaskEntity(); + task.addDiffCond("status"); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/gettaskopcount",method = RequestMethod.POST) + public RespEntity getAlarmTaskOPCount(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskOpRecord task = (ProcessAlarmTaskOpRecord) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskOpRecord.class); + + if(task==null) + task = new ProcessAlarmTaskOpRecord(); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int count = task.queryCount(dataSource, startstr, endstr); + return new RespEntity(RespCode.SUCCESS, new CountResult(count)); + } + + @ResponseBody + @RequestMapping(value="/iotserver/alarmtask/gettaskoplist",method = RequestMethod.POST) + public RespEntity getAlarmTaskOPList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + ProcessAlarmTaskOpRecord op = (ProcessAlarmTaskOpRecord) SQLTools.getEntityFromJson(rootnode,ProcessAlarmTaskOpRecord.class); + + if(op==null) + op = new ProcessAlarmTaskOpRecord(); + + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = op.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/changestate",method = RequestMethod.POST) + public RespEntity changeSensorAlarmEvent(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + ProcessAlarmEventOpRecord eventOpRecord = (ProcessAlarmEventOpRecord) SQLTools.getEntityFromJson(rootnode, ProcessAlarmEventOpRecord.class); + if(eventOpRecord==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(eventOpRecord.getEventId() == null || eventOpRecord.getNewState() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SensorAlarmEventEntity eventDB = new SensorAlarmEventEntity(); + eventDB.setEventId(eventOpRecord.getEventId()); + eventDB = (SensorAlarmEventEntity)eventDB.QueryIt(dataSource); + if(eventDB != null) { + Date recordTime = new Date(); + eventOpRecord.setPreviousState(eventDB.getState()); + eventDB.setState(eventOpRecord.getNewState()); + eventDB.setStateTime(recordTime); + if(eventDB.Update(dataSource)) { + eventOpRecord.setRecordId(eventDB.getEventId() + "_" + recordTime.getTime()); + eventOpRecord.setTimestamp(recordTime); + + eventOpRecord.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + }else + return new RespEntity(RespCode.NOTEXIST); + + return new RespEntity(RespCode.FAIL); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/alarm_event/getlog",method = RequestMethod.POST) + public RespEntity getSensorAlarmEventOpList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + ProcessAlarmEventOpRecord eventOpRecord = (ProcessAlarmEventOpRecord) SQLTools.getEntityFromJson(rootnode, ProcessAlarmEventOpRecord.class); + if(eventOpRecord==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(eventOpRecord.getEventId() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + List list = eventOpRecord.queryPage(dataSource, null, null, 0, 2000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/PublicAlarmController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/PublicAlarmController.java new file mode 100644 index 0000000..fe36e93 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/PublicAlarmController.java @@ -0,0 +1,99 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.publicsafe.PublicAlarmEntity; +import com.jingyi.iotserver.firestationport.model.school.PendingProcessItem; +import com.jingyi.iotserver.firestationport.model.school.SchoolPendingItem; +import com.jingyi.iotserver.firestationport.model.school.SchoolPendingProcessRecordEntity; +import com.jingyi.iotserver.firestationport.model.school.SchoolSecurityCheckEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@RestController +@CrossOrigin +public class PublicAlarmController { + @Autowired + private DataSource dataSource; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private SensorService sensorService; + + @ResponseBody + @RequestMapping(value="/iotserver/public/alarm/add",method = RequestMethod.POST) + public RespEntity addPublicAlarmInfo(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + PublicAlarmEntity publicAlarm = (PublicAlarmEntity) SQLTools.getEntityFromJson(rootnode,PublicAlarmEntity.class); + + if(publicAlarm==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + publicAlarm.setAlarmId(UUID.randomUUID().toString()); + publicAlarm.setReportTime(new Date()); + publicAlarm.setStatus(PublicAlarmEntity.STATE_OPEN); + publicAlarm.setCheckResult(PublicAlarmEntity.RESULT_NO); + if(FireCtrlSystemInit.netMode == 1){ + sensorService.addWechatAlarmEvent(publicAlarm); + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(publicAlarm), "/iotserver/school/check/add"); + } + + if (!publicAlarm.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/public/alarm/getlist",method = RequestMethod.POST) + public RespEntity get(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + PublicAlarmEntity publicAlarm = (PublicAlarmEntity) SQLTools.getEntityFromJson(rootnode,PublicAlarmEntity.class); + + if(publicAlarm==null) + publicAlarm = new PublicAlarmEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = publicAlarm.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/RfidController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/RfidController.java new file mode 100644 index 0000000..98278dd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/RfidController.java @@ -0,0 +1,689 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.school.SchoolNewsEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.gas.DataDescriptionEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidAntDetectorEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidBuzEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidStateEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.List; + +@RestController +@CrossOrigin +public class RfidController { + @Autowired + private DataSource dataSource; + + @Autowired + private StationServices stationServices; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + private final Logger logger = LoggerFactory.getLogger(RfidController.class); + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/detectant/add",method = RequestMethod.POST) + public RespEntity addRfidDetect(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidAntDetectorEntity detector = (RfidAntDetectorEntity) SQLTools.getEntityFromJson(rootnode,RfidAntDetectorEntity.class); + if(detector==null||detector.getRfidreader()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(detector.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if(detector.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/detectant/delete",method = RequestMethod.POST) + public RespEntity deleteRfidDetect(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidAntDetectorEntity detector = (RfidAntDetectorEntity) SQLTools.getEntityFromJson(rootnode,RfidAntDetectorEntity.class); + if(detector==null||detector.getRfidreader()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(detector.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(detector.Delete(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/detectant/update",method = RequestMethod.POST) + public RespEntity updateRfidDetect(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidAntDetectorEntity detector = (RfidAntDetectorEntity) SQLTools.getEntityFromJson(rootnode,RfidAntDetectorEntity.class); + if(detector==null||detector.getRfidreader()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(detector.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(detector.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/detectant/getcount",method = RequestMethod.POST) + public RespEntity getDetectorCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidAntDetectorEntity detector = (RfidAntDetectorEntity) SQLTools.getEntityFromJson(rootnode,RfidAntDetectorEntity.class); + + if(detector==null) + detector = new RfidAntDetectorEntity(); + int count = detector.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/detectant/getlist",method = RequestMethod.POST) + public RespEntity getDetectorList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + RfidAntDetectorEntity detector = (RfidAntDetectorEntity) SQLTools.getEntityFromJson(rootnode,RfidAntDetectorEntity.class); + + if(detector==null) + detector = new RfidAntDetectorEntity(); + List list = detector.queryPage(dataSource,null,null,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/add",method = RequestMethod.POST) + public RespEntity addRfid(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidStateEntity rfid = (RfidStateEntity) SQLTools.getEntityFromJson(rootnode,RfidStateEntity.class); + if(rfid==null||rfid.getRfid()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(rfid.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if(rfid.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/delete",method = RequestMethod.POST) + public RespEntity deleteRfid(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidStateEntity rfid = (RfidStateEntity) SQLTools.getEntityFromJson(rootnode,RfidStateEntity.class); + if(rfid==null||rfid.getRfid()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(rfid.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(rfid.Delete(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/update",method = RequestMethod.POST) + public RespEntity updateRfid(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidStateEntity rfid = (RfidStateEntity) SQLTools.getEntityFromJson(rootnode,RfidStateEntity.class); + if(rfid==null||rfid.getRfid()==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(rfid.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(rfid.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/getcount",method = RequestMethod.POST) + public RespEntity getRfidCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidStateEntity rfid = (RfidStateEntity) SQLTools.getEntityFromJson(rootnode,RfidStateEntity.class); + + if(rfid==null) + rfid = new RfidStateEntity(); + int count = rfid.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/getlist",method = RequestMethod.POST) + public RespEntity getRfidList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + RfidStateEntity rfid = (RfidStateEntity) SQLTools.getEntityFromJson(rootnode,RfidStateEntity.class); + + if(rfid==null) + rfid = new RfidStateEntity(); + List list = rfid.queryPage(dataSource,null,null,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/buzevent/getcount",method = RequestMethod.POST) + public RespEntity getRfidBuzEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidBuzEventEntity event = (RfidBuzEventEntity) SQLTools.getEntityFromJson(rootnode,RfidBuzEventEntity.class); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + if(event==null) + event = new RfidBuzEventEntity(); + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/buzevent/getlist",method = RequestMethod.POST) + public RespEntity getRfidBuzEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + RfidBuzEventEntity event = (RfidBuzEventEntity) SQLTools.getEntityFromJson(rootnode,RfidBuzEventEntity.class); + + if(event==null) + event = new RfidBuzEventEntity(); + List list = event.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/event/getcount",method = RequestMethod.POST) + public RespEntity getRfidEventCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + RfidEventEntity event = (RfidEventEntity) SQLTools.getEntityFromJson(rootnode, RfidEventEntity.class); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + if(event==null) + event = new RfidEventEntity(); + int count = event.queryCount(dataSource,startstr,endstr); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/sensor/rfid/event/getlist",method = RequestMethod.POST) + public RespEntity getRfidEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + RfidEventEntity event = (RfidEventEntity) SQLTools.getEntityFromJson(rootnode,RfidEventEntity.class); + + if(event==null) + event = new RfidEventEntity(); + List list = event.queryPage(dataSource,startstr,endstr,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + @ResponseBody + @RequestMapping(value="/firectrl/push_alarm_point/add",method = RequestMethod.POST) + public RespEntity addPushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + if (bodyData != null) { + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, bodyData, "/firectrl/push_alarm_point/add"); + } + PushAlarmPointEntity alarmPointEntity = JSON.parseObject(bodyData, PushAlarmPointEntity.class);// SQLTools.getEntityFromJson(rootnode, PushAlarmPointEntity.class); + + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (alarmPointEntity.getPointCode() == null || alarmPointEntity.getBrigade() == null || alarmPointEntity.getAccount() == null) + return new RespEntity(RespCode.ERROR_CMD); + + alarmPointEntity.setPointId(alarmPointEntity.getAccount() + "_" + alarmPointEntity.getPointCode()); + if(alarmPointEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (alarmPointEntity.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/push_alarm_point/update",method = RequestMethod.POST) + public RespEntity updatePushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + System.out.println("updatePushAlarmPoint: 0 " + bodyData); + if (bodyData != null) { + PushAlarmPointEntity pointEntity = JSON.parseObject(bodyData, PushAlarmPointEntity.class); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, bodyData, "/firectrl/push_alarm_point/update"); + } + System.out.println("updatePushAlarmPoint: 1"); + if (pointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + + System.out.println("updatePushAlarmPoint: 2"); + if (pointEntity.getPointId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + System.out.println("updatePushAlarmPoint: 3"); + if(pointEntity.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if (pointEntity.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/push_alarm_point/delete",method = RequestMethod.POST) + public RespEntity deletePushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + if (bodyData != null) { + PushAlarmPointEntity pointEntity = JSON.parseObject(bodyData, PushAlarmPointEntity.class); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, bodyData, "/firectrl/push_alarm_point/delete"); + } + + if (pointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (pointEntity.getPointId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(pointEntity.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (pointEntity.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/push_alarm_point/getlist",method = RequestMethod.POST) + public RespEntity getPushAlarmPoint(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PushAlarmPointEntity pointEntity = (PushAlarmPointEntity)SQLTools.getEntityFromJson(rootnode,PushAlarmPointEntity.class); + + if(pointEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(pointEntity.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = pointEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/push_alarm_point/dwmc",method = RequestMethod.POST) + public RespEntity getPushAlarmPointInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PushAlarmPointEntity pointEntity = (PushAlarmPointEntity)SQLTools.getEntityFromJson(rootnode,PushAlarmPointEntity.class); + + if(pointEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(pointEntity.getDwmc()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + PushAlarmPointEntity list = PushAlarmPointEntity.QueryStationName(dataSource, pointEntity.getDwmc()); + if(list == null){ + return new RespEntity(RespCode.NOTEXIST); + } + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + /* + 传感器数值描述表 + */ + @ResponseBody + @RequestMapping(value="/firectrl/data_description/add",method = RequestMethod.POST) + public RespEntity addDataDescription(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + if (bodyData != null) { + + DataDescriptionEntity alarmPointEntity = JSON.parseObject(bodyData, DataDescriptionEntity.class); + if (alarmPointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (alarmPointEntity.getName() == null || alarmPointEntity.getType() == null ) + return new RespEntity(RespCode.ERROR_CMD); + + if(alarmPointEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (alarmPointEntity.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/data_description/update",method = RequestMethod.POST) + public RespEntity updateDataDescription(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + if (bodyData != null) { + DataDescriptionEntity pointEntity = JSON.parseObject(bodyData, DataDescriptionEntity.class); + + if (pointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (pointEntity.getName() == null || pointEntity.getType() == null ) + return new RespEntity(RespCode.ERROR_CMD); + + if(pointEntity.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (pointEntity.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/data_description/delete",method = RequestMethod.POST) + public RespEntity deleteDataDescription(HttpServletRequest request) { + RespEntity rel = null; + try { + String bodyData = HttpTools.getBodyFromRequest(request); + if (bodyData != null) { + DataDescriptionEntity pointEntity = JSON.parseObject(bodyData, DataDescriptionEntity.class); + + if (pointEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (pointEntity.getName() == null || pointEntity.getType() == null ) + return new RespEntity(RespCode.ERROR_CMD); + if(pointEntity.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (pointEntity.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/data_description/getlist",method = RequestMethod.POST) + public RespEntity getDataDescriptionList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + DataDescriptionEntity pointEntity = (DataDescriptionEntity)SQLTools.getEntityFromJson(rootnode,PushAlarmPointEntity.class); + + if(pointEntity==null) + pointEntity = new DataDescriptionEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = pointEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/SchoolController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/SchoolController.java new file mode 100644 index 0000000..bbd67a8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/SchoolController.java @@ -0,0 +1,4434 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.clientmanage.model.BrigadeEntity; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.school.*; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SkynetIPCEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.PolicemanInfo; +import com.jingyi.iotserver.firestationport.model.statistics.BoroughPoliceSummary; +import com.jingyi.iotserver.firestationport.model.statistics.SchoolPoliceSummary; +import com.jingyi.iotserver.firestationport.services.DataStatisticsService; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.analyze.StatisticsMessage; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.GuardSignEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.SensorEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.utils.*; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.io.File; +import java.util.*; + +@RestController +@CrossOrigin +public class SchoolController { + + String wechat_appId = "wxf04e1270a77256d7"; + String wechat_secret = "6a47207367bb478b2ae0682c9c3e8d7f"; + + + @Autowired + private DataSource dataSource; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Autowired + DataStatisticsService dataStatisticsService; + + @Autowired + private StationServices stationServices; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @ResponseBody + @RequestMapping(value="/iotserver/school/check/add",method = RequestMethod.POST) + public RespEntity addSchoolCheckInfo(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorPoliceCheck task = (SchoolColorPoliceCheck) SQLTools.getEntityFromJson(rootnode,SchoolColorPoliceCheck.class); + + System.out.println("addSchoolCheckInfo rec:" + rootnode.toString()); + if(task==null||task.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + task.setTimestamp(new Date()); + task.setRecordId(UUID.randomUUID().toString()); + try { + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,task.getStation()); + if(st == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + task.setBrigade(st.getBrigade()); + task.setBorough(st.getBorough()); + task.setDetachment(st.getDetachment()); + }catch (Exception e){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(task), "/iotserver/school/check/add"); + } + + if (!task.Insert(dataSource)) { + return new RespEntity(RespCode.FAIL); + } + + List processItemList = task.buildPendingItemList(); + if(!processItemList.isEmpty()){ + SchoolPendingItem pendingItem = new SchoolPendingItem(); + pendingItem.setId(UUID.randomUUID().toString()); + Date ts = new Date(); + pendingItem.setTimestamp(ts); + pendingItem.setState(SchoolPendingItem.STATE_PENDING); + pendingItem.setStation(task.getStation()); + pendingItem.setBrigade(task.getBrigade()); + pendingItem.setBorough(task.getBorough()); + pendingItem.setDetachment(task.getDetachment()); + pendingItem.setCreator(task.getCheckerName()); + + StringBuilder problemDesc = new StringBuilder(); + for(int iItem = 0; iItem < processItemList.size() - 1; iItem++){ + problemDesc.append(processItemList.get(iItem).getItemValue()+ ","); + } + problemDesc.append(processItemList.get(processItemList.size() - 1).toString() + "."); + + pendingItem.setProblemDesc(problemDesc.toString()); + pendingItem.Insert(dataSource); + + SchoolPendingProcessRecordEntity newRecord = new SchoolPendingProcessRecordEntity(); + newRecord.setBrigade(pendingItem.getBrigade()); + newRecord.setBorough(pendingItem.getBorough()); + newRecord.setDetachment(pendingItem.getDetachment()); + newRecord.setStation(pendingItem.getStation()); + newRecord.setItemId(pendingItem.getId()); + newRecord.setRecordId(UUID.randomUUID().toString()); + newRecord.setTimestamp(ts); + newRecord.setEventType(SchoolPendingProcessRecordEntity.OP_CREATE); + newRecord.setUserName(pendingItem.getCreator()); + newRecord.Insert(dataSource); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/check/update",method = RequestMethod.POST) + public RespEntity updateSchoolCheckInfo(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorPoliceCheck task = (SchoolColorPoliceCheck) SQLTools.getEntityFromJson(rootnode,SchoolColorPoliceCheck.class); + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + SchoolColorPoliceCheck orgtask = (SchoolColorPoliceCheck)task.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + } + task.setTimestamp(new Date()); + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(task), "/iotserver/school/check/update"); + } + if (task.Update(dataSource)) { + return new RespEntity(RespCode.SUCCESS); + }else + return new RespEntity(RespCode.FAIL); + + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/check/getinfo",method = RequestMethod.POST) + public RespEntity querySchoolCheckInfo(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorPoliceCheck securityCheck = (SchoolColorPoliceCheck) SQLTools.getEntityFromJson(rootnode,SchoolColorPoliceCheck.class); + if(securityCheck==null) + return new RespEntity(RespCode.ERROR_REQUEST); + SchoolColorPoliceCheck oldSecurityCheck= (SchoolColorPoliceCheck)securityCheck.QueryIt(dataSource); + if(oldSecurityCheck==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + return new RespEntity(RespCode.SUCCESS, oldSecurityCheck); + } + + + @ResponseBody + @RequestMapping(value="/iotserver/school/check/getlist",method = RequestMethod.POST) + public RespEntity getSchoolCheckInfoList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorPoliceCheck task = (SchoolColorPoliceCheck) SQLTools.getEntityFromJson(rootnode,SchoolColorPoliceCheck.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null && task.getBorough()== null && task.getDetachment() == null && task.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = task.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/check/get_pending",method = RequestMethod.POST) + public RespEntity getSchoolCheckPendingItemList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolSecurityCheckEntity task = (SchoolSecurityCheckEntity) SQLTools.getEntityFromJson(rootnode,SchoolSecurityCheckEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null && task.getBorough()== null && task.getDetachment() == null && task.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + List pendingProcessItemList = new ArrayList<>(); + if(list==null){ + return new RespEntity(RespCode.SUCCESS, pendingProcessItemList); + } + if(list.size()==0){ + return new RespEntity(RespCode.SUCCESS, pendingProcessItemList); + } + + for(int iStation = 0; iStation < list.size(); iStation++){ + SchoolSecurityCheckEntity securityCheck = (SchoolSecurityCheckEntity)(list.get(iStation)); + List schoolPending = securityCheck.buildPendingItemList(); + pendingProcessItemList.addAll(schoolPending); + } + + return new RespEntity(RespCode.SUCCESS, pendingProcessItemList); + } + + /* + 三色评定概要分 + */ + + @ResponseBody + @RequestMapping(value="/iotserver/school/color_detail/add",method = RequestMethod.POST) + public RespEntity addSchoolColorRatingDetail(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorDetailEntity colorRatingDetail = (SchoolColorDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorDetailEntity.class); + + if(colorRatingDetail==null||colorRatingDetail.getStation()==null ||colorRatingDetail.getSchoolTime() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + FireStationBaseInfoEntity stationBaseInfo = FireStationBaseInfoEntity.Query(dataSource, colorRatingDetail.getStation()); + if (stationBaseInfo != null){ + colorRatingDetail.setBrigade(stationBaseInfo.getBrigade()); + colorRatingDetail.setBorough(stationBaseInfo.getBorough()); + colorRatingDetail.setDetachment(stationBaseInfo.getDetachment()); + } + + colorRatingDetail.setTimestamp(new Date()); + colorRatingDetail.calcScore(); + + SchoolColorRatingEntity ratingEntity = new SchoolColorRatingEntity(); + ratingEntity.setBrigade(colorRatingDetail.getBrigade()); + ratingEntity.setBorough(colorRatingDetail.getBorough()); + ratingEntity.setDetachment(colorRatingDetail.getDetachment()); + ratingEntity.setStation(colorRatingDetail.getStation()); + ratingEntity.setTimestamp(colorRatingDetail.getTimestamp()); + ratingEntity.setScoreCase(colorRatingDetail.getScoreCase()); + ratingEntity.setScoreDesire(colorRatingDetail.getScoreDesire()); + ratingEntity.setScoreDevices(colorRatingDetail.getScoreDevices()); + ratingEntity.setScoreHuman(colorRatingDetail.getScoreHuman()); + ratingEntity.setScoreScheme(colorRatingDetail.getScoreScheme()); + ratingEntity.setScoreTech(colorRatingDetail.getScoreTech()); + ratingEntity.setScoreTotal(colorRatingDetail.getScoreTotal()); + ratingEntity.setSchoolTime(colorRatingDetail.getSchoolTime()); + + insertNewSchoolTime(colorRatingDetail.getSchoolTime(), SchoolTimeLabelEntity.TYPE_COLOR, colorRatingDetail.getBrigade()); + + SchoolColorPoliceCheck newCheckRecord = (SchoolColorPoliceCheck) SQLTools.getEntityFromJson(rootnode,SchoolColorPoliceCheck.class); + if(newCheckRecord != null){ + newCheckRecord.setRecordId(UUID.randomUUID().toString()); + newCheckRecord.setTimestamp(colorRatingDetail.getTimestamp()); + newCheckRecord.Insert(dataSource); + } + + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_ColorDetail, JSON.toJSONString(colorRatingDetail), "/iotserver/school/color_detail/add"); + } + SchoolColorDetailEntity oldDetail = (SchoolColorDetailEntity)colorRatingDetail.QueryIt(dataSource); + boolean detialFail = false; + if(oldDetail==null){ + if (!colorRatingDetail.Insert(dataSource)) { + detialFail = true; + } + }else{ + if (!colorRatingDetail.Update(dataSource)) { + detialFail = true; + } + } + if(detialFail == true){ + return new RespEntity(RespCode.FAIL); + } + + SchoolColorRatingEntity oldRating = (SchoolColorRatingEntity)ratingEntity.QueryIt(dataSource); + detialFail = false; + if(oldRating==null){ + if (!ratingEntity.Insert(dataSource)) { + detialFail = true; + } + }else{ + if (!ratingEntity.Update(dataSource)) { + detialFail = true; + } + } + if(detialFail == true){ + return new RespEntity(RespCode.FAIL); + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/color_detail/getdetail",method = RequestMethod.POST) + public RespEntity getSchoolColorRatingDetail(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorDetailEntity colorDetail = (SchoolColorDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorDetailEntity.class); + + if(colorDetail==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if( colorDetail.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + SchoolColorDetailEntity orgtask = (SchoolColorDetailEntity)colorDetail.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + }else{ + return new RespEntity(RespCode.SUCCESS, orgtask); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/color_detail/getlist",method = RequestMethod.POST) + public RespEntity getSchoolColorRatingDetailList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorDetailEntity detailEntity = (SchoolColorDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorDetailEntity.class); + + if(detailEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(detailEntity.getBrigade()==null && detailEntity.getBorough()== null && detailEntity.getDetachment() == null && detailEntity.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = detailEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/colorrating/getlist",method = RequestMethod.POST) + public RespEntity getSchoolColorRatingList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorRatingEntity task = (SchoolColorRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null && task.getBorough()== null && task.getDetachment() == null && task.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/colorrating/getcase",method = RequestMethod.POST) + public RespEntity getSchoolColorRatingCaseList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorRatingEntity task = (SchoolColorRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null ) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = SchoolColorRatingEntity.QueryCase(dataSource, task.getBrigade(), task.getSchoolTime()); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/colorrating/getcompose",method = RequestMethod.POST) + public RespEntity getSchoolColorRatingCompose(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorRatingEntity task = (SchoolColorRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null && task.getBorough()== null && task.getDetachment() == null ) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + SchoolColorRatingCompose ratingCompose = new SchoolColorRatingCompose(); + + if(list == null){ + return new RespEntity(RespCode.SUCCESS, ratingCompose); + } + if(list.size() == 0){ + return new RespEntity(RespCode.SUCCESS, ratingCompose); + } + + for(int iSchool = 0; iSchool < list.size(); iSchool++){ + SchoolColorRatingEntity ratingEntity = (SchoolColorRatingEntity)list.get(iSchool); + + if(ratingEntity.getScoreTotal()>= 960){ + ratingCompose.addColorGreen(1); + }else if(ratingEntity.getScoreTotal()>= 910){ + ratingCompose.addColorYellow(1); + }else{ + ratingCompose.addColorRed(1); + } + + if(ratingEntity.getScoreHuman() >= 150){ + ratingCompose.addHumanGreat(1); + }else if(ratingEntity.getScoreHuman() >= 100){ + ratingCompose.addHumanGood(1); + }else{ + ratingCompose.addHumanBad(1); + } + + if(ratingEntity.getScoreDevices() >= 150){ + ratingCompose.addDevicesGreat(1); + }else if(ratingEntity.getScoreDevices() >= 100){ + ratingCompose.addDevicesGood(1); + }else{ + ratingCompose.addDevicesBad(1); + } + + if(ratingEntity.getScoreTech() >= 200){ + ratingCompose.addTechGreat(1); + }else if(ratingEntity.getScoreTech() >= 150){ + ratingCompose.addTechGood(1); + }else{ + ratingCompose.addTechBad(1); + } + + if(ratingEntity.getScoreDesire() >= 80){ + ratingCompose.addDesireGreat(1); + }else if(ratingEntity.getScoreDesire() >= 60){ + ratingCompose.addDesireGood(1); + }else{ + ratingCompose.addDesireBad(1); + } + + if(ratingEntity.getScoreScheme() >= 150){ + ratingCompose.addSchemeGreat(1); + }else if(ratingEntity.getScoreScheme() >= 100){ + ratingCompose.addSchemeGood(1); + }else{ + ratingCompose.addSchemeBad(1); + } + + if(ratingEntity.getScoreCase() > 0){ + ratingCompose.addCaseTotal(1); + } + + } + + return new RespEntity(RespCode.SUCCESS, ratingCompose); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/colorrating/brigade",method = RequestMethod.POST) + public RespEntity getBrigadeColorRating(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorRatingEntity task = (SchoolColorRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + if(list == null){ + return new RespEntity(RespCode.SUCCESS, task); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS, task); + } + + int scoreTotal = 0; + int scoreHumam = 0; + int scoreDevices = 0; + int scoreDesire = 0; + int scoreScheme = 0; + int scoreTech = 0; + int scoreCase = 0; + + for(int iSchool = 0; iSchool < schoolSize; iSchool++){ + SchoolColorRatingEntity ratingEntity = (SchoolColorRatingEntity)list.get(iSchool); + scoreTotal += ratingEntity.getScoreTotal(); + scoreHumam += ratingEntity.getScoreHuman(); + scoreDevices += ratingEntity.getScoreDevices(); + scoreDesire += ratingEntity.getScoreDesire(); + scoreScheme += ratingEntity.getScoreScheme(); + scoreTech += ratingEntity.getScoreTech(); + scoreCase += ratingEntity.getScoreCase(); + } + + task.setScoreTotal(scoreTotal/schoolSize); + task.setScoreHuman(scoreHumam/schoolSize); + task.setScoreDevices(scoreDevices/schoolSize); + task.setScoreDesire(scoreDesire/schoolSize); + task.setScoreScheme(scoreScheme/schoolSize); + task.setScoreTech(scoreTech/schoolSize); + task.setScoreCase(scoreCase/schoolSize); + + return new RespEntity(RespCode.SUCCESS, task); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/colorrating/borough",method = RequestMethod.POST) + public RespEntity getBoroughColorRating(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorRatingEntity task = (SchoolColorRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBorough()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + if(list == null){ + return new RespEntity(RespCode.SUCCESS, task); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS, task); + } + + int scoreTotal = 0; + int scoreHumam = 0; + int scoreDevices = 0; + int scoreDesire = 0; + int scoreScheme = 0; + int scoreTech = 0; + int scoreCase = 0; + + for(int iSchool = 0; iSchool < schoolSize; iSchool++){ + SchoolColorRatingEntity ratingEntity = (SchoolColorRatingEntity)list.get(iSchool); + scoreTotal += ratingEntity.getScoreTotal(); + scoreHumam += ratingEntity.getScoreHuman(); + scoreDevices += ratingEntity.getScoreDevices(); + scoreDesire += ratingEntity.getScoreDesire(); + scoreScheme += ratingEntity.getScoreScheme(); + scoreTech += ratingEntity.getScoreTech(); + scoreCase += ratingEntity.getScoreCase(); + } + + task.setScoreTotal(scoreTotal/schoolSize); + task.setScoreHuman(scoreHumam/schoolSize); + task.setScoreDevices(scoreDevices/schoolSize); + task.setScoreDesire(scoreDesire/schoolSize); + task.setScoreScheme(scoreScheme/schoolSize); + task.setScoreTech(scoreTech/schoolSize); + task.setScoreCase(scoreCase/schoolSize); + + return new RespEntity(RespCode.SUCCESS, task); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/colorrating/summary",method = RequestMethod.POST) + public RespEntity getColorRatingSummary(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolColorDetailEntity task = (SchoolColorDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolColorDetailEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null ||task.getSchoolTime() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = task.queryPage(dataSource, null, null, 0, 1000); + List summaryList = new ArrayList<>(); + if(list == null){ + return new RespEntity(RespCode.SUCCESS, summaryList); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS, summaryList); + } + + + for(int iSchool = 0; iSchool < schoolSize; iSchool++){ + + SchoolRatingSummary ratingSummary = new SchoolRatingSummary(); + SchoolColorDetailEntity ratingEntity = (SchoolColorDetailEntity)list.get(iSchool); + + ratingSummary.setBrigade(ratingEntity.getBrigade()); + ratingSummary.setBorough(ratingEntity.getBorough()); + ratingSummary.setDetachment(ratingEntity.getDetachment()); + ratingSummary.setStation(ratingEntity.getStation()); + + String checkDescription = ""; + if(ratingEntity.getGuarderCount() > 0){ + checkDescription += ratingEntity.getGuarderCountDetail() + ";"; + } + + if(ratingEntity.getGuarderCert() > 0){ + checkDescription += ratingEntity.getGuarderCertDetail() + ";"; + } + + if(ratingEntity.getGuarderOverAge() > 0){ + checkDescription += ratingEntity.getGuarderOverAgeDetail() + ";"; + } + + if(ratingEntity.getPeakGuarderArmed() > 0){ + checkDescription += ratingEntity.getPeakGuarderArmedDetail() + ";"; + } + + if(ratingEntity.getPeakProtectScheme() > 0){ + checkDescription += ratingEntity.getPeakProtectSchemeDetail() + ";"; + } + + if(ratingEntity.getPeakStaff() > 0){ + checkDescription += ratingEntity.getPeakStaffDetail() + ";"; + } + + if(ratingEntity.getZoneClosed() > 0){ + checkDescription += ratingEntity.getZoneClosedDetail() + ";"; + } + + if(ratingEntity.getEquipCount() > 0){ + checkDescription += ratingEntity.getEquipCountDetail() + ";"; + } + + if(ratingEntity.getCollision() > 0){ + checkDescription += ratingEntity.getCollisionDetail() + ";"; + } + + if(ratingEntity.getIpcCover() > 0){ + checkDescription += ratingEntity.getIpcCoverDetail() + ";"; + } + + if(ratingEntity.getAlarmSystem() > 0){ + checkDescription += ratingEntity.getAlarmSystemDetail() + ";"; + } + + if(ratingEntity.getIpcGate() > 0){ + checkDescription += ratingEntity.getIpcGateDetail() + ";"; + } + + if(ratingEntity.getIpcRecord() > 0){ + checkDescription += ratingEntity.getIpcRecordDetail() + ";"; + } + + if(ratingEntity.getLawEducation() > 0){ + checkDescription += ratingEntity.getLawEducationDetail() + ";"; + } + + if(ratingEntity.getConflict() > 0){ + checkDescription += ratingEntity.getConflictDetail() + ";"; + } + + if(ratingEntity.getGuarderScheme() > 0){ + checkDescription += ratingEntity.getGuarderSchemeDetail() + ";"; + } + + if(ratingEntity.getBuildingScheme() > 0){ + checkDescription += ratingEntity.getBuildingSchemeDetail() + ";"; + } + + if(ratingEntity.getFireScheme() > 0){ + checkDescription += ratingEntity.getFireSchemeDetail() + ";"; + } + + if(ratingEntity.getDangerousScheme() > 0){ + checkDescription += ratingEntity.getDangerousSchemeDetail() + ";"; + } + + if(ratingEntity.getConflictScheme() > 0){ + checkDescription += ratingEntity.getConflictSchemeDetail() + ";"; + } + + if(ratingEntity.getGuarderPMIScheme() > 0){ + checkDescription += ratingEntity.getGuarderPMISchemeDetail() + ";"; + } + + if(ratingEntity.getSecurityServiceScheme() > 0){ + checkDescription += ratingEntity.getSecurityServiceSchemeDetail() + ";"; + } + + ratingSummary.setRatingDescriptionStation(checkDescription); + ratingSummary.setScoreTotalStation(ratingEntity.getScoreTotal()); + + ratingSummary.setRatingDescriptionBrigade(checkDescription); + ratingSummary.setScoreTotalBrigade(ratingSummary.getScoreTotalStation()); + + int scoreTotal = ratingSummary.getScoreTotalStation(); + int level = 1; + if(scoreTotal >= 960){ + level = 1; + }else if(scoreTotal >= 910){ + level = 2; + }else if(scoreTotal >= 800){ + level = 3; + }else{ + level = 4; + } + ratingSummary.setLevelStation(level); + + scoreTotal = ratingSummary.getScoreTotalBrigade(); + if(scoreTotal >= 960){ + level = 1; + }else if(scoreTotal >= 910){ + level = 2; + }else if(scoreTotal >= 800){ + level = 3; + }else{ + level = 4; + } + ratingSummary.setLevelBrigade(level); + + ratingSummary.setRatingBonusBrigade(""); + ratingSummary.setRatingBonusStation(""); + ratingSummary.setRatingCasesStation(""); + ratingSummary.setRatingCasesBrigade(""); + + summaryList.add(ratingSummary); + } + + return new RespEntity(RespCode.SUCCESS, summaryList); + } + + /* + 星级评定 + */ + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_detail/add",method = RequestMethod.POST) + public RespEntity addSchoolStarDetail(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarDetailEntity starDetail = (SchoolStarDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarDetailEntity.class); + + if(starDetail==null||starDetail.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + /* + insert record + */ + Date checkTime = new Date(); + try{ + SchoolStarDetailRecord starCheckRecord = (SchoolStarDetailRecord) SQLTools.getEntityFromJson(rootnode,SchoolStarDetailRecord.class); + starCheckRecord.setTimestamp(checkTime); + starCheckRecord.Insert(dataSource); + }catch (Exception e){ + } + + starDetail.setTimestamp(checkTime); + starDetail.calcScore(); + + SchoolStarRatingEntity ratingEntity = new SchoolStarRatingEntity(); + ratingEntity.setBrigade(starDetail.getBrigade()); + ratingEntity.setBorough(starDetail.getBorough()); + ratingEntity.setDetachment(starDetail.getDetachment()); + ratingEntity.setStation(starDetail.getStation()); + ratingEntity.setTimestamp(starDetail.getTimestamp()); + ratingEntity.setScoreBonus(starDetail.getScoreBonus()); + ratingEntity.setScoreEmcManage(starDetail.getScoreEmcManage()); + ratingEntity.setScoreInsideManage(starDetail.getScoreInsideManage()); + ratingEntity.setScoreOutsideManage(starDetail.getScoreOutsideManage()); + ratingEntity.setScoreRiskManage(starDetail.getScoreRiskManage()); + ratingEntity.setScoreLawEducation(starDetail.getScoreLawEducation()); + ratingEntity.setScoreTotal(starDetail.getScoreTotal()); + ratingEntity.setSchoolTime(starDetail.getSchoolTime()); + + insertNewSchoolTime(starDetail.getSchoolTime(), SchoolTimeLabelEntity.TYPE_STAR, starDetail.getBrigade()); + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_StarDetail, JSON.toJSONString(starDetail), "/iotserver/school/star_detail/add"); + } + SchoolStarDetailEntity oldDetail = (SchoolStarDetailEntity)starDetail.QueryIt(dataSource); + boolean detialFail = false; + if(oldDetail==null){ + if (!starDetail.Insert(dataSource)) { + detialFail = true; + } + }else{ + if (!starDetail.Update(dataSource)) { + detialFail = true; + } + } + if(detialFail == true){ + return new RespEntity(RespCode.FAIL); + } + + SchoolStarRatingEntity oldRating = (SchoolStarRatingEntity)ratingEntity.QueryIt(dataSource); + detialFail = false; + if(oldRating==null){ + if (!ratingEntity.Insert(dataSource)) { + detialFail = true; + } + }else{ + if (!ratingEntity.Update(dataSource)) { + detialFail = true; + } + } + + if(detialFail == true){ + return new RespEntity(RespCode.FAIL); + } + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_detail/getdetail",method = RequestMethod.POST) + public RespEntity getSchoolStarDetail(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarDetailEntity colorDetail = (SchoolStarDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarDetailEntity.class); + + if(colorDetail==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if( colorDetail.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + SchoolStarDetailEntity orgtask = (SchoolStarDetailEntity)colorDetail.QueryIt(dataSource); + if(orgtask==null){ + return new RespEntity(RespCode.NOTEXIST); + }else{ + return new RespEntity(RespCode.SUCCESS, orgtask); + } + + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_detail/getlist",method = RequestMethod.POST) + public RespEntity getSchoolStarDetailList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarDetailEntity detailEntity = (SchoolStarDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarDetailEntity.class); + + if(detailEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(detailEntity.getBrigade()==null && detailEntity.getBorough()== null && detailEntity.getDetachment() == null && detailEntity.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = detailEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_rating/getlist",method = RequestMethod.POST) + public RespEntity getSchoolStarRatingList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarRatingEntity task = (SchoolStarRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null && task.getBorough()== null && task.getDetachment() == null && task.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_rating/getbonus",method = RequestMethod.POST) + public RespEntity getSchoolStarRatingBonusList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarRatingEntity task = (SchoolStarRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = SchoolStarRatingEntity.QueryBonus(dataSource, task.getBrigade(), task.getSchoolTime()); + return new RespEntity(RespCode.SUCCESS, list); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_rating/getcompose",method = RequestMethod.POST) + public RespEntity getSchoolStarRatingCompose(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarRatingEntity task = (SchoolStarRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null && task.getBorough()== null && task.getDetachment() == null ) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + SchoolStarRatingCompose ratingCompose = new SchoolStarRatingCompose(); + ratingCompose.setBrigade(task.getBrigade()); + ratingCompose.setBorough(task.getBorough()); + ratingCompose.setDetachment(task.getDetachment()); + ratingCompose.setStation(task.getStation()); + if(list == null){ + return new RespEntity(RespCode.SUCCESS, ratingCompose); + } + if(list.size() == 0){ + return new RespEntity(RespCode.SUCCESS, ratingCompose); + } + + for(int iSchool = 0; iSchool < list.size(); iSchool++){ + SchoolStarRatingEntity ratingEntity = (SchoolStarRatingEntity)list.get(iSchool); + + if(ratingEntity.getScoreTotal() >= 950){ + ratingCompose.addTotalStar5(); + }else if(ratingEntity.getScoreTotal() >= 850){ + ratingCompose.addTotalStar4(); + }else if(ratingEntity.getScoreTotal() >= 750){ + ratingCompose.addTotalStar3(); + }else if(ratingEntity.getScoreTotal() >= 650){ + ratingCompose.addTotalStar2(); + }else{ + ratingCompose.addTotalStar1(); + } + + if(ratingEntity.getScoreInsideManage() >= 150){ + ratingCompose.addInsideGreat(); + }else if(ratingEntity.getScoreInsideManage() >= 100){ + ratingCompose.addInsideGood(); + }else{ + ratingCompose.addInsideBad(); + } + + if(ratingEntity.getScoreOutsideManage() >= 150){ + ratingCompose.addOutsideGreat(); + }else if(ratingEntity.getScoreOutsideManage() >= 100){ + ratingCompose.addOutsideGood(); + }else{ + ratingCompose.addOutsideBad(); + } + + if(ratingEntity.getScoreRiskManage() >= 200){ + ratingCompose.addRiskGreat(); + }else if(ratingEntity.getScoreRiskManage() >= 150){ + ratingCompose.addRiskGood(); + }else{ + ratingCompose.addRiskBad(); + } + + if(ratingEntity.getScoreLawEducation() == 150){ + ratingCompose.addLawGreat(); + }else if(ratingEntity.getScoreLawEducation() >= 130){ + ratingCompose.addLawGood(); + }else{ + ratingCompose.addLawBad(); + } + + if(ratingEntity.getScoreEmcManage() == 200){ + ratingCompose.addEmcGreat(); + }else if(ratingEntity.getScoreEmcManage() >= 170){ + ratingCompose.addEmcGood(); + }else{ + ratingCompose.addEmcBad(); + } + + if(ratingEntity.getScoreBonus() > 0){ + ratingCompose.addBonus(); + } + + } + + System.out.println("QueryCase " + JSON.toJSONString(ratingCompose)); + return new RespEntity(RespCode.SUCCESS, ratingCompose); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_rating/brigade",method = RequestMethod.POST) + public RespEntity getBrigadeStarRating(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarRatingEntity task = (SchoolStarRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + if(list == null){ + return new RespEntity(RespCode.SUCCESS, task); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS, task); + } + + int scoreTotal = 0; + int scoreInsideManage = 0; + int scoreOutsideManage = 0; + int scoreRiskManage = 0; + int scoreLawEducation = 0; + int scoreEmcManage = 0; + int scoreBonus = 0; + + for(int iSchool = 0; iSchool < schoolSize; iSchool++){ + SchoolStarRatingEntity ratingEntity = (SchoolStarRatingEntity)list.get(iSchool); + scoreTotal += ratingEntity.getScoreTotal(); + scoreInsideManage += ratingEntity.getScoreInsideManage(); + scoreOutsideManage += ratingEntity.getScoreOutsideManage(); + scoreRiskManage += ratingEntity.getScoreRiskManage(); + scoreLawEducation += ratingEntity.getScoreLawEducation(); + scoreEmcManage += ratingEntity.getScoreEmcManage(); + scoreBonus += ratingEntity.getScoreBonus(); + } + + task.setScoreTotal(scoreTotal/schoolSize); + task.setScoreInsideManage(scoreInsideManage/schoolSize); + task.setScoreOutsideManage(scoreOutsideManage/schoolSize); + task.setScoreRiskManage(scoreRiskManage/schoolSize); + task.setScoreLawEducation(scoreLawEducation/schoolSize); + task.setScoreEmcManage(scoreEmcManage/schoolSize); + task.setScoreBonus(scoreBonus/schoolSize); + + return new RespEntity(RespCode.SUCCESS, task); + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_rating/borough",method = RequestMethod.POST) + public RespEntity getBoroughStarRating(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarRatingEntity task = (SchoolStarRatingEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarRatingEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBorough()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = task.queryPage(dataSource, null, null, pageindex, pagesize); + + if(list == null){ + return new RespEntity(RespCode.SUCCESS, task); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS, task); + } + + int scoreTotal = 0; + int scoreInsideManage = 0; + int scoreOutsideManage = 0; + int scoreRiskManage = 0; + int scoreLawEducation = 0; + int scoreEmcManage = 0; + int scoreBonus = 0; + + for(int iSchool = 0; iSchool < schoolSize; iSchool++){ + SchoolStarRatingEntity ratingEntity = (SchoolStarRatingEntity)list.get(iSchool); + scoreTotal += ratingEntity.getScoreTotal(); + scoreInsideManage += ratingEntity.getScoreInsideManage(); + scoreOutsideManage += ratingEntity.getScoreOutsideManage(); + scoreRiskManage += ratingEntity.getScoreRiskManage(); + scoreLawEducation += ratingEntity.getScoreLawEducation(); + scoreEmcManage += ratingEntity.getScoreEmcManage(); + scoreBonus += ratingEntity.getScoreBonus(); + } + + task.setScoreTotal(scoreTotal/schoolSize); + task.setScoreInsideManage(scoreInsideManage/schoolSize); + task.setScoreOutsideManage(scoreOutsideManage/schoolSize); + task.setScoreRiskManage(scoreRiskManage/schoolSize); + task.setScoreLawEducation(scoreLawEducation/schoolSize); + task.setScoreEmcManage(scoreEmcManage/schoolSize); + task.setScoreBonus(scoreBonus/schoolSize); + + return new RespEntity(RespCode.SUCCESS, task); + } + + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_rating/summary",method = RequestMethod.POST) + public RespEntity getStarRatingSummary(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarDetailEntity task = (SchoolStarDetailEntity) SQLTools.getEntityFromJson(rootnode,SchoolStarDetailEntity.class); + + if(task==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(task.getBrigade()==null ||task.getSchoolTime() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = task.queryPage(dataSource, null, null, 0, 1000); + List summaryList = new ArrayList<>(); + if(list == null){ + return new RespEntity(RespCode.SUCCESS, summaryList); + } + int schoolSize = list.size(); + if(schoolSize == 0){ + return new RespEntity(RespCode.SUCCESS, summaryList); + } + + for(int iSchool = 0; iSchool < schoolSize; iSchool++){ + SchoolRatingSummary ratingSummary = new SchoolRatingSummary(); + SchoolStarDetailEntity ratingEntity = (SchoolStarDetailEntity)list.get(iSchool); + + ratingSummary.setBrigade(ratingEntity.getBrigade()); + ratingSummary.setBorough(ratingEntity.getBorough()); + ratingSummary.setDetachment(ratingEntity.getDetachment()); + ratingSummary.setStation(ratingEntity.getStation()); + + String checkDescription = ""; + if(ratingEntity.getInResponsibility() > 0){ + checkDescription += ratingEntity.getInResponsibilityDetail() + ";"; + } + + if(ratingEntity.getInTeamBuild() > 0){ + checkDescription += ratingEntity.getInTeamBuildDetail() + ";"; + } + + if(ratingEntity.getInDevicesSetup() > 0){ + checkDescription += ratingEntity.getInDevicesSetupDetail() + ";"; + } + + if(ratingEntity.getInFireManage() > 0){ + checkDescription += ratingEntity.getInFireManageDetail() + ";"; + } + + if(ratingEntity.getInDangerousManage() > 0){ + checkDescription += ratingEntity.getInDangerousManageDetail() + ";"; + } + + if(ratingEntity.getInSmartSecurity() > 0){ + checkDescription += ratingEntity.getInSmartSecurityDetail() + ";"; + } + + if(ratingEntity.getInSecurityScheme() > 0){ + checkDescription += ratingEntity.getInSecuritySchemeDetail() + ";"; + } + + if(ratingEntity.getOutPeakGuard() > 0){ + checkDescription += ratingEntity.getOutPeakGuardDetail() + ";"; + } + + if(ratingEntity.getOutRiskPrevent() > 0){ + checkDescription += ratingEntity.getOutRiskPreventDetail() + ";"; + } + + if(ratingEntity.getOutTraffic() > 0){ + checkDescription += ratingEntity.getOutTrafficDetail() + ";"; + } + + if(ratingEntity.getOutCaseManage() > 0){ + checkDescription += ratingEntity.getOutCaseManageDetail() + ";"; + } + + if(ratingEntity.getRiskDangerManage() > 0){ + checkDescription += ratingEntity.getRiskDangerManageDetail() + ";"; + } + + if(ratingEntity.getRiskConflictManage() > 0){ + checkDescription += ratingEntity.getRiskConflictManageDetail() + ";"; + } + + if(ratingEntity.getRiskProcess() > 0){ + checkDescription += ratingEntity.getRiskProcessDetail() + ";"; + } + + if(ratingEntity.getLawEducation() > 0){ + checkDescription += ratingEntity.getLawEducationDetail() + ";"; + } + + if(ratingEntity.getLawFirstClass() > 0){ + checkDescription += ratingEntity.getLawFirstClassDetail() + ";"; + } + + if(ratingEntity.getEmcPlan() > 0){ + checkDescription += ratingEntity.getEmcPlanDetail() + ";"; + } + + if(ratingEntity.getEmcDrill() > 0){ + checkDescription += ratingEntity.getEmcDrillDetail() + ";"; + } + + ratingSummary.setRatingDescriptionStation(checkDescription); + ratingSummary.setScoreTotalStation(ratingEntity.getScoreTotal()); + + ratingSummary.setRatingDescriptionBrigade(checkDescription); + ratingSummary.setScoreTotalBrigade(ratingSummary.getScoreTotalStation()); + + int scoreTotal = ratingSummary.getScoreTotalStation(); + int level = 5; + if(scoreTotal >= SchoolRatingSummary.School_Star_Level_1){ + level = 5; + }else if(scoreTotal >= SchoolRatingSummary.School_Star_Level_2){ + level = 4; + }else if(scoreTotal >= SchoolRatingSummary.School_Star_Level_3){ + level = 3; + }else if(scoreTotal >= SchoolRatingSummary.School_Star_Level_4){ + level = 2; + }else{ + level = 1; + } + ratingSummary.setLevelStation(level); + + scoreTotal = ratingSummary.getScoreTotalBrigade(); + if(scoreTotal >= SchoolRatingSummary.School_Star_Level_1){ + level = 5; + }else if(scoreTotal >= SchoolRatingSummary.School_Star_Level_2){ + level = 4; + }else if(scoreTotal >= SchoolRatingSummary.School_Star_Level_3){ + level = 3; + }else if(scoreTotal >= SchoolRatingSummary.School_Star_Level_4){ + level = 2; + }else{ + level = 1; + } + ratingSummary.setLevelBrigade(level); + + String checkBonus = ""; + if(ratingEntity.getBonus1() > 0){ + checkBonus += ratingEntity.getBonus1Detail() + ";"; + } + if(ratingEntity.getBonus2() > 0){ + checkBonus += ratingEntity.getBonus2Detail() + ";"; + } + if(ratingEntity.getBonus3() > 0){ + checkBonus += ratingEntity.getBonus3Detail() + ";"; + } + if(ratingEntity.getBonus4() > 0){ + checkBonus += ratingEntity.getBonus4Detail() + ";"; + } + if(ratingEntity.getBonus5() > 0){ + checkBonus += ratingEntity.getBonus5Detail() + ";"; + } + + ratingSummary.setRatingBonusBrigade(checkBonus); + ratingSummary.setRatingBonusStation(checkBonus); + ratingSummary.setRatingCasesStation(""); + ratingSummary.setRatingCasesBrigade(""); + + summaryList.add(ratingSummary); + } + + return new RespEntity(RespCode.SUCCESS, summaryList); + } + + + @ResponseBody + @RequestMapping(value="/iotserver/school/star_check_record/getlist",method = RequestMethod.POST) + public RespEntity getSchoolStarCheckRecordList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolStarDetailRecord schoolStarDetailRecord = (SchoolStarDetailRecord) SQLTools.getEntityFromJson(rootnode,SchoolStarDetailRecord.class); + + if(schoolStarDetailRecord==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(schoolStarDetailRecord.getBrigade()==null && schoolStarDetailRecord.getBorough()== null && schoolStarDetailRecord.getDetachment() == null && schoolStarDetailRecord.getStation()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = schoolStarDetailRecord.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + private void insertNewSchoolTime(String schoolTime, String type, String brigade){ + SchoolTimeLabelEntity timeLabelEntity = new SchoolTimeLabelEntity(); + timeLabelEntity.setSchoolTime(schoolTime); + timeLabelEntity.setType(type); + timeLabelEntity.setBrigade(brigade); + SchoolTimeLabelEntity oldLabel = (SchoolTimeLabelEntity)timeLabelEntity.QueryIt(dataSource); + if(oldLabel == null){ + timeLabelEntity.Insert(dataSource); + } + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/timelabel/getlist",method = RequestMethod.POST) + public RespEntity getSchoolTimeList(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + SchoolTimeLabelEntity timeLabelEntity = (SchoolTimeLabelEntity) SQLTools.getEntityFromJson(rootnode,SchoolTimeLabelEntity.class); + + if(timeLabelEntity==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(timeLabelEntity.getBrigade()==null || timeLabelEntity.getType() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 100; + if (pageindex < 0) + pageindex = 0; + + List list = timeLabelEntity.queryPage(dataSource, null, null, pageindex, pagesize); + + return new RespEntity(RespCode.SUCCESS, list); + } + + /* + sign target urls + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_target/getlist",method = RequestMethod.POST) + public RespEntity getSignTargetList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + GuardSignTargetEntity signTarget = (GuardSignTargetEntity)SQLTools.getEntityFromJson(rootnode,GuardSignTargetEntity.class); + + if(signTarget==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(signTarget.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 500; + if (pageindex < 0) + pageindex = 0; + + List list = signTarget.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_target/add",method = RequestMethod.POST) + public RespEntity addSignTargetInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + GuardSignTargetEntity per = (GuardSignTargetEntity) SQLTools.getEntityFromJson(rootnode, GuardSignTargetEntity.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getTargetId() == null ) + per.setTargetId(UUID.randomUUID().toString()); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(per), "/firectrl/school/sign_target/add"); + } + + if(per.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (per.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_target/add_brigade",method = RequestMethod.POST) + public RespEntity addBrigadeSignTargetInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + GuardSignTargetEntity per = (GuardSignTargetEntity) SQLTools.getEntityFromJson(rootnode, GuardSignTargetEntity.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + + FireStationBaseInfoEntity schoolStation = new FireStationBaseInfoEntity(); + schoolStation.setBrigade(per.getBrigade()); + + List schoolList = stationServices.queryStationList( schoolStation, 1000, 0); + + if(schoolList != null){ + for(int iSchool = 0; iSchool < schoolList.size(); iSchool++){ + FireStationBaseInfoEntity schoolObj = (FireStationBaseInfoEntity)schoolList.get(iSchool); + GuardSignTargetEntity newSignTgt = new GuardSignTargetEntity(); + newSignTgt.setBrigade(schoolObj.getBrigade()); + newSignTgt.setStation(schoolObj.getName()); + + List signTgtList = newSignTgt.queryPage(dataSource, null, null, 0, 200); + if(signTgtList != null){ + if(signTgtList.size() <= 0){ + newSignTgt.setTargetId(UUID.randomUUID().toString()); + newSignTgt.setTagId(UUID.randomUUID().toString()); + newSignTgt.setAddress(schoolObj.getAddress()); + newSignTgt.setBorough(schoolObj.getBorough()); + newSignTgt.setDetachment(schoolObj.getDetachment()); + newSignTgt.setLongitude(schoolObj.getLongitude()); + newSignTgt.setLatitude(schoolObj.getLatitude()); + newSignTgt.Insert(dataSource); + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(newSignTgt), "/firectrl/school/sign_target/add"); + } + } + } + } + } + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return new RespEntity(RespCode.SUCCESS); + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_target/delete",method = RequestMethod.POST) + public RespEntity deleteSignTargetInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + GuardSignTargetEntity per = (GuardSignTargetEntity) SQLTools.getEntityFromJson(rootnode, GuardSignTargetEntity.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getTargetId() == null || per.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(per), "/firectrl/school/sign_target/delete"); + } + if (per.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_target/update",method = RequestMethod.POST) + public RespEntity updateSignTargetInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + GuardSignTargetEntity per = (GuardSignTargetEntity) SQLTools.getEntityFromJson(rootnode, GuardSignTargetEntity.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getTargetId() == null || per.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(per), "/firectrl/school/sign_target/update"); + } + if (per.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_event/getlist",method = RequestMethod.POST) + public RespEntity getSignEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + GuardSignEventEntity signEvent = (GuardSignEventEntity)SQLTools.getEntityFromJson(rootnode,GuardSignEventEntity.class); + + if(signEvent==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(signEvent.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + String stationLevel = JsonHelper.getStringValue(rootnode, "level"); + + if(stationLevel != null){ + FireStationBaseInfoEntity impStation = new FireStationBaseInfoEntity(); + impStation.setBrigade(signEvent.getBrigade()); + impStation.setBorough(signEvent.getBorough()); + impStation.setDetachment(signEvent.getDetachment()); + impStation.setLevel(stationLevel); + + List schoolList = stationServices.queryStationList( impStation, 1000, 0); + + List listEvent = new ArrayList<>(); + if(schoolList != null){ + for(int iSchool = 0; iSchool < schoolList.size(); iSchool++){ + FireStationBaseInfoEntity schoolObj = (FireStationBaseInfoEntity)schoolList.get(iSchool); + signEvent.setStation(schoolObj.getName()); + signEvent.setBrigade(schoolObj.getBrigade()); + signEvent.setBorough(schoolObj.getBorough()); + signEvent.setDetachment(schoolObj.getDetachment()); + List stationEvents = signEvent.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + listEvent.addAll(stationEvents); + } + } + return new RespEntity(RespCode.SUCCESS, listEvent); + }else{ + List list = signEvent.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + } + + + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_event_imp/getlist",method = RequestMethod.POST) + public RespEntity getSignEventImpList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + GuardSignEventEntity signEvent = (GuardSignEventEntity)SQLTools.getEntityFromJson(rootnode,GuardSignEventEntity.class); + + if(signEvent==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(signEvent.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + String stationLevel = JsonHelper.getStringValue(rootnode, "level"); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + FireStationBaseInfoEntity impStation = new FireStationBaseInfoEntity(); + impStation.setBrigade(signEvent.getBrigade()); + impStation.setBorough(signEvent.getBorough()); + impStation.setDetachment(signEvent.getDetachment()); + if(stationLevel != null){ + impStation.setLevel(stationLevel); + } + + List schoolList = stationServices.queryStationList( impStation, 1000, 0); + + List listEvent = new ArrayList<>(); + if(schoolList != null){ + for(int iSchool = 0; iSchool < schoolList.size(); iSchool++){ + FireStationBaseInfoEntity schoolObj = (FireStationBaseInfoEntity)schoolList.get(iSchool); + signEvent.setStation(schoolObj.getName()); + signEvent.setBrigade(schoolObj.getBrigade()); + signEvent.setBorough(schoolObj.getBorough()); + signEvent.setDetachment(schoolObj.getDetachment()); + List stationEvents = signEvent.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + listEvent.addAll(stationEvents); + } + } + return new RespEntity(RespCode.SUCCESS, listEvent); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/sign_event/getcount",method = RequestMethod.POST) + public RespEntity countSignEventList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + GuardSignEventEntity signEvent = (GuardSignEventEntity)SQLTools.getEntityFromJson(rootnode,GuardSignEventEntity.class); + + if(signEvent==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(signEvent.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + System.out.println("countSignEventList: " + signEvent.getBrigade()); + System.out.println("countSignEventList: " + startstr); + System.out.println("countSignEventList: " + endstr); + + int count = signEvent.queryCount(dataSource,startstr,endstr); + CountResult countobj = new CountResult(); + countobj.setCount(count); + + System.out.println("countSignEventList: " + count); + return new RespEntity(RespCode.SUCCESS, countobj); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/iotserver/school/guard_sign/sign",method = RequestMethod.POST) + public RespEntity addGuardSignEvent(HttpServletRequest request) { + RespEntity rel = null; + + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + GuardSignEventEntity signEvent = (GuardSignEventEntity) SQLTools.getEntityFromJson(rootnode, GuardSignEventEntity.class); + System.out.println("addGuardSignEvent: " + rootnode.toString()); + + + if (signEvent == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + if (FireCtrlSystemInit.netMode == 1) { + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(signEvent), "/iotserver/school/guard_sign/sign"); + dataStatisticsService.addGuardSignAgentMessage(signEvent); + } + + if (signEvent.getTagId() == null || signEvent.getPersonId() == null || signEvent.getPersonType() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + GuardSignTargetEntity signTarget = new GuardSignTargetEntity(signEvent.getTagId()); + List listTarget = signTarget.queryPage(dataSource, null, null, 0, 100); + if (listTarget == null) { + return new RespEntity(RespCode.NOTEXIST); + } + if (listTarget.size() == 0) { + return new RespEntity(RespCode.NOTEXIST); + } + + signTarget = (GuardSignTargetEntity) listTarget.get(0); + if (signTarget == null) { + return new RespEntity(RespCode.NOTEXIST); + } + System.out.println("addGuardSignEvent: " + signTarget.getTargetId()); + + signEvent.setTargetId(signTarget.getTargetId()); + if (signEvent.getSignTimestamp() == null) { + signEvent.setSignTimestamp(new Date()); + } + + PolicemanInfo policemanInfo = new PolicemanInfo(); + policemanInfo.setId(signEvent.getPersonId()); + policemanInfo = (PolicemanInfo) policemanInfo.QueryIt(dataSource); + if (policemanInfo != null) { + policemanInfo.setSignTimestamp(signEvent.getSignTimestamp()); + policemanInfo.Update(dataSource); + } + + switch (signEvent.getPersonType()) { + case PolicemanInfo.TYPE_Volunteer: { + boolean signState = peakVolunteerSign(signEvent, signTarget); + if (signState == true) { + return new RespEntity(RespCode.SUCCESS, signTarget); + } else { + return new RespEntity(RespCode.EXIST, signTarget); + } + } + case PolicemanInfo.TYPE_PoliceManager: + case PolicemanInfo.TYPE_Policeman: { + boolean signState = peakPolicemenSign(signEvent, signTarget); + if (signState == true) { + return new RespEntity(RespCode.SUCCESS, signTarget); + } else { + return new RespEntity(RespCode.EXIST, signTarget); + } + } + case PolicemanInfo.TYPE_SchoolManager: + case PolicemanInfo.TYPE_Guarder: { + boolean signState = peakGuardSign(signEvent, signTarget); + if (signState == true) { + return new RespEntity(RespCode.SUCCESS, signTarget); + } else { + return new RespEntity(RespCode.EXIST, signTarget); + } + } + default:{ + boolean signState = peakVolunteerSign(signEvent, signTarget); + if (signState == true) { + return new RespEntity(RespCode.SUCCESS, signTarget); + } else { + return new RespEntity(RespCode.EXIST, signTarget); + } + } + } + + // return new RespEntity(RespCode.SUCCESS); + } + + private boolean peakVolunteerSign(GuardSignEventEntity signEvent, GuardSignTargetEntity signTarget){ + Calendar signDayTime = Calendar.getInstance(); + signDayTime.setTime(signEvent.getSignTimestamp()); + int nYear = signDayTime.get(Calendar.YEAR); + int nMonth = signDayTime.get(Calendar.MONTH)+1; + int nDay = signDayTime.get(Calendar.DAY_OF_MONTH); + int nHour = signDayTime.get(Calendar.HOUR_OF_DAY); + + String signEventId = signEvent.getPersonId()+ "_" + signTarget.getTargetId() + "_" + signEvent.getSignTimestamp().getTime(); + signEvent.setSignId(signEventId); + + signEvent.setTaskId("non"); + signEvent.setYear(nYear); + signEvent.setMonth(nMonth); + signEvent.setDay(nDay); + signEvent.setBrigade(signTarget.getBrigade()); + signEvent.setBorough(signTarget.getBorough()); + signEvent.setDetachment(signTarget.getDetachment()); + signEvent.setStation(signTarget.getStation()); + signEvent.Insert(dataSource); + sendSignNotify(signEvent); + StatisticsMessage msg = new StatisticsMessage(); + msg.setCode(StatisticsMessage.School_Volunteer_Sign); + msg.setStation(signTarget.getStation()); + dataStatisticsService.addStatisticsMessage(msg); + return true; + } + + private boolean peakPolicemenSign(GuardSignEventEntity signEvent, GuardSignTargetEntity signTarget){ + Calendar signDayTime = Calendar.getInstance(); + signDayTime.setTime(signEvent.getSignTimestamp()); + int nYear = signDayTime.get(Calendar.YEAR); + int nMonth = signDayTime.get(Calendar.MONTH)+1; + int nDay = signDayTime.get(Calendar.DAY_OF_MONTH); + int nHour = signDayTime.get(Calendar.HOUR_OF_DAY); + + String signEventId = signEvent.getPersonId()+ "_" + signTarget.getTargetId() + "_" + signEvent.getSignTimestamp().getTime(); + signEvent.setSignId(signEventId); + + signEvent.setTaskId("non"); + signEvent.setYear(nYear); + signEvent.setMonth(nMonth); + signEvent.setDay(nDay); + signEvent.setBrigade(signTarget.getBrigade()); + signEvent.setBorough(signTarget.getBorough()); + signEvent.setDetachment(signTarget.getDetachment()); + signEvent.setStation(signTarget.getStation()); + + signEvent.Insert(dataSource); + + sendSignNotify(signEvent); + StatisticsMessage msg = new StatisticsMessage(); + msg.setCode(StatisticsMessage.School_Policeman_Sign); + msg.setStation(signTarget.getStation()); + dataStatisticsService.addStatisticsMessage(msg); + return true; + } + + private boolean peakGuardSign(GuardSignEventEntity signEvent, GuardSignTargetEntity signTarget){ + Calendar signDayTime = Calendar.getInstance(); + signDayTime.setTime(signEvent.getSignTimestamp()); + int nYear = signDayTime.get(Calendar.YEAR); + int nMonth = signDayTime.get(Calendar.MONTH)+1; + int nDay = signDayTime.get(Calendar.DAY_OF_MONTH); + int nHour = signDayTime.get(Calendar.HOUR_OF_DAY); + + String signEventId = signEvent.getPersonId()+ "_" + signTarget.getTargetId() + "_" + signEvent.getSignTimestamp().getTime(); + signEvent.setSignId(signEventId); + + signEvent.setTaskId("non"); + signEvent.setYear(nYear); + signEvent.setMonth(nMonth); + signEvent.setDay(nDay); + signEvent.setBrigade(signTarget.getBrigade()); + signEvent.setBorough(signTarget.getBorough()); + signEvent.setDetachment(signTarget.getDetachment()); + signEvent.setStation(signTarget.getStation()); + signEvent.Insert(dataSource); + + sendSignNotify(signEvent); + + StatisticsMessage msg = new StatisticsMessage(); + msg.setCode(StatisticsMessage.School_Guard_Sign); + msg.setStation(signTarget.getStation()); + dataStatisticsService.addStatisticsMessage(msg); + return true; + } + + private void sendSignNotify(GuardSignEventEntity signEvent){ + GuardSignEventNotify eventNotify = new GuardSignEventNotify(signEvent); + + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, signEvent.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(eventNotify.getPersonName()); + pro.setDevice_type(eventNotify.getPersonType()); + eventNotify.attachProperty(pro); + clientWebsocketManager.addWebNotify(eventNotify); + } + } + + + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/add",method = RequestMethod.POST) + public RespEntity addPolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (FireCtrlSystemInit.netMode == 1) { + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(per), "/firectrl/school/policeman/add"); + } + + if(per.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + per.setUserState(PolicemanInfo.STATE_NEW); + if (per.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/login",method = RequestMethod.POST) + public RespEntity loginPolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getPassword() == null) + return new RespEntity(RespCode.ERROR_CMD); + + PolicemanInfo perIegel = (PolicemanInfo)per.QueryIt(dataSource); + if(perIegel!=null){ + if(!PolicemanInfo.STATE_REG.equalsIgnoreCase(perIegel.getUserState()) ){ + return new RespEntity(RespCode.NOAUTHOR, "账号未审批"); + } + + if(PolicemanInfo.ACCOUNT_TYPE_WeChat.equalsIgnoreCase(perIegel.getAccountType())){ + perIegel.setPassword(""); + return new RespEntity(RespCode.SUCCESS, perIegel); + }else{ + if(perIegel.getPassword() == null){ + return new RespEntity(RespCode.SUCCESS, perIegel); + } + if(perIegel.getPassword().equals(per.getPassword()) ){ + perIegel.setPassword(""); + return new RespEntity(RespCode.SUCCESS, perIegel); + } + return new RespEntity(RespCode.USER_PWD_ERROR); + } + + } + rel = new RespEntity(RespCode.NOTEXIST); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/wechat/login",method = RequestMethod.POST) + public RespEntity loginPolicemanByWechat(HttpServletRequest request) { + RespEntity rel = null; + try { + + String codeStr = HttpTools.getBodyFromRequest(request); + WechatAccountInfo accountInfo = JSON.parseObject(codeStr, WechatAccountInfo.class); + if(accountInfo == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + if(accountInfo.getCode() == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + String params = "appid=" + wechat_appId + "&secret=" + wechat_secret + "&js_code=" + accountInfo.getCode() + "&grant_type=authorization_code"; + + try { + String agentUrlLong = "https://api.weixin.qq.com/sns/jscode2session?" + params ; + System.out.println("process getWechatOpenId: url = " + agentUrlLong); + + OkHttpClient okHttpClient = new OkHttpClient(); + Request okRequest = new Request.Builder().url(agentUrlLong).build(); + Response response = okHttpClient.newCall(okRequest).execute(); + + if(response.isSuccessful()){ + String body = response.body().string(); + System.out.println("getWechatOpenId: ok = " + body); + + String wechatOpenId = ""; + JSONObject jsonObject = JSONObject.parseObject(body); + if(!jsonObject.containsKey("openid")){ + return new RespEntity(RespCode.FAIL, "openid error"); + } + wechatOpenId = jsonObject.getString("openid"); + PolicemanInfo wechatAccount = new PolicemanInfo(); + wechatAccount.setId(wechatOpenId); + + PolicemanInfo perIegel = (PolicemanInfo)wechatAccount.QueryIt(dataSource); + if(perIegel!=null){ + if(PolicemanInfo.STATE_REG.equalsIgnoreCase(perIegel.getUserState()) ){ + perIegel.setPassword(""); + return new RespEntity(RespCode.SUCCESS, perIegel); + } + + return new RespEntity(RespCode.NOAUTHOR, "账号未审批"); + }else{ + return new RespEntity(RespCode.NOTEXIST, wechatOpenId); + } + }else{ + return new RespEntity(RespCode.FAIL, "获取微信账号失败"); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("getWechatOpenId: fail = " + e.getMessage()); + } + return new RespEntity(RespCode.EXCEPTION); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/register",method = RequestMethod.POST) + public RespEntity registerPolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getUserState() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (FireCtrlSystemInit.netMode == 1) { + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(per), "/firectrl/school/policeman/register"); + } + + PolicemanInfo perIegel = (PolicemanInfo)per.QueryIt(dataSource); + if(perIegel == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(per.getUserState().equalsIgnoreCase(perIegel.getUserState())){ + return new RespEntity(RespCode.EXIST); + } + perIegel.setUserState(per.getUserState()); + + if (perIegel.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/update",method = RequestMethod.POST) + public RespEntity modifyPolicemanInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PolicemanInfo per = (PolicemanInfo) SQLTools.getEntityFromJson(rootnode, PolicemanInfo.class); + if (per == null) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getId() == null || per.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (FireCtrlSystemInit.netMode == 1) { + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(per), "/firectrl/school/policeman/update"); + } + + PolicemanInfo perIegel = (PolicemanInfo)per.QueryIt(dataSource); + if(perIegel == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (per.Update(dataSource)) { + perIegel = (PolicemanInfo)per.QueryIt(dataSource); + perIegel.setPassword(""); + rel = new RespEntity(RespCode.SUCCESS, perIegel); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/getnewlist",method = RequestMethod.POST) + public RespEntity getNewPolicemanList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PolicemanInfo policemanInfo = (PolicemanInfo)SQLTools.getEntityFromJson(rootnode,PolicemanInfo.class); + + if(policemanInfo==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(policemanInfo.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + //policemanInfo.setUserState(PolicemanInfo.STATE_NEW); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = policemanInfo.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/policeman/summary",method = RequestMethod.POST) + public RespEntity getPolicemanSummary(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughEntity boroughCond = (BoroughEntity)SQLTools.getEntityFromJson(rootnode,BoroughEntity.class); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + if(boroughCond==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(boroughCond.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List boroughList = boroughCond.queryList(dataSource,null,null); + List boroughPoliceSummaryList = new ArrayList<>(); + if(boroughList != null) { + // System.out.println("process getPolicemanSummary: borough count = " + boroughList.size()); + for (int iBorough = 0; iBorough < boroughList.size(); iBorough++) { + BoroughEntity boroughObj = (BoroughEntity) boroughList.get(iBorough); + + FireStationBaseInfoEntity schoolStation = new FireStationBaseInfoEntity(); + schoolStation.setBrigade(boroughCond.getBrigade()); + schoolStation.setBorough(boroughObj.getBorough()); + + BoroughPoliceSummary boroughSum = new BoroughPoliceSummary(); + boroughSum.setBorough(boroughObj.getBorough()); + + List schoolSummaryList = new ArrayList<>(); + int guardCount = 0; + int policeCount = 0; + int volunteerCount = 0; + int teacherCount = 0; + + int guardSignCount = 0; + int policeSignCount = 0; + int volunteerSignCount = 0; + int teacherSignCount = 0; + + int newsPeakGuardBorough = 0; + int newsLawBorough = 0; + int newsExerciseBorough = 0; + int newsOtherBorough = 0; + + List schoolList = stationServices.queryStationList( schoolStation, 1000, 0); + if(schoolList != null){ + for(int iSchool = 0; iSchool < schoolList.size(); iSchool++){ + FireStationBaseInfoEntity schoolObj = (FireStationBaseInfoEntity)schoolList.get(iSchool); + + PolicemanInfo schoolPolice = new PolicemanInfo(); + schoolPolice.setBrigade(schoolObj.getBrigade()); + schoolPolice.setBorough(schoolObj.getBorough()); + schoolPolice.setStation(schoolObj.getName()); + + SchoolPoliceSummary schoolSummary = new SchoolPoliceSummary(); + schoolSummary.setStation(schoolObj.getName()); + + List personList = schoolPolice.queryPage(dataSource, null, null, 0, 1000); + + int guardCountSchool = 0; + int policeCountSchool = 0; + int volunteerCountSchool = 0; + int teacherCountSchool = 0; + if(personList != null){ + for(int iPer = 0; iPer < personList.size(); iPer++){ + PolicemanInfo tgtPerson = (PolicemanInfo)personList.get(iPer); + if(tgtPerson.getPersonType() != null){ + switch (tgtPerson.getPersonType()){ + case PolicemanInfo.TYPE_Guarder:guardCountSchool += 1;break; + case PolicemanInfo.TYPE_Policeman: + case PolicemanInfo.TYPE_PoliceManager:policeCountSchool += 1;break; + case PolicemanInfo.TYPE_Volunteer:volunteerCountSchool += 1;break; + case PolicemanInfo.TYPE_SchoolManager:teacherCountSchool += 1;break; + } + } + } + } + schoolSummary.setPoliceCount(policeCountSchool); + schoolSummary.setGuardCount(guardCountSchool); + schoolSummary.setVolunteerCount( volunteerCountSchool); + schoolSummary.setTeacherCount( teacherCountSchool); + + policeCount += schoolSummary.getPoliceCount(); + guardCount += schoolSummary.getGuardCount(); + volunteerCount += schoolSummary.getVolunteerCount(); + teacherCount += schoolSummary.getTeacherCount(); + + GuardSignEventEntity signEvent = new GuardSignEventEntity(); + signEvent.setStation(schoolObj.getName()); + signEvent.setYear(-1); + signEvent.setMonth(-1); + signEvent.setDay(-1); + + List signList = signEvent.queryPage(dataSource, startstr, endstr, 0, 1000); + int guardSignSchool = 0; + int policeSignSchool = 0; + int volunteerSignSchool = 0; + int teacherSignSchool = 0; + if(personList != null){ + for(int iSign= 0; iSign < signList.size(); iSign++){ + GuardSignEventEntity tgtSign = (GuardSignEventEntity)signList.get(iSign); + if(tgtSign.getPersonType() != null){ + switch (tgtSign.getPersonType()){ + case PolicemanInfo.TYPE_Guarder:guardSignSchool += 1;break; + case PolicemanInfo.TYPE_Policeman: + case PolicemanInfo.TYPE_PoliceManager:policeSignSchool += 1;break; + case PolicemanInfo.TYPE_Volunteer:volunteerSignSchool += 1;break; + case PolicemanInfo.TYPE_SchoolManager:teacherSignSchool += 1;break; + } + } + } + } + + schoolSummary.setPoliceSignCount(policeSignSchool); + schoolSummary.setGuardSignCount(guardSignSchool); + schoolSummary.setVolunteerSignCount(volunteerSignSchool); + schoolSummary.setTeacherSignCount(teacherSignSchool); + + SchoolNewsEntity schoolNews =new SchoolNewsEntity(); + schoolNews.setStation(schoolObj.getName()); + schoolNews.setBrigade(schoolObj.getBrigade()); + schoolNews.setBorough(schoolObj.getBorough()); + + List listSchoolNews = schoolNews.queryPage(dataSource, startstr, endstr, 0, 1000); + int newsPeakGuard = 0; + int newsLaw = 0; + int newsExercise = 0; + int newsOther = 0; + if(listSchoolNews != null){ + for(int iNews = 0; iNews < listSchoolNews.size(); iNews++){ + SchoolNewsEntity tgtNews = (SchoolNewsEntity)listSchoolNews.get(iNews); + if(tgtNews.getType() == null){ + newsOther += 1; + }else{ + switch (tgtNews.getType()){ + case SchoolNewsEntity.TYPE_PeakGuard:newsPeakGuard += 1;break; + case SchoolNewsEntity.TYPE_Law:newsLaw += 1;break; + case SchoolNewsEntity.TYPE_Exercise:newsExercise += 1;break; + default:newsOther += 1;break; + } + } + } + } + schoolSummary.setNewsPeakGuard(newsPeakGuard); + schoolSummary.setNewsLaw(newsLaw); + schoolSummary.setNewsExercise(newsExercise); + schoolSummary.setNewsOther(newsOther); + schoolSummaryList.add(schoolSummary); + + guardSignCount += schoolSummary.getGuardSignCount(); + policeSignCount += schoolSummary.getPoliceSignCount(); + volunteerSignCount+= schoolSummary.getVolunteerSignCount(); + teacherSignCount += schoolSummary.getTeacherSignCount(); + newsPeakGuardBorough += schoolSummary.getNewsPeakGuard(); + newsLawBorough += schoolSummary.getNewsLaw(); + newsExerciseBorough += schoolSummary.getNewsExercise(); + newsOtherBorough += schoolSummary.getNewsOther(); + } + } + boroughSum.setGuardCount(guardCount); + boroughSum.setPoliceCount(policeCount); + boroughSum.setVolunteerCount(volunteerCount); + boroughSum.setTeacherCount(teacherCount); + boroughSum.setGuardSignCount(guardSignCount); + boroughSum.setPoliceSignCount(policeSignCount); + boroughSum.setVolunteerSignCount(volunteerSignCount); + boroughSum.setTeacherSignCount(teacherSignCount); + boroughSum.setNewsPeakGuard(newsPeakGuardBorough); + boroughSum.setNewsLaw(newsLawBorough); + boroughSum.setNewsExercise(newsExerciseBorough); + boroughSum.setNewsOther(newsOtherBorough); + + boroughSum.setSchoolSummaryList(schoolSummaryList); + boroughPoliceSummaryList.add(boroughSum); + } + + } + + return new RespEntity(RespCode.SUCCESS, boroughPoliceSummaryList); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/importantstation/getlist",method = RequestMethod.POST) + public RespEntity getImportantStationList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + ImportantStation importantStation = (ImportantStation)SQLTools.getEntityFromJson(rootnode,ImportantStation.class); + + if(importantStation==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(importantStation.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = importantStation.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/importantstation/add",method = RequestMethod.POST) + public RespEntity addImportantStationInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + ImportantStation importantStation = (ImportantStation) SQLTools.getEntityFromJson(rootnode, ImportantStation.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getName() == null || importantStation.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (importantStation.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/importantstation/update",method = RequestMethod.POST) + public RespEntity updateImportantStationInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + ImportantStation importantStation = (ImportantStation) SQLTools.getEntityFromJson(rootnode, ImportantStation.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (importantStation.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/importantstation/delete",method = RequestMethod.POST) + public RespEntity deleteImportantStationInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + ImportantStation importantStation = (ImportantStation) SQLTools.getEntityFromJson(rootnode, ImportantStation.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (importantStation.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + skynet ipc alarm fence + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/skynetfence/getlist",method = RequestMethod.POST) + public RespEntity getSkynetFenceList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + AlarmFenceEntity importantStation = (AlarmFenceEntity)SQLTools.getEntityFromJson(rootnode,AlarmFenceEntity.class); + + if(importantStation==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(importantStation.getBrigade()==null && importantStation.getBorough() == null && importantStation.getDetachment() == null ) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = importantStation.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/skynetfence/add",method = RequestMethod.POST) + public RespEntity addSkynetFenceInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + AlarmFenceEntity importantStation = (AlarmFenceEntity) SQLTools.getEntityFromJson(rootnode, AlarmFenceEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (importantStation.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/skynetfence/get",method = RequestMethod.POST) + public RespEntity getSkynetFenceInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + AlarmFenceEntity importantStation = (AlarmFenceEntity) SQLTools.getEntityFromJson(rootnode, AlarmFenceEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + + AlarmFenceEntity retFence = (AlarmFenceEntity)importantStation.QueryIt(dataSource); + if(retFence == null){ + return new RespEntity(RespCode.NOTEXIST); + } + return new RespEntity(RespCode.SUCCESS, retFence); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/skynet_sim/alarm",method = RequestMethod.POST) + public RespEntity addSkynetAarlm(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SensorAlarmEventEntity simAlarm = (SensorAlarmEventEntity) SQLTools.getEntityFromJson(rootnode, SensorAlarmEventEntity.class); + if (simAlarm == null) + return new RespEntity(RespCode.ERROR_CMD); + if (simAlarm.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + + simAlarm.Insert(dataSource); + + SkynetIPCEntity sensor = SkynetIPCEntity.Query(dataSource, simAlarm.getDeviceId()); + if (sensor == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + System.out.println("skynet ipc: "+JSON.toJSONString(sensor)); + FireStationBaseInfoEntity stationInfo = FireStationBaseInfoEntity.Query(dataSource, sensor.getStation()); + if (stationInfo == null) { + return new RespEntity(RespCode.ERROR_CMD); + } + + SensorEventNotify notify = new SensorEventNotify(simAlarm); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(stationInfo.getBrigade()); + pro.setBorough(stationInfo.getBorough()); + pro.setDetachment(stationInfo.getDetachment()); + pro.setStation(stationInfo.getName()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(sensor.getDeviceType()); + notify.attachProperty(pro); + System.out.println("websocket send sensor event: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + dataStatisticsService.addSensorAlarmEvent(stationInfo, simAlarm); + + return new RespEntity(RespCode.SUCCESS); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/get_brigade_list",method = RequestMethod.POST) + public RespEntity getBrigadeList(HttpServletRequest request) { + RespEntity rel = null; + try { + BrigadeEntity brigade = null; + try{ + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + brigade = (BrigadeEntity) SQLTools.getEntityFromJson(rootnode, BrigadeEntity.class); + } + }catch (Exception ee) { + + } + if(brigade==null) + brigade = new BrigadeEntity(); + List list = brigade.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + rel = new RespEntity(RespCode.SUCCESS,list); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/get_borough_list",method = RequestMethod.POST) + public RespEntity getBoroughList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + BoroughEntity borough = (BoroughEntity)SQLTools.getEntityFromJson(rootnode,BoroughEntity.class); + if(borough == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + if(borough.getBrigade() == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + + List list = borough.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + rel = new RespEntity(RespCode.SUCCESS,list); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/get_station_list",method = RequestMethod.POST) + public RespEntity getStationList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity schoolStation = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode, FireStationBaseInfoEntity.class); + if(schoolStation == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + if(schoolStation.getBrigade() == null || schoolStation.getBorough() == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + + List list = schoolStation.queryList(dataSource,null,null); + if(list!=null&&list.size()>0) + rel = new RespEntity(RespCode.SUCCESS,list); + else + rel = new RespEntity(RespCode.FAIL); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + school news report api + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/news/getlist",method = RequestMethod.POST) + public RespEntity getSchoolNewsList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SchoolNewsEntity importantStation = (SchoolNewsEntity)SQLTools.getEntityFromJson(rootnode,SchoolNewsEntity.class); + + if(importantStation==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(importantStation.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = importantStation.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/getlast",method = RequestMethod.POST) + public RespEntity getSchoolNewsLast(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SchoolNewsEntity importantStation = (SchoolNewsEntity)SQLTools.getEntityFromJson(rootnode,SchoolNewsEntity.class); + + if(importantStation==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(importantStation.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + importantStation.setStatus(SchoolNewsEntity.STATE_OPEN); + int limitCount = JsonHelper.getIntValue(rootnode, "limit"); + if(limitCount <= 0){ + limitCount = 2; + } + + List list = importantStation.QueryLasts(dataSource, limitCount); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/add",method = RequestMethod.POST) + public RespEntity addSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolNewsEntity schoolNewsEntity = (SchoolNewsEntity) SQLTools.getEntityFromJson(rootnode, SchoolNewsEntity.class); + if (schoolNewsEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (schoolNewsEntity.getStation() == null || schoolNewsEntity.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(schoolNewsEntity.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if(schoolNewsEntity.getNewsId() == null){ + schoolNewsEntity.setNewsId(UUID.randomUUID().toString()); + } + schoolNewsEntity.setTimestamp(new Date()); + schoolNewsEntity.setStatus(SchoolNewsEntity.STATE_HIDE); + if (schoolNewsEntity.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(schoolNewsEntity.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(schoolNewsEntity.getTimestamp()); + newOp.setPersonName(schoolNewsEntity.getCreator()); + newOp.setPersonId(schoolNewsEntity.getCreatorId()); + newOp.setOp(NewsOpRecordEntity.OP_CREATE); + newOp.setData(""); + newOp.Insert(dataSource); + + if(FireCtrlSystemInit.netMode == 1){ + System.out.println("agentFile2Skynet: start 1 = "); + + if(schoolNewsEntity.getPost() != null && !schoolNewsEntity.getStation().equalsIgnoreCase(schoolNewsEntity.getPost())){ + FireStationBaseInfoEntity school = new FireStationBaseInfoEntity(); + school.setName(schoolNewsEntity.getPost()); + school = (FireStationBaseInfoEntity)school.QueryIt(dataSource); + if(school!=null){ + schoolNewsEntity.setBorough(school.getBorough()); + schoolNewsEntity.setBrigade(school.getBrigade()); + schoolNewsEntity.setDetachment(school.getDetachment()); + schoolNewsEntity.setStation(school.getName()); + + schoolNewsEntity.setNewsId(UUID.randomUUID().toString()); + schoolNewsEntity.Insert(dataSource); + } + } + + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(schoolNewsEntity), "/firectrl/school/news/add"); + dataStatisticsService.addNewsAgentMessage(schoolNewsEntity); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/update",method = RequestMethod.POST) + public RespEntity updateSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolNewsEntity importantStation = (SchoolNewsEntity) SQLTools.getEntityFromJson(rootnode, SchoolNewsEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getNewsId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(importantStation.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + newOp.setPersonName(importantStation.getCreator()); + newOp.setPersonId(importantStation.getCreatorId()); + newOp.setOp(NewsOpRecordEntity.OP_MODIFY); + newOp.setData(""); + newOp.Insert(dataSource); + + if (importantStation.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/open",method = RequestMethod.POST) + public RespEntity openSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolNewsEntity importantStation = (SchoolNewsEntity) SQLTools.getEntityFromJson(rootnode, SchoolNewsEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getNewsId() == null || importantStation.getChecker() == null ) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + importantStation.setStatus(SchoolNewsEntity.STATE_OPEN); + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(importantStation.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + newOp.setPersonName(importantStation.getChecker()); + newOp.setPersonId(importantStation.getChecker()); + newOp.setOp(NewsOpRecordEntity.OP_SET_OPEN); + newOp.setData(""); + newOp.Insert(dataSource); + + if (importantStation.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/hide",method = RequestMethod.POST) + public RespEntity hideSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolNewsEntity importantStation = (SchoolNewsEntity) SQLTools.getEntityFromJson(rootnode, SchoolNewsEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getNewsId() == null || importantStation.getChecker() == null ) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + importantStation.setStatus(SchoolNewsEntity.STATE_HIDE); + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(importantStation.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + newOp.setPersonName(importantStation.getChecker()); + newOp.setPersonId(importantStation.getChecker()); + newOp.setOp(NewsOpRecordEntity.OP_SET_HIDE); + newOp.setData(""); + newOp.Insert(dataSource); + + if (importantStation.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/delete",method = RequestMethod.POST) + public RespEntity deleteSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolNewsEntity importantStation = (SchoolNewsEntity) SQLTools.getEntityFromJson(rootnode, SchoolNewsEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getNewsId() == null || importantStation.getChecker() == null ) + return new RespEntity(RespCode.ERROR_CMD); + + SchoolNewsEntity srcObj = (SchoolNewsEntity)importantStation.QueryIt(dataSource); + if(srcObj == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(importantStation.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + if(importantStation.getChecker().equals(srcObj.getCreatorId())){ + newOp.setPersonName(srcObj.getCreator()); + } + + newOp.setPersonId(importantStation.getChecker()); + newOp.setOp(NewsOpRecordEntity.OP_DELETE); + newOp.setData(""); + newOp.Insert(dataSource); + + if (importantStation.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + /* + 芙蓉公安新闻接口 + */ + @ResponseBody + @RequestMapping(value="/firectrl/police/news/getlist",method = RequestMethod.POST) + public RespEntity getPoliceNewsList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PoliceNewsEntity policeNews = (PoliceNewsEntity)SQLTools.getEntityFromJson(rootnode,PoliceNewsEntity.class); + + if(policeNews==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(policeNews.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = policeNews.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/getlast",method = RequestMethod.POST) + public RespEntity getPoliceNewsLast(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PoliceNewsEntity policeNews = (PoliceNewsEntity)SQLTools.getEntityFromJson(rootnode,PoliceNewsEntity.class); + + if(policeNews==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(policeNews.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int limitCount = JsonHelper.getIntValue(rootnode, "limit"); + if(limitCount <= 0){ + limitCount = 2; + } + + List list = policeNews.QueryLasts(dataSource, limitCount); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/add",method = RequestMethod.POST) + public RespEntity addPoliceNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PoliceNewsEntity policeNews = (PoliceNewsEntity) SQLTools.getEntityFromJson(rootnode, PoliceNewsEntity.class); + if (policeNews == null) + return new RespEntity(RespCode.ERROR_CMD); + if (policeNews.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(policeNews.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if(policeNews.getNewsId() == null){ + policeNews.setNewsId(UUID.randomUUID().toString()); + } + policeNews.setTimestamp(new Date()); + if (policeNews.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/update",method = RequestMethod.POST) + public RespEntity updatePoliceNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PoliceNewsEntity policeNews = (PoliceNewsEntity) SQLTools.getEntityFromJson(rootnode, PoliceNewsEntity.class); + if (policeNews == null) + return new RespEntity(RespCode.ERROR_CMD); + if (policeNews.getNewsId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(policeNews.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (policeNews.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/delete",method = RequestMethod.POST) + public RespEntity deletePoliceNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PoliceNewsEntity policeNews = (PoliceNewsEntity) SQLTools.getEntityFromJson(rootnode, PoliceNewsEntity.class); + if (policeNews == null) + return new RespEntity(RespCode.ERROR_CMD); + if (policeNews.getNewsId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(policeNews.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (policeNews.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + 新闻点赞接口 + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/news/praise",method = RequestMethod.POST) + public RespEntity praiseSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolNewsEntity schoolNews = (SchoolNewsEntity) SQLTools.getEntityFromJson(rootnode, SchoolNewsEntity.class); + if (schoolNews == null) + return new RespEntity(RespCode.ERROR_CMD); + if (schoolNews.getNewsId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + SchoolNewsEntity schoolNewsDst = (SchoolNewsEntity)schoolNews.QueryIt(dataSource); + if(schoolNewsDst == null){ + return new RespEntity(RespCode.NOTEXIST); + } + int praiseCount = schoolNewsDst.getPraiseCount(); + schoolNewsDst.setPraiseCount(praiseCount + 1); + if (schoolNewsDst.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(schoolNews.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + newOp.setPersonName(schoolNews.getChecker()); + newOp.setPersonId(schoolNews.getChecker()); + newOp.setOp(NewsOpRecordEntity.OP_PRAISE); + newOp.setData(""); + newOp.Insert(dataSource); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* +新闻评论接口 + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/news/remark/add",method = RequestMethod.POST) + public RespEntity remarkSchoolNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + NewsRemarkEntity newsRemark = (NewsRemarkEntity) SQLTools.getEntityFromJson(rootnode, NewsRemarkEntity.class); + if (newsRemark == null) + return new RespEntity(RespCode.ERROR_CMD); + if (newsRemark.getNewsId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(newsRemark.getRecordId() == null){ + newsRemark.setRecordId(UUID.randomUUID().toString()); + } + newsRemark.setState(NewsRemarkEntity.STATE_HIDE); + + if(newsRemark.getTimestamp() == null){ + newsRemark.setTimestamp(new Date()); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(newsRemark), "/firectrl/school/news/remark/add"); + } + + newsRemark.Insert(dataSource); + + SchoolNewsEntity schoolNewsDst = new SchoolNewsEntity(); + schoolNewsDst.setNewsId(newsRemark.getNewsId()); + schoolNewsDst = (SchoolNewsEntity)schoolNewsDst.QueryIt(dataSource); + if(schoolNewsDst == null){ + return new RespEntity(RespCode.NOTEXIST); + } + int praiseCount = schoolNewsDst.getRemarkCount(); + schoolNewsDst.setRemarkCount(praiseCount + 1); + if (schoolNewsDst.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(newsRemark.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + newOp.setPersonName(newsRemark.getPersonName()); + newOp.setPersonId(newsRemark.getPersonId()); + newOp.setOp(NewsOpRecordEntity.OP_REMARK); + newOp.setData(newsRemark.getRecordId()); + newOp.Insert(dataSource); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/remark/update",method = RequestMethod.POST) + public RespEntity updateNewsRemarkInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + NewsRemarkEntity newsRemark = (NewsRemarkEntity) SQLTools.getEntityFromJson(rootnode, NewsRemarkEntity.class); + if (newsRemark == null) + return new RespEntity(RespCode.ERROR_CMD); + if (newsRemark.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(newsRemark), "/firectrl/school/news/remark/update"); + } + + if(newsRemark.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (newsRemark.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + NewsOpRecordEntity newOp = new NewsOpRecordEntity(); + newOp.setNewsId(newsRemark.getNewsId()); + newOp.setRecordId(UUID.randomUUID().toString()); + newOp.setTimestamp(new Date()); + newOp.setPersonName(newsRemark.getPersonName()); + newOp.setPersonId(newsRemark.getPersonId()); + newOp.setOp(NewsOpRecordEntity.OP_MODIFY); + newOp.setData(newsRemark.getRecordId()); + newOp.Insert(dataSource); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/remark/getlist",method = RequestMethod.POST) + public RespEntity getSchoolNewsRemarkList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + NewsRemarkEntity newsRemark = (NewsRemarkEntity)SQLTools.getEntityFromJson(rootnode,NewsRemarkEntity.class); + + if(newsRemark==null) + newsRemark = new NewsRemarkEntity(); + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = newsRemark.queryPage(dataSource, startstr, endstr, 0, 1000); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/remark/open",method = RequestMethod.POST) + public RespEntity openNewsRemarkInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + NewsRemarkEntity newsRemark = (NewsRemarkEntity) SQLTools.getEntityFromJson(rootnode, NewsRemarkEntity.class); + if (newsRemark == null) + return new RespEntity(RespCode.ERROR_CMD); + if (newsRemark.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(newsRemark.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + newsRemark.setState(NewsRemarkEntity.STATE_OPEN); + if (newsRemark.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/remark/open_lonsung",method = RequestMethod.POST) + public RespEntity openNewsRemarkInfoFromLonsung(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + NewsRemarkEntity newsRemark = (NewsRemarkEntity) SQLTools.getEntityFromJson(rootnode, NewsRemarkEntity.class); + if (newsRemark == null) + return new RespEntity(RespCode.ERROR_CMD); + if (newsRemark.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(newsRemark), "/firectrl/police/news/remark/open"); + } + + if(newsRemark.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + newsRemark.setState(NewsRemarkEntity.STATE_OPEN); + if (newsRemark.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/remark/open_furong",method = RequestMethod.POST) + public RespEntity openNewsRemarkInfoFromFurong(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + NewsRemarkEntity newsRemark = (NewsRemarkEntity) SQLTools.getEntityFromJson(rootnode, NewsRemarkEntity.class); + if (newsRemark == null) + return new RespEntity(RespCode.ERROR_CMD); + if (newsRemark.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(FireCtrlSystemInit.netMode == 0){ + ioTCtrlServer.translateHttp2Internet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(newsRemark), "/firectrl/police/news/remark/open"); + } + + if(newsRemark.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + newsRemark.setState(NewsRemarkEntity.STATE_OPEN); + if (newsRemark.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/remark/delete_agent",method = RequestMethod.POST) + public RespEntity deleteNewsRemarkInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + NewsRemarkEntity newsRemark = (NewsRemarkEntity) SQLTools.getEntityFromJson(rootnode, NewsRemarkEntity.class); + if (newsRemark == null) + return new RespEntity(RespCode.ERROR_CMD); + if (newsRemark.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(newsRemark), "/firectrl/police/news/remark/delete"); + } + + if(newsRemark.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if (newsRemark.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/news/remark/getopenlist",method = RequestMethod.POST) + public RespEntity getOpenSchoolNewsRemarkList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + NewsRemarkEntity newsRemark = (NewsRemarkEntity)SQLTools.getEntityFromJson(rootnode,NewsRemarkEntity.class); + + String personId = null; + if(newsRemark.getPersonId() != null){ + personId = new String(newsRemark.getPersonId()) ; + } + + newsRemark.setPersonId(null); + + if(newsRemark==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(newsRemark.getNewsId()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + newsRemark.setState(NewsRemarkEntity.STATE_OPEN); + List list = newsRemark.queryPage(dataSource, null, null, 0, 1000); + + if(list == null){ + list = new ArrayList<>(); + } + + if(personId != null){ + newsRemark.setState(NewsRemarkEntity.STATE_HIDE); + newsRemark.setPersonId(personId); + List listHide = newsRemark.queryPage(dataSource, null, null, 0, 1000); + list.addAll(listHide); + } + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/police/news/praise",method = RequestMethod.POST) + public RespEntity praisePoliceNewsInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PoliceNewsEntity policeNews = (PoliceNewsEntity) SQLTools.getEntityFromJson(rootnode, PoliceNewsEntity.class); + if (policeNews == null) + return new RespEntity(RespCode.ERROR_CMD); + if (policeNews.getNewsId() == null) + return new RespEntity(RespCode.ERROR_CMD); + + PoliceNewsEntity policeNewsDst = (PoliceNewsEntity)policeNews.QueryIt(dataSource); + if(policeNewsDst == null){ + return new RespEntity(RespCode.NOTEXIST); + } + int praiseCount = policeNewsDst.getPraiseCount(); + policeNewsDst.setPraiseCount(praiseCount + 1); + if (policeNewsDst.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + 学校通用文件接口 + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/commonfile/getlist",method = RequestMethod.POST) + public RespEntity getSchoolCommonFileList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SchoolCommonFileEntity schoolCommonFile = (SchoolCommonFileEntity)SQLTools.getEntityFromJson(rootnode,SchoolCommonFileEntity.class); + + if(schoolCommonFile==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(schoolCommonFile.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + List list = schoolCommonFile.queryPage(dataSource, startstr, endstr, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/commonfile/getlast",method = RequestMethod.POST) + public RespEntity getSchoolCommonFileLast(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SchoolCommonFileEntity schoolCommonFile = (SchoolCommonFileEntity)SQLTools.getEntityFromJson(rootnode,SchoolCommonFileEntity.class); + + if(schoolCommonFile==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(schoolCommonFile.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int limitCount = JsonHelper.getIntValue(rootnode, "limit"); + if(limitCount <= 0){ + limitCount = 2; + } + + List list = schoolCommonFile.QueryLasts(dataSource, limitCount); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/commonfile/add",method = RequestMethod.POST) + public RespEntity addSchoolCommonFileInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolCommonFileEntity schoolCommonFile = (SchoolCommonFileEntity) SQLTools.getEntityFromJson(rootnode, SchoolCommonFileEntity.class); + if (schoolCommonFile == null) + return new RespEntity(RespCode.ERROR_CMD); + if (schoolCommonFile.getStation() == null || schoolCommonFile.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(schoolCommonFile.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if(schoolCommonFile.getFileId() == null){ + schoolCommonFile.setFileId(UUID.randomUUID().toString()); + } + schoolCommonFile.setTimestamp(new Date()); + if (schoolCommonFile.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + if(FireCtrlSystemInit.netMode == 1){ + System.out.println("agentFile2Skynet: start 1 = "); + + if(schoolCommonFile.getPost() != null && !schoolCommonFile.getStation().equalsIgnoreCase(schoolCommonFile.getPost())){ + FireStationBaseInfoEntity school = new FireStationBaseInfoEntity(); + school.setName(schoolCommonFile.getPost()); + school = (FireStationBaseInfoEntity)school.QueryIt(dataSource); + if(school!=null){ + schoolCommonFile.setBorough(school.getBorough()); + schoolCommonFile.setBrigade(school.getBrigade()); + schoolCommonFile.setDetachment(school.getDetachment()); + schoolCommonFile.setStation(school.getName()); + + schoolCommonFile.setFileId(UUID.randomUUID().toString()); + schoolCommonFile.Insert(dataSource); + } + } + + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(schoolCommonFile), "/firectrl/school/commonfile/add"); + dataStatisticsService.addCommonFileAgentMessage(schoolCommonFile); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/commonfile/update",method = RequestMethod.POST) + public RespEntity updateSchoolCommonFileInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolCommonFileEntity importantStation = (SchoolCommonFileEntity) SQLTools.getEntityFromJson(rootnode, SchoolCommonFileEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getFileId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (importantStation.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/commonfile/delete",method = RequestMethod.POST) + public RespEntity deleteSchoolCommonFileInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolCommonFileEntity importantStation = (SchoolCommonFileEntity) SQLTools.getEntityFromJson(rootnode, SchoolCommonFileEntity.class); + if (importantStation == null) + return new RespEntity(RespCode.ERROR_CMD); + if (importantStation.getFileId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(importantStation.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (importantStation.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + vip student manage api + */ + @ResponseBody + @RequestMapping(value="/firectrl/school/student/getlist",method = RequestMethod.POST) + public RespEntity getStudentList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + StudentVipEntity studentVip = (StudentVipEntity)SQLTools.getEntityFromJson(rootnode,StudentVipEntity.class); + + if(studentVip==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(studentVip.getBrigade()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = studentVip.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/student/add",method = RequestMethod.POST) + public RespEntity addStudentInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + StudentVipEntity studentVip = (StudentVipEntity) SQLTools.getEntityFromJson(rootnode, StudentVipEntity.class); + if (studentVip == null) + return new RespEntity(RespCode.ERROR_CMD); + if (studentVip.getName() == null || studentVip.getBrigade() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(studentVip.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(studentVip), "/firectrl/school/student/add"); + rel = new RespEntity(RespCode.SUCCESS); + }else{ + if (studentVip.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/student/update",method = RequestMethod.POST) + public RespEntity updateStudentInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + StudentVipEntity studentVip = (StudentVipEntity) SQLTools.getEntityFromJson(rootnode, StudentVipEntity.class); + if (studentVip == null) + return new RespEntity(RespCode.ERROR_CMD); + if (studentVip.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(studentVip.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(studentVip), "/firectrl/school/student/update"); + rel = new RespEntity(RespCode.SUCCESS); + }else{ + if (studentVip.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/student/delete",method = RequestMethod.POST) + public RespEntity deleteStudentInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + StudentVipEntity studentVip = (StudentVipEntity) SQLTools.getEntityFromJson(rootnode, StudentVipEntity.class); + if (studentVip == null) + return new RespEntity(RespCode.ERROR_CMD); + if (studentVip.getName() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(studentVip.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (studentVip.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/wechat/openid",method = RequestMethod.POST) + public RespEntity getWechatOpenId(HttpServletRequest request) { + + String codeStr = HttpTools.getBodyFromRequest(request); + WechatAccountInfo accountInfo = JSON.parseObject(codeStr, WechatAccountInfo.class); + if(accountInfo == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + if(accountInfo.getCode() == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + String params = "appid=" + wechat_appId + "&secret=" + wechat_secret + "&js_code=" + accountInfo.getCode() + "&grant_type=authorization_code"; + + try { + String agentUrlLong = "https://api.weixin.qq.com/sns/jscode2session?" + params ; + System.out.println("process getWechatOpenId: url = " + agentUrlLong); + + OkHttpClient okHttpClient = new OkHttpClient(); + Request okRequest = new Request.Builder().url(agentUrlLong).build(); + Response response = okHttpClient.newCall(okRequest).execute(); + + if(response.isSuccessful()){ + String body = response.body().string(); + System.out.println("getWechatOpenId: ok = " + body); + return new RespEntity(RespCode.SUCCESS, body); + }else{ + return new RespEntity(RespCode.FAIL, response.message()); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("getWechatOpenId: fail = " + e.getMessage()); + }finally { + + } + + return new RespEntity(RespCode.FAIL); + } + + + /* + person black list manage api + */ + @ResponseBody + @RequestMapping(value="/firectrl/person/blacklist/getlist",method = RequestMethod.POST) + public RespEntity getPersonBlackList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PersonBlacklistEntity studentVip = (PersonBlacklistEntity)SQLTools.getEntityFromJson(rootnode,PersonBlacklistEntity.class); + + if(studentVip==null) + studentVip = new PersonBlacklistEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = studentVip.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/person/blacklist/add",method = RequestMethod.POST) + public RespEntity addPersonBlackInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PersonBlacklistEntity personBlacklist = (PersonBlacklistEntity) SQLTools.getEntityFromJson(rootnode, PersonBlacklistEntity.class); + if (personBlacklist == null) + return new RespEntity(RespCode.ERROR_CMD); + if (personBlacklist.getPersonId() == null || personBlacklist.getPersonName() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(personBlacklist.QueryIt(dataSource)!=null){ + personBlacklist.Update(dataSource); + }else{ + personBlacklist.Insert(dataSource); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(personBlacklist), "/firectrl/person/blacklist/add"); + // rel = new RespEntity(RespCode.SUCCESS); + } + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/person/blacklist/scan",method = RequestMethod.POST) + public RespEntity scanPersonBlackInfo(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + String groupName = JsonHelper.getStringValue(rootnode, "group"); + String groupLevel= JsonHelper.getStringValue(rootnode, "level"); + if(groupName == null){ + return new RespEntity(RespCode.ERROR_CMD); + } + dataStatisticsService.scanPersonFile(groupName, groupLevel); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/person/blacklist/update",method = RequestMethod.POST) + public RespEntity updatePersonBlackInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PersonBlacklistEntity personBlacklist = (PersonBlacklistEntity) SQLTools.getEntityFromJson(rootnode, PersonBlacklistEntity.class); + if (personBlacklist == null) + return new RespEntity(RespCode.ERROR_CMD); + if (personBlacklist.getPersonId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(personBlacklist.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(personBlacklist), "/firectrl/person/blacklist/update"); + rel = new RespEntity(RespCode.SUCCESS); + } + + if (personBlacklist.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/person/blacklist/delete",method = RequestMethod.POST) + public RespEntity deletePersonBlackInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + PersonBlacklistEntity personBlacklist = (PersonBlacklistEntity) SQLTools.getEntityFromJson(rootnode, PersonBlacklistEntity.class); + if (personBlacklist == null) + return new RespEntity(RespCode.ERROR_CMD); + if (personBlacklist.getPersonId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(personBlacklist.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (personBlacklist.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + /* + 学校整改api + */ + @ResponseBody + @RequestMapping(value="/school/pending/item/getlist",method = RequestMethod.POST) + public RespEntity getSchoolPendingList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SchoolPendingItem schoolPendingItem = (SchoolPendingItem)SQLTools.getEntityFromJson(rootnode,SchoolPendingItem.class); + + if(schoolPendingItem==null) + return new RespEntity(RespCode.ERROR_REQUEST); + if(schoolPendingItem.getBrigade()==null && schoolPendingItem.getBorough() == null && schoolPendingItem.getDetachment() == null && schoolPendingItem.getStation() == null) + return new RespEntity(RespCode.ERROR_REQUEST); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = schoolPendingItem.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/school/pending/item/add",method = RequestMethod.POST) + public RespEntity addSchoolPendingInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolPendingItem pendingItem = (SchoolPendingItem) SQLTools.getEntityFromJson(rootnode, SchoolPendingItem.class); + if (pendingItem == null) + return new RespEntity(RespCode.ERROR_CMD); + if (pendingItem.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + + if (pendingItem.getId() == null){ + pendingItem.setId(UUID.randomUUID().toString()); + } + + if(pendingItem.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + + Date ts = new Date(); + if (pendingItem.getTimestamp() == null){ + pendingItem.setTimestamp(ts); + } + + pendingItem.setState(SchoolPendingItem.STATE_PENDING); + + SchoolPendingProcessRecordEntity newRecord = new SchoolPendingProcessRecordEntity(); + newRecord.setBrigade(pendingItem.getBrigade()); + newRecord.setBorough(pendingItem.getBorough()); + newRecord.setDetachment(pendingItem.getDetachment()); + newRecord.setStation(pendingItem.getStation()); + newRecord.setItemId(pendingItem.getId()); + newRecord.setRecordId(UUID.randomUUID().toString()); + newRecord.setTimestamp(ts); + newRecord.setEventType(SchoolPendingProcessRecordEntity.OP_CREATE); + newRecord.setUserName(pendingItem.getCreator()); + newRecord.Insert(dataSource); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(pendingItem), "/school/pending/item/add"); + } + if (pendingItem.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/school/pending/item/update",method = RequestMethod.POST) + public RespEntity updateSchoolPendingInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolPendingItem pendingItem = (SchoolPendingItem) SQLTools.getEntityFromJson(rootnode, SchoolPendingItem.class); + if (pendingItem == null) + return new RespEntity(RespCode.ERROR_CMD); + if (pendingItem.getId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(pendingItem.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + SchoolPendingProcessRecordEntity newRecord = new SchoolPendingProcessRecordEntity(); + newRecord.setBrigade(pendingItem.getBrigade()); + newRecord.setBorough(pendingItem.getBorough()); + newRecord.setDetachment(pendingItem.getDetachment()); + newRecord.setStation(pendingItem.getStation()); + newRecord.setItemId(pendingItem.getId()); + newRecord.setRecordId(UUID.randomUUID().toString()); + newRecord.setTimestamp(new Date()); + newRecord.setEventType(SchoolPendingProcessRecordEntity.OP_UPDATE); + newRecord.setUserName(pendingItem.getCreator()); + newRecord.Insert(dataSource); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(pendingItem), "/school/pending/item/update"); + rel = new RespEntity(RespCode.SUCCESS); + }else{ + if (pendingItem.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/school/pending/item/delete",method = RequestMethod.POST) + public RespEntity deleteSchoolPendingInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolPendingItem pendingItem = (SchoolPendingItem) SQLTools.getEntityFromJson(rootnode, SchoolPendingItem.class); + if (pendingItem == null) + return new RespEntity(RespCode.ERROR_CMD); + if (pendingItem.getId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(pendingItem.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + + SchoolPendingProcessRecordEntity newRecord = new SchoolPendingProcessRecordEntity(); + newRecord.setBrigade(pendingItem.getBrigade()); + newRecord.setBorough(pendingItem.getBorough()); + newRecord.setDetachment(pendingItem.getDetachment()); + newRecord.setStation(pendingItem.getStation()); + newRecord.setItemId(pendingItem.getId()); + newRecord.setRecordId(UUID.randomUUID().toString()); + newRecord.setTimestamp(new Date()); + newRecord.setEventType(SchoolPendingProcessRecordEntity.OP_DELETE); + newRecord.setUserName(pendingItem.getCreator()); + newRecord.Insert(dataSource); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(pendingItem), "/school/pending/item/delete"); + rel = new RespEntity(RespCode.SUCCESS); + }else { + if (pendingItem.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + } else { + rel = new RespEntity(RespCode.FAIL); + } + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/school/pending/item/operate",method = RequestMethod.POST) + public RespEntity opSchoolPendingInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + SchoolPendingProcessRecordEntity recordEntity = (SchoolPendingProcessRecordEntity) SQLTools.getEntityFromJson(rootnode, SchoolPendingProcessRecordEntity.class); + if (recordEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (recordEntity.getItemId() == null || recordEntity.getEventType() == null) + return new RespEntity(RespCode.ERROR_CMD); + + SchoolPendingItem pendingItem = new SchoolPendingItem(); + pendingItem.setId(recordEntity.getItemId()); + pendingItem = (SchoolPendingItem)pendingItem.QueryIt(dataSource); + if(pendingItem==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(recordEntity.getEventType().equalsIgnoreCase(SchoolPendingProcessRecordEntity.OP_REVISE)){ + pendingItem.setState(SchoolPendingItem.STATE_REVISE); + }else if(recordEntity.getEventType().equalsIgnoreCase(SchoolPendingProcessRecordEntity.OP_REJECT)){ + pendingItem.setState(SchoolPendingItem.STATE_PENDING); + }else{ + return new RespEntity(RespCode.ERROR_CMD); + } + + pendingItem.Update(dataSource); + + recordEntity.setBrigade(pendingItem.getBrigade()); + recordEntity.setBorough(pendingItem.getBorough()); + recordEntity.setDetachment(pendingItem.getDetachment()); + recordEntity.setStation(pendingItem.getStation()); + recordEntity.setRecordId(UUID.randomUUID().toString()); + recordEntity.setTimestamp(new Date()); + + recordEntity.Insert(dataSource); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(pendingItem), "/school/pending/item/operate"); + rel = new RespEntity(RespCode.SUCCESS); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/school/add",method = RequestMethod.POST) + public RespEntity createStation(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||station.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity old = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(old!=null){ + return new RespEntity(RespCode.EXIST); + } + if(station.getDevice_id()!=null){ + old = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,station.getDevice_id()); + if(old!=null){ + return new RespEntity(RespCode.DEVICE_BOUND); + } + } + station.setCreatetime(new Date(System.currentTimeMillis())); + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(station), "/firectrl/school/add"); + } + + if(station.Insert(dataSource)) { + rel= new RespEntity(RespCode.SUCCESS); + }else{ + rel = new RespEntity(RespCode.FAIL); + } + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/school/update",method = RequestMethod.POST) + public RespEntity updateSchool(HttpServletRequest request) { + RespEntity rel = null; + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + FireStationBaseInfoEntity station = (FireStationBaseInfoEntity)SQLTools.getEntityFromJson(rootnode,FireStationBaseInfoEntity.class); + + if(station==null||station.getName()==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + try { + FireStationBaseInfoEntity old = FireStationBaseInfoEntity.Query(dataSource,station.getName()); + if(old == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(station), "/firectrl/school/update"); + } + + if(station.Update(dataSource)) { + rel= new RespEntity(RespCode.SUCCESS); + }else{ + rel = new RespEntity(RespCode.FAIL); + } + + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + + /* + school advice manage api + */ + @ResponseBody + @RequestMapping(value="/firectrl/advice/getlist",method = RequestMethod.POST) + public RespEntity getAdviceList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + AdviceEntity studentVip = (AdviceEntity)SQLTools.getEntityFromJson(rootnode,AdviceEntity.class); + + if(studentVip==null) + studentVip = new AdviceEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = studentVip.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/advice/add",method = RequestMethod.POST) + public RespEntity addAdviceInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + AdviceEntity adviceEntity = (AdviceEntity) SQLTools.getEntityFromJson(rootnode, AdviceEntity.class); + if (adviceEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (adviceEntity.getContent() == null) + return new RespEntity(RespCode.ERROR_CMD); + + adviceEntity.setAdviceId(UUID.randomUUID().toString()); + adviceEntity.setSourceId("root"); + adviceEntity.setRecordId(UUID.randomUUID().toString()); + adviceEntity.setStatus(AdviceEntity.STATE_OPEN); + + if (adviceEntity.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(adviceEntity), "/firectrl/advice/add"); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/advice/update",method = RequestMethod.POST) + public RespEntity updateAdviceInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + AdviceEntity adviceEntity = (AdviceEntity) SQLTools.getEntityFromJson(rootnode, AdviceEntity.class); + if (adviceEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (adviceEntity.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(adviceEntity.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (adviceEntity.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(adviceEntity), "/firectrl/advice/update"); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/advice/delete",method = RequestMethod.POST) + public RespEntity deleteAdviceInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + AdviceEntity adviceEntity = (AdviceEntity) SQLTools.getEntityFromJson(rootnode, AdviceEntity.class); + if (adviceEntity == null) + return new RespEntity(RespCode.ERROR_CMD); + if (adviceEntity.getRecordId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(adviceEntity.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (adviceEntity.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + if(FireCtrlSystemInit.netMode == 1){ + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_School_Check, JSON.toJSONString(adviceEntity), "/firectrl/advice/delete"); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/policeman/sync",method = RequestMethod.POST) + public RespEntity syncPolicemanInfo(HttpServletRequest request) { + try { + if (FireCtrlSystemInit.netMode == 1) { + PolicemanInfo policemanInfo = new PolicemanInfo(); + + List list = policemanInfo.queryPage(dataSource, null, null, 0, 5000); + if(list != null) { + for (int iPerson = 0; iPerson < list.size(); iPerson++){ + PolicemanInfo policeman = (PolicemanInfo)list.get(iPerson); + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(policeman), "/firectrl/school/policeman/add"); + } + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.SUCCESS); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/SecurityPersonController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/SecurityPersonController.java new file mode 100644 index 0000000..a8d2860 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/SecurityPersonController.java @@ -0,0 +1,236 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.CountResult; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.person.PersonLogEntity; +import com.jingyi.iotserver.firestationport.model.person.SecurityPersonEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.List; +import java.util.UUID; + +@RestController +@CrossOrigin +public class SecurityPersonController { + @Autowired + private DataSource dataSource; + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/add",method = RequestMethod.POST) + public RespEntity addSecurityPerson(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + if(securityPerson==null||securityPerson.getName()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(securityPerson.getStaffId() == null){ + securityPerson.setStaffId(UUID.randomUUID().toString()); + } + if(securityPerson.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if(securityPerson.Insert(dataSource)){ + PersonLogEntity personLog = new PersonLogEntity(securityPerson); + personLog.setOperationType(PersonLogEntity.Operation_Type_Info_Add); + personLog.setPreviousData(""); + personLog.setNowData(JSON.toJSONString(securityPerson)); + personLog.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS, securityPerson); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/delete",method = RequestMethod.POST) + public RespEntity deleteSecurityPerson(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + if(securityPerson==null||securityPerson.getStaffId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity tgtPerson = (SecurityPersonEntity)securityPerson.QueryIt(dataSource); + if(tgtPerson == null){ + return new RespEntity(RespCode.NOTEXIST); + } + if(securityPerson.Delete(dataSource)){ + PersonLogEntity personLog = new PersonLogEntity(tgtPerson); + personLog.setOperationType(PersonLogEntity.Operation_Type_Info_Delete); + personLog.setNowData(""); + personLog.setPreviousData(JSON.toJSONString(securityPerson)); + personLog.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/update",method = RequestMethod.POST) + public RespEntity updateSecurityPerson(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + if(securityPerson==null||securityPerson.getStaffId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity tgtPerson = (SecurityPersonEntity)securityPerson.QueryIt(dataSource); + if(tgtPerson == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(securityPerson.Update(dataSource)) { + PersonLogEntity personLog = new PersonLogEntity(tgtPerson); + personLog.setOperationType(PersonLogEntity.Operation_Type_Info_Modify); + personLog.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/move",method = RequestMethod.POST) + public RespEntity moveSecurityPerson(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + if(securityPerson==null||securityPerson.getStaffId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity tgtPerson = (SecurityPersonEntity)securityPerson.QueryIt(dataSource); + if(tgtPerson == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(securityPerson.Update(dataSource)) { + PersonLogEntity personLog = new PersonLogEntity(tgtPerson); + personLog.setOperationType(PersonLogEntity.Operation_Type_Org_Modify); + personLog.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/change_device",method = RequestMethod.POST) + public RespEntity changePersonDevice(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + if(securityPerson==null||securityPerson.getStaffId()==null||securityPerson.getDeviceId()==null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity tgtPerson = (SecurityPersonEntity)securityPerson.QueryIt(dataSource); + if(tgtPerson == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + if(securityPerson.Update(dataSource)) { + PersonLogEntity personLog = new PersonLogEntity(tgtPerson); + personLog.setOperationType(PersonLogEntity.Operation_Type_Device_Change); + personLog.setPreviousData(tgtPerson.getDeviceId()); + personLog.setNowData(securityPerson.getDeviceId()); + personLog.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return new RespEntity(RespCode.FAIL); + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/count",method = RequestMethod.POST) + public RespEntity getSecurityPersonCount(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + + if(securityPerson==null) + securityPerson = new SecurityPersonEntity(); + int count = securityPerson.queryCount(dataSource,null,null); + CountResult reulst = new CountResult(); + reulst.setCount(count); + return new RespEntity(RespCode.SUCCESS,reulst); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/firectrl/client/security/person/getlist",method = RequestMethod.POST) + public RespEntity getSecurityPersonList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if(rootnode==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + int pagesize = JsonHelper.getIntValue(rootnode,"pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode,"pageindex"); + if(pagesize<=0) + pagesize = 100; + if(pageindex<0) + pageindex = 0; + + SecurityPersonEntity securityPerson = (SecurityPersonEntity) SQLTools.getEntityFromJson(rootnode,SecurityPersonEntity.class); + + if(securityPerson==null) + securityPerson = new SecurityPersonEntity(); + List list = securityPerson.queryPage(dataSource,null,null,pageindex,pagesize); + return new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/StationPictureController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/StationPictureController.java new file mode 100644 index 0000000..d18ec95 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/StationPictureController.java @@ -0,0 +1,200 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.mdev.MDevPictureEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import java.io.*; +import java.net.URLEncoder; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@RestController +@CrossOrigin +public class StationPictureController { + @Autowired + private DataSource dataSource; + + @ResponseBody + @RequestMapping(value = "/mdev/picture/upload", method = RequestMethod.POST) + public RespEntity uploadFile(@RequestParam("jsondata") String jsondata, @RequestParam("file") MultipartFile file) { + String path = "./pic"; + String filename ;//获取文件名 + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + MDevPictureEntity p = null; + { + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1( jsondata); + if (rootnode != null) { + p = (MDevPictureEntity) SQLTools.getEntityFromJson(rootnode, MDevPictureEntity.class); + if(p==null) + { + return new RespEntity(RespCode.ERROR_REQUEST); + } + String uri = "/mdev/pic/download?creator="; + if(p.getCreator()!=null&&p.getCreator().length()>0) { + uri += p.getCreator(); + path += "/"+p.getCreator(); + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + } + if(p.getId() == null){ + p.setId(UUID.randomUUID().toString()); + } + + p.setUploadtime(new Date()); + if(!p.Insert(dataSource)) + return new RespEntity(RespCode.FAIL); + + MDevPictureEntity pupdate = new MDevPictureEntity(); + pupdate.setId(p.getId()); + filename = p.getId()+".jpg"; + pupdate.setFilename(filename); + uri += "&file="+filename; + pupdate.setUri(uri); + p.setFilename(filename); + p.setUri(uri); + if(!pupdate.Update(dataSource)) + { + return new RespEntity(RespCode.FAIL); + } + }else{ + return new RespEntity(RespCode.ERROR_REQUEST); + } + } catch (Exception ee) { + return new RespEntity(RespCode.NOTEXIST); + } + } + + if (!file.isEmpty()) { + + try { + InputStream ins = file.getInputStream(); + + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(new File(path + File.separator + filename))); + + byte[] buffer = new byte[128*1024]; + int len = 0; + while((len = ins.read(buffer)) != -1) { + out.write(buffer,0,len); + } + out.flush(); + out.close(); + return new RespEntity(RespCode.SUCCESS,p); + } catch (FileNotFoundException e) { + return new RespEntity(RespCode.NOTEXIST); + } catch (IOException e) { + return new RespEntity(RespCode.EXCEPTION); + } + } else { + return new RespEntity(RespCode.EXCEPTION); + } + } + + @ResponseBody + @RequestMapping(value="/mdev/pic/getlist",method = RequestMethod.POST) + public RespEntity getStationMobleList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + if (rootnode == null) { + return new RespEntity(RespCode.ERROR_REQUEST); + } + + MDevPictureEntity p = (MDevPictureEntity) SQLTools.getEntityFromJson(rootnode, MDevPictureEntity.class); + if(p==null) + return new RespEntity(RespCode.ERROR_REQUEST); + + List list = p.queryList(dataSource,null,null); + rel = new RespEntity(RespCode.SUCCESS,list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + ///https://www.genetek.cc:8086/medev/pic/download?creator=weizhan&file=12333 + @RequestMapping(value="/mdev/pic/download") + public void downloadMap(String creator,String file,HttpServletRequest request, HttpServletResponse response) throws Exception { + String path = "./pic"; + + if(creator!=null&&creator.length()>0) + path += "/"+creator; + if(file==null||file.length()<=0) + { + response.sendError(707); + return; + } + String fileName = file; + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File(path, fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + //动态设置响应类型,根据前台传递文件类型设置响应类型 + response.setContentType(request.getSession().getServletContext().getMimeType(extendFileName)); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(fileName,"UTF-8")); + //获取输出流对象(用于写文件) + ServletOutputStream os = response.getOutputStream(); + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,os); + + } + + @RequestMapping(value="/mdev/pic/downloadId") + public void downloadPictureById(String id,HttpServletRequest request, HttpServletResponse response) throws Exception { + String path = "./pic"; + if(id == null){ + return; + } + MDevPictureEntity pictureEntity = new MDevPictureEntity(); + pictureEntity.setId(id); + MDevPictureEntity pictureInDB = (MDevPictureEntity)pictureEntity.QueryIt(dataSource); + if(pictureInDB == null){ + response.sendError(707); + return; + } + String creator = pictureInDB.getCreator(); + String file = pictureInDB.getFilename(); + + if(creator!=null&&creator.length()>0) + path += "/"+creator; + if(file==null||file.length()<=0) { + response.sendError(707); + return; + } + String fileName = file; + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File(path, fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + //动态设置响应类型,根据前台传递文件类型设置响应类型 + response.setContentType(request.getSession().getServletContext().getMimeType(extendFileName)); + //设置响应头,attachment表示以附件的形式下载,inline表示在线打开 + response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(fileName,"UTF-8")); + //获取输出流对象(用于写文件) + ServletOutputStream os = response.getOutputStream(); + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,os); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/WaterDeviceController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/WaterDeviceController.java new file mode 100644 index 0000000..4966ff1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/WaterDeviceController.java @@ -0,0 +1,632 @@ +package com.jingyi.iotserver.firestationport.controller; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.school.ImportantStation; +import com.jingyi.iotserver.firestationport.model.sensor.water.*; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.UUID; + +@RestController +@CrossOrigin +public class WaterDeviceController { + @Autowired + private DataSource dataSource; + + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterfilter/getlist",method = RequestMethod.POST) + public RespEntity getWaterFilterList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + WaterFilterEntity waterFilter = (WaterFilterEntity) SQLTools.getEntityFromJson(rootnode,WaterFilterEntity.class); + + if(waterFilter==null) + waterFilter = new WaterFilterEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = waterFilter.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + e.printStackTrace(); + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterfilter/add",method = RequestMethod.POST) + public RespEntity addWaterFilterInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + WaterFilterEntity waterFilter = (WaterFilterEntity) SQLTools.getEntityFromJson(rootnode, WaterFilterEntity.class); + if (waterFilter == null) + return new RespEntity(RespCode.ERROR_CMD); + if (waterFilter.getFilterId() == null || waterFilter.getWaterDeviceId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(waterFilter.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (waterFilter.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterfilter/update",method = RequestMethod.POST) + public RespEntity updateWaterFilterInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + WaterFilterEntity waterFilter = (WaterFilterEntity) SQLTools.getEntityFromJson(rootnode, WaterFilterEntity.class); + if (waterFilter == null) + return new RespEntity(RespCode.ERROR_CMD); + if (waterFilter.getFilterId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(waterFilter.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (waterFilter.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterfilter/delete",method = RequestMethod.POST) + public RespEntity deleteWaterFilterInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + WaterFilterEntity waterFilter = (WaterFilterEntity) SQLTools.getEntityFromJson(rootnode, WaterFilterEntity.class); + if (waterFilter == null) + return new RespEntity(RespCode.ERROR_CMD); + if (waterFilter.getFilterId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(waterFilter.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (waterFilter.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/getlist",method = RequestMethod.POST) + public RespEntity getMaintainStaffList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + MaintainStaffEntity maintainStaff = (MaintainStaffEntity) SQLTools.getEntityFromJson(rootnode,MaintainStaffEntity.class); + + if(maintainStaff==null) + maintainStaff = new MaintainStaffEntity(); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = maintainStaff.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/add",method = RequestMethod.POST) + public RespEntity addMaintainStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffEntity maintainStaff = (MaintainStaffEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + if (maintainStaff.getStaffName() == null ) + return new RespEntity(RespCode.ERROR_CMD); + + if(maintainStaff.getIdCode() != null){ + maintainStaff.setStaffId(maintainStaff.getIdCode()); + }else{ + maintainStaff.setStaffId(UUID.randomUUID().toString()); + } + + if(maintainStaff.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (maintainStaff.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/update",method = RequestMethod.POST) + public RespEntity updateMaintainStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffEntity maintainStaff = (MaintainStaffEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + if (maintainStaff.getStaffId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(maintainStaff.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (maintainStaff.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/delete",method = RequestMethod.POST) + public RespEntity deleteWaterMaintainStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffEntity maintainStaff = (MaintainStaffEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + if (maintainStaff.getStaffId() == null) + return new RespEntity(RespCode.ERROR_CMD); + if(maintainStaff.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (maintainStaff.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/bind",method = RequestMethod.POST) + public RespEntity bindMaintainStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffBindEntity maintainStaff = (MaintainStaffBindEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffBindEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + if (maintainStaff.getStaffId() == null || maintainStaff.getStation() == null) + return new RespEntity(RespCode.ERROR_CMD); + + maintainStaff.setBindId(maintainStaff.getStation() + "_" + maintainStaff.getStaffId()); + if(maintainStaff.QueryIt(dataSource) != null){ + return new RespEntity(RespCode.EXIST); + } + if (maintainStaff.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/unbind",method = RequestMethod.POST) + public RespEntity unbindMaintainStaff(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffBindEntity maintainStaff = (MaintainStaffBindEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffBindEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + if(maintainStaff.QueryIt(dataSource)==null){ + return new RespEntity(RespCode.NOTEXIST); + } + if (maintainStaff.Delete(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/bind_stations",method = RequestMethod.POST) + public RespEntity getBindStations(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffBindEntity maintainStaff = (MaintainStaffBindEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffBindEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + if (maintainStaff.getStaffId() == null ) + return new RespEntity(RespCode.ERROR_CMD); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = maintainStaff.queryPage(dataSource, null, null, pageindex, pagesize); + rel = new RespEntity(RespCode.SUCCESS, list); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/maintain_staff/bind_staffs",method = RequestMethod.POST) + public RespEntity getBindStaffes(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + MaintainStaffBindEntity maintainStaff = (MaintainStaffBindEntity) SQLTools.getEntityFromJson(rootnode, MaintainStaffBindEntity.class); + if (maintainStaff == null) + return new RespEntity(RespCode.ERROR_CMD); + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = maintainStaff.queryPage(dataSource, null, null, pageindex, pagesize); + + List bindStaffs = new ArrayList<>(); + if(list != null){ + for(int iStaff = 0; iStaff < list.size(); iStaff++){ + MaintainStaffBindEntity bindStaff = (MaintainStaffBindEntity)list.get(iStaff); + MaintainStaffEntity tgtStaff = new MaintainStaffEntity(); + tgtStaff.setStaffId(bindStaff.getStaffId()); + tgtStaff = (MaintainStaffEntity)tgtStaff.QueryIt(dataSource); + if(tgtStaff != null){ + bindStaffs.add(tgtStaff); + } + } + } + + rel = new RespEntity(RespCode.SUCCESS, bindStaffs); + } + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterflow/hour/getlist",method = RequestMethod.POST) + public RespEntity getWaterFlowHourList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + WaterFlowHourEntity flowHourEntity = (WaterFlowHourEntity) SQLTools.getEntityFromJson(rootnode,WaterFlowHourEntity.class); + + if(flowHourEntity==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(flowHourEntity.getBrigade() == null && flowHourEntity.getBorough() == null && flowHourEntity.getDetachment() == null && flowHourEntity.getStation() == null && flowHourEntity.getWaterDeviceId() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = flowHourEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterflow/day/getlist",method = RequestMethod.POST) + public RespEntity getWaterFlowDayList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + WaterFlowDayEntity flowDayEntity = (WaterFlowDayEntity) SQLTools.getEntityFromJson(rootnode,WaterFlowDayEntity.class); + + if(flowDayEntity==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(flowDayEntity.getBrigade() == null && flowDayEntity.getBorough() == null && flowDayEntity.getDetachment() == null && flowDayEntity.getStation() == null && flowDayEntity.getWaterDeviceId() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = flowDayEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterflow/month/getlist",method = RequestMethod.POST) + public RespEntity getWaterFlowMonthList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + WaterFlowMonthEntity flowMonthEntity = (WaterFlowMonthEntity) SQLTools.getEntityFromJson(rootnode,WaterFlowMonthEntity.class); + + if(flowMonthEntity==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(flowMonthEntity.getBrigade() == null && flowMonthEntity.getBorough() == null && flowMonthEntity.getDetachment() == null && flowMonthEntity.getStation() == null && flowMonthEntity.getWaterDeviceId() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + int pagesize = JsonHelper.getIntValue(rootnode, "pagesize"); + int pageindex = JsonHelper.getIntValue(rootnode, "pageindex"); + if (pagesize <= 0) + pagesize = 1000; + if (pageindex < 0) + pageindex = 0; + + List list = flowMonthEntity.queryPage(dataSource, null, null, pageindex, pagesize); + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterflow/station/flowsum",method = RequestMethod.POST) + public RespEntity getStationWaterFlowSum(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + WaterFlowMonthEntity flowMonthEntity = (WaterFlowMonthEntity) SQLTools.getEntityFromJson(rootnode,WaterFlowMonthEntity.class); + + if(flowMonthEntity==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + + if(flowMonthEntity.getBrigade() == null && flowMonthEntity.getBorough() == null && flowMonthEntity.getDetachment() == null && flowMonthEntity.getStation() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + flowMonthEntity.setWaterDeviceId(null); + + WaterFlowSum flowSum = new WaterFlowSum(); + flowSum.setStation(flowMonthEntity.getStation()); + flowSum.setBorough(flowMonthEntity.getBorough()); + flowSum.setDetachment(flowMonthEntity.getDetachment()); + flowSum.setBrigade(flowMonthEntity.getBrigade()); + + Calendar signDayTime = Calendar.getInstance(); + String nYear = String.valueOf(signDayTime.get(Calendar.YEAR)); + String nMonth = String.valueOf(signDayTime.get(Calendar.MONTH)+1); + String nDay = String.valueOf(signDayTime.get(Calendar.DAY_OF_MONTH)); + + flowMonthEntity.setYear(nYear); + + WaterFlowDayEntity dayFlow = new WaterFlowDayEntity(); + dayFlow.setStation(flowMonthEntity.getStation()); + dayFlow.setBorough(flowMonthEntity.getBorough()); + dayFlow.setDetachment(flowMonthEntity.getDetachment()); + dayFlow.setBrigade(flowMonthEntity.getBrigade()); + dayFlow.setDay(nDay); + dayFlow.setMonth(nMonth); + dayFlow.setYear(nYear); + List listDay= dayFlow.queryPage(dataSource, null, null, 0, 50000); + if(listDay != null){ + WaterFlowDayEntity tgtDayFlow = (WaterFlowDayEntity)listDay.get(0); + flowSum.setFlowCurDay(tgtDayFlow.getFlow()); + }else{ + flowSum.setFlowCurDay(0); + } + + List listMonth = flowMonthEntity.queryPage(dataSource, null, null, 0, 50000); + if(listMonth == null){ + return new RespEntity(RespCode.SUCCESS, flowSum); + } + if(listMonth.isEmpty()){ + return new RespEntity(RespCode.SUCCESS, flowSum); + } + + long yearFlow = 0; + long monthFlow = 0; + for(int iMon = 0; iMon < listMonth.size(); iMon++){ + WaterFlowMonthEntity tgtMonth = (WaterFlowMonthEntity)listMonth.get(iMon); + yearFlow += tgtMonth.getFlow(); + + if(iMon == listMonth.size()-1){ + monthFlow = tgtMonth.getFlow();; + } + } + flowSum.setFlowCurYear(yearFlow); + flowSum.setFlowCurMonth(monthFlow); + + + return new RespEntity(RespCode.SUCCESS, flowSum); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + + @ResponseBody + @RequestMapping(value="/firectrl/foodsafe/waterflow/stations/flowsum",method = RequestMethod.POST) + public RespEntity getStationsWaterFlowSum(HttpServletRequest request) { + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + WaterFlowMonthEntity flowMonthEntity = (WaterFlowMonthEntity) SQLTools.getEntityFromJson(rootnode,WaterFlowMonthEntity.class); + + if(flowMonthEntity==null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + if(flowMonthEntity.getBrigade() == null && flowMonthEntity.getBorough() == null && flowMonthEntity.getDetachment() == null && flowMonthEntity.getStation() == null){ + return new RespEntity(RespCode.ERROR_REQUEST); + } + flowMonthEntity.setWaterDeviceId(null); + + FireStationBaseInfoEntity tgtStation = new FireStationBaseInfoEntity(); + tgtStation.setBrigade(flowMonthEntity.getBrigade()); + tgtStation.setBorough(flowMonthEntity.getBorough()); + tgtStation.setDetachment(flowMonthEntity.getDetachment()); + tgtStation.setName(flowMonthEntity.getStation()); + + List stationList = tgtStation.queryPage(dataSource,null,null,0,10000); + if(stationList == null){ + return new RespEntity(RespCode.NOTEXIST); + } + + List retWfList = new ArrayList<>(); + for(int iSt = 0; iSt < stationList.size(); iSt++){ + FireStationBaseInfoEntity stationInfo = (FireStationBaseInfoEntity)stationList.get(iSt); + + WaterFlowSum flowSum = new WaterFlowSum(); + flowSum.setStation(stationInfo.getName()); + flowSum.setBorough(stationInfo.getBorough()); + flowSum.setDetachment(stationInfo.getDetachment()); + flowSum.setBrigade(stationInfo.getBrigade()); + + Calendar signDayTime = Calendar.getInstance(); + String nYear = String.valueOf(signDayTime.get(Calendar.YEAR)); + String nMonth = String.valueOf(signDayTime.get(Calendar.MONTH)+1); + String nDay = String.valueOf(signDayTime.get(Calendar.DAY_OF_MONTH)); + + flowMonthEntity.setYear(nYear); + flowMonthEntity.setStation(stationInfo.getName()); + flowMonthEntity.setBorough(stationInfo.getBorough()); + flowMonthEntity.setDetachment(stationInfo.getDetachment()); + flowMonthEntity.setBrigade(stationInfo.getBrigade()); + + WaterFlowDayEntity dayFlow = new WaterFlowDayEntity(); + dayFlow.setStation(stationInfo.getName()); + dayFlow.setBorough(stationInfo.getBorough()); + dayFlow.setDetachment(stationInfo.getDetachment()); + dayFlow.setBrigade(stationInfo.getBrigade()); + dayFlow.setDay(nDay); + dayFlow.setMonth(nMonth); + dayFlow.setYear(nYear); + List listDay= dayFlow.queryPage(dataSource, null, null, 0, 50000); + if(listDay != null && listDay.size() > 0){ + WaterFlowDayEntity tgtDayFlow = (WaterFlowDayEntity)listDay.get(0); + flowSum.setFlowCurDay(tgtDayFlow.getFlow()); + }else{ + flowSum.setFlowCurDay(0); + } + long yearFlow = 0; + long monthFlow = 0; + List listMonth = flowMonthEntity.queryPage(dataSource, null, null, 0, 50000); + if(listMonth != null){ + for(int iMon = 0; iMon < listMonth.size(); iMon++){ + WaterFlowMonthEntity tgtMonth = (WaterFlowMonthEntity)listMonth.get(iMon); + yearFlow += tgtMonth.getFlow(); + + if(iMon == listMonth.size()-1){ + monthFlow = tgtMonth.getFlow();; + } + } + } + flowSum.setFlowCurYear(yearFlow); + flowSum.setFlowCurMonth(monthFlow); + + retWfList.add(flowSum); + } + return new RespEntity(RespCode.SUCCESS, retWfList); + }catch (Exception e){ + e.printStackTrace(); + // System.out.println("getStationsWaterFlowSum: "+ e); + return new RespEntity(RespCode.EXCEPTION); + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/terminal/MDevInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/terminal/MDevInfoEntity.java new file mode 100644 index 0000000..b8dd7e2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/terminal/MDevInfoEntity.java @@ -0,0 +1,280 @@ +package com.jingyi.iotserver.firestationport.controller.terminal; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SQLUpdateCmd; + +import javax.sql.DataSource; +import java.util.Date; + +public class MDevInfoEntity extends SQLDataObject { + @JPos(index = 0,identify = true,orderkey = true) + private int number; + @JPos(index = 1,primary = true,filter = true) + private String deviceid; + @JPos(index = 2,filter = true) + private String devicetype; + + @JPos(index = 3,filter = true) + private String name; + @JPos(index = 4,filter = true) + private String showname; + @JPos(index = 5,filter = true) + private String station; + @JPos(index = 6,filter = true) + private String model; + @JPos(index = 7,filter = true) + private String username; + @JPos(index = 8,filter = true) + private String userphone; + @JPos(index = 9,filter = true) + private String address; + @JPos(index = 10) + private double setuplongitude; + @JPos(index = 11) + private double setuplatitude; + @JPos(index = 12) + private String detail; + @JPos(index = 13,update = false) + private Date createtime; + @JPos(index = 14,filter = true) + private String action;//active stop + @JPos(index = 15,filter = true) + private String status;//online offline + @JPos(index = 17) + private double longitude; + @JPos(index = 18) + private double latitude; + @JPos(index = 19,filter = true) + private String brigade; + @JPos(index = 20,filter = true) + private String borough; + @JPos(index = 21,filter = true) + private String detachment; + @JPos(index = 22) + private Date locatetime; + @JPos(index = 23) + private double speed; + @JPos(index = 24) + private double bearing; + @JPos(index = 25) + private String post; + + private String workstate;// onwork | offwork + + + public void setNumber(int number) { + this.number = number; + } + + public int getNumber() { + return number; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setShowname(String showname) { + this.showname = showname; + } + + public String getShowname() { + return showname; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setUserphone(String userphone) { + this.userphone = userphone; + } + + public String getUserphone() { + return userphone; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setSetuplatitude(double setuplatitude) { + this.setuplatitude = setuplatitude; + } + + public double getSetuplatitude() { + return setuplatitude; + } + + public void setSetuplongitude(double setuplongitude) { + this.setuplongitude = setuplongitude; + } + + public double getSetuplongitude() { + return setuplongitude; + } + + public void setDetail(String detail) { + this.detail = detail; + } + + public String getDetail() { + return detail; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setAction(String action) { + this.action = action; + } + + + public String getAction() { + return action; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setLocatetime(Date locatetime) { + this.locatetime = locatetime; + } + + public Date getLocatetime() { + return locatetime; + } + + public void setSpeed(double speed) { + this.speed = speed; + } + + public double getSpeed() { + return speed; + } + + public void setBearing(double bearing) { + this.bearing = bearing; + } + + public double getBearing() { + return bearing; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public void setWorkstate(String workstate) { + this.workstate = workstate; + } + + public String getWorkstate() { + return workstate; + } + + public String tableName(){ + return "mobile_device_info_table"; + } + + + public String getPost() { + return post; + } + + public void setPost(String post) { + this.post = post; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/controller/terminal/StationAIIPCController.java b/src/main/java/com/jingyi/iotserver/firestationport/controller/terminal/StationAIIPCController.java new file mode 100644 index 0000000..dae56b5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/controller/terminal/StationAIIPCController.java @@ -0,0 +1,287 @@ +package com.jingyi.iotserver.firestationport.controller.terminal; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorSubDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorEventProcessEntity; +import com.jingyi.iotserver.firestationport.model.station.PersonInfoEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class StationAIIPCController { + + @Autowired + private DataSource dataSource; + + @Autowired + private UserAuthorManager userAuthorManager; + + @Autowired + private EnvConfigService envConfigService; + @ResponseBody + @RequestMapping(value="/firectrl/terminal/person/add",method = RequestMethod.POST) + public RespEntity addPersonInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode= HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if (per == null || per.getStaffid() == null || per.getStaffid().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null || per.getStation().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if(per.QueryIt(dataSource)!=null){ + return new RespEntity(RespCode.EXIST); + } + if (per.Insert(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate("station", UserAuthorManager.USER_OPERATE_TYPE_CREATE,"PERSONINFO", + "添加人员", JsonHelper.convertObjectToStr(per),rel.getCode()); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/person/delete",method = RequestMethod.POST) + public RespEntity deletePersonInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode = HttpTools.getJsonFromRequest(request); + + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if (per == null || per.getStaffid() == null || per.getStaffid().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null || per.getStation().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + + + if (per.Delete(dataSource)) { + + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate("station",UserAuthorManager.USER_OPERATE_TYPE_DELETE,"PERSONINFO", + "删除人员",JsonHelper.convertObjectToStr(per),rel.getCode()); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/person/update",method = RequestMethod.POST) + public RespEntity updatePersonInfo(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + if (rootnode != null) { + + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if (per == null || per.getStaffid() == null || per.getStaffid().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if ( per.getStation() == null || per.getStation().length() <= 0) + return new RespEntity(RespCode.ERROR_CMD); + if (per.Update(dataSource)) { + rel = new RespEntity(RespCode.SUCCESS); + }else { + rel = new RespEntity(RespCode.FAIL); + } + + userAuthorManager.AddUserOperate("station",UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"PERSONINFO", + "更改人员信息",JsonHelper.convertObjectToStr(per),rel.getCode()); + } + + + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + return rel; + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/person/getlist",method = RequestMethod.POST) + public RespEntity getPersonInfoList(HttpServletRequest request) { + RespEntity rel = null; + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + PersonInfoEntity per = (PersonInfoEntity) SQLTools.getEntityFromJson(rootnode, PersonInfoEntity.class); + if(per==null) + per = new PersonInfoEntity(); + + List list = per.queryList(dataSource,null,null); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/sensor/getsubdevlist",method = RequestMethod.POST) + public RespEntity getSensorSubdevList(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SensorSubDeviceEntity ss = (SensorSubDeviceEntity) SQLTools.getEntityFromJson(rootnode, SensorSubDeviceEntity.class); + + + if(ss==null||ss.getDeviceid()==null) + return new RespEntity(RespCode.NOTEXIST); + + List list = ss.queryList(dataSource,null,null); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/sensor/sensorevent/getlist",method = RequestMethod.POST) + public RespEntity getSensorEventList(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SensorEventEntity se = (SensorEventEntity) SQLTools.getEntityFromJson(rootnode, SensorEventEntity.class); + String startstr = JsonHelper.getStringValue(rootnode, "start"); + String endstr = JsonHelper.getStringValue(rootnode, "end"); + + if(se==null||se.getDeviceid()==null) + return new RespEntity(RespCode.NOTEXIST); + + List list = se.queryList(dataSource,startstr,endstr); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/sensor/sensorevent/assign",method = RequestMethod.POST) + public RespEntity updateSensorEventState(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SensorEventEntity se = (SensorEventEntity) SQLTools.getEntityFromJson(rootnode, SensorEventEntity.class); + SensorEventEntity org = (SensorEventEntity)se.QueryIt(dataSource); + String station = JsonHelper.getStringValue(rootnode,"station"); + String receiver = JsonHelper.getStringValue(rootnode,"receiver"); + if(org==null) + return new RespEntity(RespCode.NOTEXIST); + + org.setState("assigned"); + + if(!org.UpdateState(dataSource)) + return new RespEntity(RespCode.FAIL); + + SensorEventProcessEntity sep = new SensorEventProcessEntity(); + sep.setEventid(se.getEventid()); + sep.setTimestamp(new Date()); + sep.setProcess("assigned"); + sep.setOperator(station); + sep.setTitle("station"); + sep.setResult(receiver); + + sep.Insert(dataSource); + userAuthorManager.AddUserOperate("sensorevent",UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"SENSOREVENT", + "指派传感器事件任务",JsonHelper.convertObjectToStr(sep),0); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/sensor/sensorevent/close",method = RequestMethod.POST) + public RespEntity closeSensorEventState(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SensorEventEntity se = (SensorEventEntity) SQLTools.getEntityFromJson(rootnode, SensorEventEntity.class); + SensorEventEntity org = (SensorEventEntity)se.QueryIt(dataSource); + String operator = JsonHelper.getStringValue(rootnode,"operator"); + String title = JsonHelper.getStringValue(rootnode,"title"); + String result = JsonHelper.getStringValue(rootnode,"result"); + String discription = JsonHelper.getStringValue(rootnode,"discription"); + String resurl = JsonHelper.getStringValue(rootnode,"resourcelocate"); + if(org==null) + return new RespEntity(RespCode.NOTEXIST); + + org.setState("closed"); + + + if(!org.UpdateState(dataSource)) + return new RespEntity(RespCode.FAIL); + + + SensorEventProcessEntity sep = new SensorEventProcessEntity(); + sep.setEventid(se.getEventid()); + sep.setTimestamp(new Date()); + sep.setProcess("closed"); + sep.setOperator(operator); + sep.setTitle(title); + sep.setResult(result); + sep.setResourcelocate(resurl); + sep.setDescription(discription); + sep.Insert(dataSource); + + userAuthorManager.AddUserOperate("sensorevent",UserAuthorManager.USER_OPERATE_TYPE_UPDATE,"SENSOREVENT", + "关闭传感器事件任务",JsonHelper.convertObjectToStr(sep),0); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + @ResponseBody + @RequestMapping(value="/firectrl/terminal/sensor/sensorevent/getoplist",method = RequestMethod.POST) + public RespEntity getSensorEventOpList(HttpServletRequest request) { + try { + JsonNode rootnode=HttpTools.getJsonFromRequest(request); + SensorEventProcessEntity se = (SensorEventProcessEntity) SQLTools.getEntityFromJson(rootnode, SensorEventProcessEntity.class); + + + if(se==null||se.getEventid()==null) + return new RespEntity(RespCode.NOTEXIST); + + List list = se.queryList(dataSource,null,null); + + return new RespEntity(RespCode.SUCCESS, list); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/DeviceRequestEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/DeviceRequestEntity.java new file mode 100644 index 0000000..73fc9e5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/DeviceRequestEntity.java @@ -0,0 +1,59 @@ +package com.jingyi.iotserver.firestationport.model; + +public class DeviceRequestEntity { + private String Mark; + private String UserName; + private String DeviceId; + private int CID; + private long PTS; + private String data; + + + public void setCID(int CID) { + this.CID = CID; + } + + public int getCID() { + return CID; + } + + public void setMark(String mark) { + Mark = mark; + } + + public String getMark() { + return Mark; + } + + public void setUserName(String userName) { + UserName = userName; + } + + public String getUserName() { + return UserName; + } + + public void setPTS(long PTS) { + this.PTS = PTS; + } + + public long getPTS() { + return PTS; + } + + public void setDeviceId(String deviceId) { + DeviceId = deviceId; + } + + public String getDeviceId() { + return DeviceId; + } + + public void setData(String data) { + this.data = data; + } + + public String getData() { + return data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/AlarmDayCount.java b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/AlarmDayCount.java new file mode 100644 index 0000000..6cb5aa1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/AlarmDayCount.java @@ -0,0 +1,11 @@ +package com.jingyi.iotserver.firestationport.model.analyze; + +import lombok.Data; + +@Data +public class AlarmDayCount { + private String year; + private String month; + private String day; + private int countAlarm; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/StationDailyOnSignRateEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/StationDailyOnSignRateEntity.java new file mode 100644 index 0000000..047e635 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/StationDailyOnSignRateEntity.java @@ -0,0 +1,4 @@ +package com.jingyi.iotserver.firestationport.model.analyze; + +public class StationDailyOnSignRateEntity { +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/StationDailyOnlineRateEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/StationDailyOnlineRateEntity.java new file mode 100644 index 0000000..a2a96c7 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/StationDailyOnlineRateEntity.java @@ -0,0 +1,52 @@ +package com.jingyi.iotserver.firestationport.model.analyze; + +import com.jingyi.iotserver.utils.SQLCreateTableCmd; + +public class StationDailyOnlineRateEntity { + private String station; + private int date; + private long lineseconds;//second + private long lineduration;//second + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public int getDate() { + return date; + } + + public void setDate(int date) { + this.date = date; + } + + public void setLineseconds(long lineseconds) { + this.lineseconds = lineseconds; + } + + public long getLineseconds() { + return lineseconds; + } + + public void setLineduration(long lineduration) { + this.lineduration = lineduration; + } + + public long getLineduration() { + return lineduration; + } + + public static String tableName(String dynamickey){ + return "station_daily_online_rate_table"; + } + public static String createTableSql() { + SQLCreateTableCmd cmd; + String sql = "CREATE TABLE "; + sql += tableName(null); + return sql; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/WeekCount.java b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/WeekCount.java new file mode 100644 index 0000000..df31d84 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/analyze/WeekCount.java @@ -0,0 +1,32 @@ +package com.jingyi.iotserver.firestationport.model.analyze; + +public class WeekCount { + private String startTime; + private String EndTime; + private int count; + + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return EndTime; + } + + public void setEndTime(String endTime) { + EndTime = endTime; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ACBParameterCalculate.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ACBParameterCalculate.java new file mode 100644 index 0000000..27f7ca0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ACBParameterCalculate.java @@ -0,0 +1,685 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class ACBParameterCalculate { + private String deviceid; + + public double ald; + public double aldmax; + public double aldmin; + + public double aa; + public double aamax; + public double aamin; + + public double at; + public double atmax; + public double atmin; + + public double av; + public double avmax; + public double avmin; + + public double aw; + public double awmax; + public double awmin; + + public double apf; + public double apfmax; + public double apfmin; + + public double gld; + public double gldmax; + public double gldmin; + + public double ga; + public double gamax; + public double gamin; + + public double gt; + public double gtmax; + public double gtmin; + + public double gv; + public double gvmax; + public double gvmin; + + public double gw; + public double gwmax; + public double gwmin; + + public double gpf; + public double gpfmax; + public double gpfmin; + + public double ba; + public double bamax; + public double bamin; + + public double bt; + public double btmax; + public double btmin; + + public double bv; + public double bvmax; + public double bvmin; + + public double bw; + public double bwmax; + public double bwmin; + + public double bpf; + public double bpfmax; + public double bpfmin; + + public double ca; + public double camax; + public double camin; + + public double ct; + public double ctmax; + public double ctmin; + + public double cv; + public double cvmax; + public double cvmin; + + public double cw; + public double cwmax; + public double cwmin; + + public double cpf; + public double cpfmax; + public double cpfmin; + + public double na; + public double namax; + public double namin; + + public double nt; + public double ntmax; + public double ntmin; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setAld(double ald) { + this.ald = ald; + } + + public double getAld() { + return ald; + } + + public void setAldmax(double aldmax) { + this.aldmax = aldmax; + } + + public double getAldmax() { + return aldmax; + } + + public void setAldmin(double aldmin) { + this.aldmin = aldmin; + } + + public double getAldmin() { + return aldmin; + } + + public void setAa(double aa) { + this.aa = aa; + } + + public double getAa() { + return aa; + } + + public void setAamax(double aamax) { + this.aamax = aamax; + } + + public double getAamax() { + return aamax; + } + + public void setAamin(double aamin) { + this.aamin = aamin; + } + + public double getAamin() { + return aamin; + } + + public void setAt(double at) { + this.at = at; + } + + public double getAt() { + return at; + } + + public void setAtmax(double atmax) { + this.atmax = atmax; + } + + public double getAtmax() { + return atmax; + } + + public void setAtmin(double atmin) { + this.atmin = atmin; + } + + public double getAtmin() { + return atmin; + } + + public void setAv(double av) { + this.av = av; + } + + public double getAv() { + return av; + } + + public void setAmax(double avmax) { + this.avmax = avmax; + } + + public double getAvmax() { + return avmax; + } + + public void setAvmin(double avmin) { + this.avmin = avmin; + } + + public double getAvmin() { + return avmin; + } + + public void setAw(double aw) { + this.aw = aw; + } + + public double getAw() { + return aw; + } + + public void setAwmax(double awmax) { + this.awmax = awmax; + } + + public double getAwmax() { + return awmax; + } + + public void setAwmin(double awmin) { + this.awmin = awmin; + } + + public double getAwmin() { + return awmin; + } + + public void setApf(double apf) { + this.apf = apf; + } + + public double getApf() { + return apf; + } + + public void setApfmax(double apfmax) { + this.apfmax = apfmax; + } + + public double getApfmax() { + return apfmax; + } + + public void setApfmin(double apfmin) { + this.apfmin = apfmin; + } + + public double getApfmin() { + return apfmin; + } + + public void setGld(double gld) { + this.gld = gld; + } + + public double getGld() { + return gld; + } + + public void setGldmax(double gldmax) { + this.gldmax = gldmax; + } + + public double getGldmax() { + return gldmax; + } + + public void setGldmin(double gldmin) { + this.gldmin = gldmin; + } + + public double getGldmin() { + return gldmin; + } + + public void setGa(double ga) { + this.ga = ga; + } + + public double getGa() { + return ga; + } + + public void setGamax(double gamax) { + this.gamax = gamax; + } + + public double getGamax() { + return gamax; + } + + public void setGamin(double gamin) { + this.gamin = gamin; + } + + public double getGamin() { + return gamin; + } + + public void setGt(double gt) { + this.gt = gt; + } + + public double getGt() { + return gt; + } + + public void setGtmax(double gtmax) { + this.gtmax = gtmax; + } + + public double getGtmax() { + return gtmax; + } + + public void setGtmin(double gtmin) { + this.gtmin = gtmin; + } + + public double getGtmin() { + return gtmin; + } + + public void setGv(double gv) { + this.gv = gv; + } + + public double getGv() { + return gv; + } + + public void setGvmax(double gvmax) { + this.gvmax = gvmax; + } + + public double getGvmax() { + return gvmax; + } + + public void setGvmin(double gvmin) { + this.gvmin = gvmin; + } + + public double getGvmin() { + return gvmin; + } + + public void setGw(double gw) { + this.gw = gw; + } + + public double getGw() { + return gw; + } + + public void setGwmax(double gwmax) { + this.gwmax = gwmax; + } + + public double getGwmax() { + return gwmax; + } + + public void setGwmin(double gwmin) { + this.gwmin = gwmin; + } + + public double getGwmin() { + return gwmin; + } + + public void setGpf(double gpf) { + this.gpf = gpf; + } + + public double getGpf() { + return gpf; + } + + public void setGpfmax(double gpfmax) { + this.gpfmax = gpfmax; + } + + public double getGpfmax() { + return gpfmax; + } + + public void setGpfmin(double gpfmin) { + this.gpfmin = gpfmin; + } + + public double getGpfmin() { + return gpfmin; + } + + public void setBa(double ba) { + this.ba = ba; + } + + public double getBa() { + return ba; + } + + public void setBamax(double bamax) { + this.bamax = bamax; + } + + public double getBamax() { + return bamax; + } + + public void setBamin(double bamin) { + this.bamin = bamin; + } + + public double getBamin() { + return bamin; + } + + public void setBt(double bt) { + this.bt = bt; + } + + public double getBt() { + return bt; + } + + public void setBtmax(double btmax) { + this.btmax = btmax; + } + + public double getBtmax() { + return btmax; + } + + public void setBtmin(double btmin) { + this.btmin = btmin; + } + + public double getBtmin() { + return btmin; + } + + public void setBv(double bv) { + this.bv = bv; + } + + public double getBv() { + return bv; + } + + public void setBvmax(double bvmax) { + this.bvmax = bvmax; + } + + public double getBvmax() { + return bvmax; + } + + public void setBvmin(double bvmin) { + this.bvmin = bvmin; + } + + public double getBvmin() { + return bvmin; + } + + public void setBw(double bw) { + this.bw = bw; + } + + public double getBw() { + return bw; + } + + public void setBwmax(double bwmax) { + this.bwmax = bwmax; + } + + public double getBwmax() { + return bwmax; + } + + public void setBwmin(double bwmin) { + this.bwmin = bwmin; + } + + public double getBwmin() { + return bwmin; + } + + public void setBpf(double bpf) { + this.bpf = bpf; + } + + public double getBpf() { + return bpf; + } + + public void setBpfmax(double bpfmax) { + this.bpfmax = bpfmax; + } + + public double getBpfmax() { + return bpfmax; + } + + public void setBpfmin(double bpfmin) { + this.bpfmin = bpfmin; + } + + public double getBpfmin() { + return bpfmin; + } + + public void setCa(double ca) { + this.ca = ca; + } + + public double getCa() { + return ca; + } + + public void setCamax(double camax) { + this.camax = camax; + } + + public double getCamax() { + return camax; + } + + public void setCamin(double camin) { + this.camin = camin; + } + + public double getCamin() { + return camin; + } + + public void setCt(double ct) { + this.ct = ct; + } + + public double getCt() { + return ct; + } + + public void setCtmax(double ctmax) { + this.ctmax = ctmax; + } + + public double getCtmax() { + return ctmax; + } + + public void setCtmin(double ctmin) { + this.ctmin = ctmin; + } + + public double getCtmin() { + return ctmin; + } + + public void setCv(double cv) { + this.cv = cv; + } + + public double getCv() { + return cv; + } + + public void setCvmax(double cvmax) { + this.cvmax = cvmax; + } + + public double getCvmax() { + return cvmax; + } + + public void setCvmin(double cvmin) { + this.cvmin = cvmin; + } + + public double getCvmin() { + return cvmin; + } + + public void setCw(double cw) { + this.cw = cw; + } + + public double getCw() { + return cw; + } + + public void setCwmax(double cwmax) { + this.cwmax = cwmax; + } + + public double getCwmax() { + return cwmax; + } + + public void setCwmin(double cwmin) { + this.cwmin = cwmin; + } + + public double getCwmin() { + return cwmin; + } + + public void setCpf(double cpf) { + this.cpf = cpf; + } + + public double getCpf() { + return cpf; + } + + public void setCpfmax(double cpfmax) { + this.cpfmax = cpfmax; + } + + public double getCpfmax() { + return cpfmax; + } + + public void setCpfmin(double cpfmin) { + this.cpfmin = cpfmin; + } + + public double getCpfmin() { + return cpfmin; + } + + public void setNa(double na) { + this.na = na; + } + + public double getNa() { + return na; + } + + public void setNamax(double namax) { + this.namax = namax; + } + + public double getNamax() { + return namax; + } + + public void setNamin(double namin) { + this.namin = namin; + } + + public double getNamin() { + return namin; + } + + public void setNt(double nt) { + this.nt = nt; + } + + public double getNt() { + return nt; + } + + public void setNtmax(double ntmax) { + this.ntmax = ntmax; + } + + public double getNtmax() { + return ntmax; + } + + public void setNtmin(double ntmin) { + this.ntmin = ntmin; + } + + public double getNtmin() { + return ntmin; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AICameraFaceInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AICameraFaceInfo.java new file mode 100644 index 0000000..bf1e314 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AICameraFaceInfo.java @@ -0,0 +1,94 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class AICameraFaceInfo { + private int libid; + private String libname; + private int personid; + private String personname; + private int gender; + private String birthday; + private int identifytype; + private String identifyid; + private String department; + private String imageurl; + + public void setLibid(int libid) { + this.libid = libid; + } + + public int getLibid() { + return libid; + } + + public void setLibname(String libname) { + this.libname = libname; + } + + public String getLibname() { + return libname; + } + + public void setPersonid(int personid) { + this.personid = personid; + } + + public int getPersonid() { + return personid; + } + + public void setPersonname(String personname) { + this.personname = personname; + } + + public String getPersonname() { + return personname; + } + + public void setGender(int gender) { + this.gender = gender; + } + + public int getGender() { + return gender; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getBirthday() { + return birthday; + } + + public void setIdentifytype(int identifytype) { + this.identifytype = identifytype; + } + + public int getIdentifytype() { + return identifytype; + } + + public void setIdentifyid(String identifyid) { + this.identifyid = identifyid; + } + + public String getIdentifyid() { + return identifyid; + } + + public void setDepartment(String department) { + this.department = department; + } + + public String getDepartment() { + return department; + } + + public void setImageurl(String imageurl) { + this.imageurl = imageurl; + } + + public String getImageurl() { + return imageurl; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AIIPCConfig.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AIIPCConfig.java new file mode 100644 index 0000000..af13278 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AIIPCConfig.java @@ -0,0 +1,55 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + + +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCSettingEntity; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.List; + +public class AIIPCConfig { + private String deviceid; + private AIIPCSettingEntity setting; + private List eventsetting; + private List picturematchsetting; + private List textmatchsetting; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setSetting(AIIPCSettingEntity setting) { + this.setting = setting; + } + + public AIIPCSettingEntity getSetting() { + return setting; + } + + public void setEventsetting(List eventsetting) { + this.eventsetting = eventsetting; + } + + public List getEventsetting() { + return eventsetting; + } + + public void setPicturematchsetting(List picturematchsetting) { + this.picturematchsetting = picturematchsetting; + } + + public List getPicturematchsetting() { + return picturematchsetting; + } + + public void setTextmatchsetting(List textmatchsetting) { + this.textmatchsetting = textmatchsetting; + } + + public List getTextmatchsetting() { + return textmatchsetting; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AlarmTaskNewResult.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AlarmTaskNewResult.java new file mode 100644 index 0000000..383432b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AlarmTaskNewResult.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class AlarmTaskNewResult { + private String taskid; + private String receiver; + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AssignmentAnalyzeInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AssignmentAnalyzeInfo.java new file mode 100644 index 0000000..7bb8df1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/AssignmentAnalyzeInfo.java @@ -0,0 +1,49 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class AssignmentAnalyzeInfo { + public int assignmentcount; + public int receivedcount; + public int processedcount; + public int completecount; + public int total; + + public void setAssignmentcount(int assignmentcount) { + this.assignmentcount = assignmentcount; + } + + public int getAssignmentcount() { + return assignmentcount; + } + + public void setReceivedcount(int receivedcount) { + this.receivedcount = receivedcount; + } + + public int getReceivedcount() { + return receivedcount; + } + + public void setProcessedcount(int processedcount) { + this.processedcount = processedcount; + } + + public int getProcessedcount() { + return processedcount; + } + + public void setCompletecount(int completecount) { + this.completecount = completecount; + } + + public int getCompletecount() { + return completecount; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getTotal() { + return total; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ComplexMutilObject.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ComplexMutilObject.java new file mode 100644 index 0000000..221559b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ComplexMutilObject.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class ComplexMutilObject { + public Object object0; + public Object object1; + public Object object2; + + public void setObject0(Object object0) { + this.object0 = object0; + } + + public Object getObject0() { + return object0; + } + + public void setObject1(Object object1) { + this.object1 = object1; + } + + public Object getObject1() { + return object1; + } + + public void setObject2(Object object2) { + this.object2 = object2; + } + + public Object getObject2() { + return object2; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/CountInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/CountInfo.java new file mode 100644 index 0000000..a6350fd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/CountInfo.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class CountInfo { + public int count; + public int total; + public String index; + + public void setCount(int count) { + this.count = count; + } + + public int getCount() { + return count; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getTotal() { + return total; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/CountResultByIndex.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/CountResultByIndex.java new file mode 100644 index 0000000..97b7893 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/CountResultByIndex.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class CountResultByIndex { + private int index; + private int count; + + public void setIndex(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public void setCount(int count) { + this.count = count; + } + + public int getCount() { + return count; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ElectricSensorResult.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ElectricSensorResult.java new file mode 100644 index 0000000..e4ef422 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/ElectricSensorResult.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class ElectricSensorResult { + private String code; + private String msg; + + public void setCode(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getMsg() { + return msg; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/MDevMediaInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/MDevMediaInfo.java new file mode 100644 index 0000000..e9dea00 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/MDevMediaInfo.java @@ -0,0 +1,151 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import java.util.Date; + +public class MDevMediaInfo { + private String deviceid; + private String station; + private String path;//路径 + private String url;//网络地址 + private String bucket;//项目名 + private String filename;//文件名 + private String filetype;//文件类型 jpg,mp4,pcm + private Date createtime;//创建时间 + private Date uploadtime;//上传时间ms + private String user;//设备用户名 + private String address;//创建时地址 + private double longitude; + private double latitude; + private String title; + private String label; + private String comment; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setPath(String path) { + this.path = path; + } + + public String getPath() { + return path; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUrl() { + return url; + } + + public void setBucket(String bucket) { + this.bucket = bucket; + } + + public String getBucket() { + return bucket; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getFilename() { + return filename; + } + + public void setFiletype(String filetype) { + this.filetype = filetype; + } + + public String getFiletype() { + return filetype; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setUploadtime(Date uploadtime) { + this.uploadtime = uploadtime; + } + + public Date getUploadtime() { + return uploadtime; + } + + public void setUser(String user) { + this.user = user; + } + + public String getUser() { + return user; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/NoticeAnalyzeInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/NoticeAnalyzeInfo.java new file mode 100644 index 0000000..8727227 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/NoticeAnalyzeInfo.java @@ -0,0 +1,49 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class NoticeAnalyzeInfo { + public int index; + public int noticecount; + public int receivedcount; + public int readcount; + public int total; + + public void setIndex(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public void setNoticecount(int noticecount) { + this.noticecount = noticecount; + } + + public int getNoticecount() { + return noticecount; + } + + public void setReceivedcount(int receivedcount) { + this.receivedcount = receivedcount; + } + + public int getReceivedcount() { + return receivedcount; + } + + public void setReadcount(int readcount) { + this.readcount = readcount; + } + + public int getReadcount() { + return readcount; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getTotal() { + return total; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/O2DDistanceInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/O2DDistanceInfo.java new file mode 100644 index 0000000..07aef17 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/O2DDistanceInfo.java @@ -0,0 +1,67 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class O2DDistanceInfo { + private String index; + private double longitude; + private double latitude; + private double destlongitude; + private double destlatitude; + private int distance; + private int duration; + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setDestlongitude(double destlongitude) { + this.destlongitude = destlongitude; + } + + public double getDestlongitude() { + return destlongitude; + } + + public void setDestlatitude(double destlatitude) { + this.destlatitude = destlatitude; + } + + public double getDestlatitude() { + return destlatitude; + } + + public void setDistance(int distance) { + this.distance = distance; + } + + public int getDistance() { + return distance; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public int getDuration() { + return duration; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RFIDData.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RFIDData.java new file mode 100644 index 0000000..da1c96f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RFIDData.java @@ -0,0 +1,13 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class RFIDData { + private int testFlag; + + public void setTestFlag(int testFlag) { + this.testFlag = testFlag; + } + + public int getTestFlag() { + return testFlag; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RFIDResp.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RFIDResp.java new file mode 100644 index 0000000..c349591 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RFIDResp.java @@ -0,0 +1,30 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class RFIDResp { + private int code; + private String msg; + private Object data; + public void setCode(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getMsg() { + return msg; + } + + public void setData(Object data) { + this.data = data; + } + + public Object getData() { + return data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RollCallStatisticsInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RollCallStatisticsInfo.java new file mode 100644 index 0000000..ce89d62 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RollCallStatisticsInfo.java @@ -0,0 +1,51 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import java.util.Date; + +public class RollCallStatisticsInfo { + private String rollcallnumber; + private int stationcount; + private int ackcount; + private int ignorecount; + private Date starttime; + + public void setRollcallnumber(String rollcallnumber) { + this.rollcallnumber = rollcallnumber; + } + + public String getRollcallnumber() { + return rollcallnumber; + } + + public void setStationcount(int stationcount) { + this.stationcount = stationcount; + } + + public int getStationcount() { + return stationcount; + } + + public void setAckcount(int ackcount) { + this.ackcount = ackcount; + } + + public int getAckcount() { + return ackcount; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setIgnorecount(int ignorecount) { + this.ignorecount = ignorecount; + } + + public int getIgnorecount() { + return ignorecount; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RollcallReportForm.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RollcallReportForm.java new file mode 100644 index 0000000..54970e8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RollcallReportForm.java @@ -0,0 +1,60 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import java.util.List; + +public class RollcallReportForm { + private int rollcall; + private int expect; + private int ack; + private int ignore; + private String index; + private List ranking; + + public void setRollcall(int rollcall) { + this.rollcall = rollcall; + } + + public int getRollcall() { + return rollcall; + } + + public void setExpect(int expect) { + this.expect = expect; + } + + public int getExpect() { + return expect; + } + + public void setAck(int ack) { + this.ack = ack; + } + + public int getAck() { + return ack; + } + + public void setIgnore(int ignore) { + this.ignore = ignore; + } + + public int getIgnore() { + return ignore; + } + + public void setRanking(List ranking) { + this.ranking = ranking; + } + + public List getRanking() { + return ranking; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RoundInspectTaskResult.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RoundInspectTaskResult.java new file mode 100644 index 0000000..c1847cf --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/RoundInspectTaskResult.java @@ -0,0 +1,27 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionResultEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionTaskEntity; + +import java.util.List; + +public class RoundInspectTaskResult { + private RoundInspectionTaskEntity task; + private List result; + + public void setTask(RoundInspectionTaskEntity task) { + this.task = task; + } + + public RoundInspectionTaskEntity getTask() { + return task; + } + + public void setResult(List result) { + this.result = result; + } + + public List getResult() { + return result; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorAlarmCount.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorAlarmCount.java new file mode 100644 index 0000000..a0c5ff0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorAlarmCount.java @@ -0,0 +1,24 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import java.util.ArrayList; + +public class SensorAlarmCount { + private int index; + private ArrayList countlist ; + + public void setIndex(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public void setCountlist(ArrayList countlist) { + this.countlist = countlist; + } + + public ArrayList getCountlist() { + return countlist; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorAlarmCountElement.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorAlarmCountElement.java new file mode 100644 index 0000000..8ff1490 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorAlarmCountElement.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class SensorAlarmCountElement { + private int count; + private String type; + + public void setCount(int count) { + this.count = count; + } + + public int getCount() { + return count; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorStatusCount.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorStatusCount.java new file mode 100644 index 0000000..5eee10c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SensorStatusCount.java @@ -0,0 +1,76 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class SensorStatusCount { + public int unused; + public int normal; + public int alarm; + public int broken; + public int unknown; + public int total; + public String index; + public String type; + + public void setUnused(int unused) { + this.unused = unused; + } + + public int getUnused() { + return unused; + } + + public void setNormal(int normal) { + this.normal = normal; + } + + public int getNormal() { + return normal; + } + + public void setAlarm(int alarm) { + this.alarm = alarm; + } + + public int getAlarm() { + return alarm; + } + + public void setBroken(int broken) { + this.broken = broken; + } + + public int getBroken() { + return broken; + } + + public void setUnknown(int unknown) { + this.unknown = unknown; + } + + public int getUnknown() { + return unknown; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getTotal() { + return total; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StaionQueryCondition.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StaionQueryCondition.java new file mode 100644 index 0000000..85a9264 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StaionQueryCondition.java @@ -0,0 +1,48 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class StaionQueryCondition { + private String station; + private String start; + private String end; + private int pageindex; + private int pagesize; + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setStart(String start) { + this.start = start; + } + + public String getStart() { + return start; + } + + public void setEnd(String end) { + this.end = end; + } + + public String getEnd() { + return end; + } + + public void setPageindex(int pageindex) { + this.pageindex = pageindex; + } + + public int getPageindex() { + return pageindex; + } + + public void setPagesize(int pagesize) { + this.pagesize = pagesize; + } + + public int getPagesize() { + return pagesize; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationAssignmentAnalyzeInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationAssignmentAnalyzeInfo.java new file mode 100644 index 0000000..68eff6d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationAssignmentAnalyzeInfo.java @@ -0,0 +1,79 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import com.jingyi.iotserver.firestationport.model.todev.AssignmentEntity; +import com.jingyi.iotserver.firestationport.model.todev.AssignmentStatusEntity; + +import java.util.ArrayList; + +public class StationAssignmentAnalyzeInfo { + private int assimentcount; + private int receivedcount; + private int processedcount; + private int completedcount; + private ArrayList list; + + public void setAssimentcount(int assimentcount) { + this.assimentcount = assimentcount; + } + + public int getAssimentcount() { + return assimentcount; + } + + public void setReceivedcount(int receivedcount) { + this.receivedcount = receivedcount; + } + + public int getReceivedcount() { + return receivedcount; + } + + public int getProcessedcount() { + return processedcount; + } + + public void setProcessedcount(int processedcount) { + this.processedcount = processedcount; + } + + public void setCompletedcount(int completedcount) { + this.completedcount = completedcount; + } + + public int getCompletedcount() { + return completedcount; + } + + public void setList(ArrayList list) { + this.list = list; + } + + public ArrayList getList() { + return list; + } + + public StationAssignmentInfo allocinfo(){ + return new StationAssignmentInfo(); + } + + public class StationAssignmentInfo{ + private AssignmentEntity assignment; + private AssignmentStatusEntity status; + + public void setAssignment(AssignmentEntity assignment) { + this.assignment = assignment; + } + + public AssignmentEntity getAssignment() { + return assignment; + } + + public void setStatus(AssignmentStatusEntity status) { + this.status = status; + } + + public AssignmentStatusEntity getStatus() { + return status; + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationNoticeAnalyzeInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationNoticeAnalyzeInfo.java new file mode 100644 index 0000000..aeaa2de --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationNoticeAnalyzeInfo.java @@ -0,0 +1,63 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + + +import com.jingyi.iotserver.firestationport.model.todev.NoticeEntity; +import com.jingyi.iotserver.firestationport.model.todev.NoticeStatusEntity; + +import java.util.ArrayList; + +public class StationNoticeAnalyzeInfo { + private int noticecount; + private int readcount; + + private ArrayList list; + + public void setNoticecount(int noticecount) { + this.noticecount = noticecount; + } + + public int getNoticecount() { + return noticecount; + } + + public void setReadcount(int readcount) { + this.readcount = readcount; + } + + public int getReadcount() { + return readcount; + } + + public void setList(ArrayList list) { + this.list = list; + } + + public ArrayList getList() { + return list; + } + + public StationNoticeInfo allocinfo(){ + return new StationNoticeInfo(); + } + + public class StationNoticeInfo{ + private NoticeEntity notice; + private NoticeStatusEntity status; + + public void setNotice(NoticeEntity notice) { + this.notice = notice; + } + + public NoticeEntity getNotice() { + return notice; + } + + public void setStatus(NoticeStatusEntity status) { + this.status = status; + } + + public NoticeStatusEntity getStatus() { + return status; + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallAckInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallAckInfo.java new file mode 100644 index 0000000..a0795a6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallAckInfo.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import java.util.Date; + +public class StationRollcallAckInfo { + private String number; + private Date starttime; + private String state; + private Date acktime; + + public void setNumber(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setAcktime(Date acktime) { + this.acktime = acktime; + } + + public Date getAcktime() { + return acktime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallCounter.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallCounter.java new file mode 100644 index 0000000..fd2201c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallCounter.java @@ -0,0 +1,38 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class StationRollcallCounter implements Comparable{ + private String name; + private int ack; + private int ignore; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setAck(int ack) { + this.ack = ack; + } + + public int getAck() { + return ack; + } + + public void setIgnore(int ignore) { + this.ignore = ignore; + } + + public int getIgnore() { + return ignore; + } + + @Override + public int compareTo(Object o) { + StationRollcallCounter candidate = (StationRollcallCounter)o; + return (this.getAck() < candidate.getAck() ? -1 : + (this.getAck() == candidate.getAck() ? 0 : 1)); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallReportForm.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallReportForm.java new file mode 100644 index 0000000..b865efd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/StationRollcallReportForm.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +import java.util.List; + +public class StationRollcallReportForm { + private int rollcall; + private int ack; + private int ignore; + private List list; + + public void setRollcall(int rollcall) { + this.rollcall = rollcall; + } + + public int getRollcall() { + return rollcall; + } + + public void setAck(int ack) { + this.ack = ack; + } + + public int getAck() { + return ack; + } + + public void setIgnore(int ignore) { + this.ignore = ignore; + } + + public int getIgnore() { + return ignore; + } + + public void setList(List list) { + this.list = list; + } + + public List getList() { + return list; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SystemCountInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SystemCountInfo.java new file mode 100644 index 0000000..d2424cd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/SystemCountInfo.java @@ -0,0 +1,162 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class SystemCountInfo { + private String brigade; + private int alarmPoint; + private int ipc; + private int partner; + private int vip; + private int ai; + private int station; + + private int borough; + + private int student; + + private String schoolTime; + private int schoolStarCount; + private int schoolColorCount; + private int schoolCheckCount; + private int schoolNewsCount; + private int schoolTaskCount; + private int schoolSignCount; + private int schoolGuardCount; + + + public int getAlarmPoint() { + return alarmPoint; + } + + public void setAlarmPoint(int alarmPoint) { + this.alarmPoint = alarmPoint; + } + + public int getIpc() { + return ipc; + } + + public void setIpc(int ipc) { + this.ipc = ipc; + } + + public int getPartner() { + return partner; + } + + public void setPartner(int partner) { + this.partner = partner; + } + + public int getVip() { + return vip; + } + + public void setVip(int vip) { + this.vip = vip; + } + + public int getAi() { + return ai; + } + + public void setAi(int ai) { + this.ai = ai; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public int getStation() { + return station; + } + + public void setStation(int station) { + this.station = station; + } + + + public int getBorough() { + return borough; + } + + public void setBorough(int borough) { + this.borough = borough; + } + + public int getStudent() { + return student; + } + + public void setStudent(int student) { + this.student = student; + } + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public int getSchoolStarCount() { + return schoolStarCount; + } + + public void setSchoolStarCount(int schoolStarCount) { + this.schoolStarCount = schoolStarCount; + } + + public int getSchoolColorCount() { + return schoolColorCount; + } + + public void setSchoolColorCount(int schoolColorCount) { + this.schoolColorCount = schoolColorCount; + } + + public int getSchoolCheckCount() { + return schoolCheckCount; + } + + public void setSchoolCheckCount(int schoolCheckCount) { + this.schoolCheckCount = schoolCheckCount; + } + + public int getSchoolNewsCount() { + return schoolNewsCount; + } + + public void setSchoolNewsCount(int schoolNewsCount) { + this.schoolNewsCount = schoolNewsCount; + } + + public int getSchoolTaskCount() { + return schoolTaskCount; + } + + public void setSchoolTaskCount(int schoolTaskCount) { + this.schoolTaskCount = schoolTaskCount; + } + + public int getSchoolSignCount() { + return schoolSignCount; + } + + public void setSchoolSignCount(int schoolSignCount) { + this.schoolSignCount = schoolSignCount; + } + + public int getSchoolGuardCount() { + return schoolGuardCount; + } + + public void setSchoolGuardCount(int schoolGuardCount) { + this.schoolGuardCount = schoolGuardCount; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimeCountInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimeCountInfo.java new file mode 100644 index 0000000..636b1b6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimeCountInfo.java @@ -0,0 +1,30 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class TimeCountInfo { + public int seconds; + public int total; + public String index; + public void setSeconds(int seconds) { + this.seconds = seconds; + } + + public int getSeconds() { + return seconds; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getTotal() { + return total; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimePoint.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimePoint.java new file mode 100644 index 0000000..ed4abd9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimePoint.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class TimePoint { + public String time; + public String index; + + public void setTime(String time) { + this.time = time; + } + + public String getTime() { + return time; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimeSegement.java b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimeSegement.java new file mode 100644 index 0000000..727e7b6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/complexquery/TimeSegement.java @@ -0,0 +1,30 @@ +package com.jingyi.iotserver.firestationport.model.complexquery; + +public class TimeSegement { + public String start; + public String end; + public String index; + public void setStart(String start) { + this.start = start; + } + + public String getStart() { + return start; + } + + public void setEnd(String end) { + this.end = end; + } + + public String getEnd() { + return end; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getIndex() { + return index; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/emc/MaterialEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/emc/MaterialEntity.java new file mode 100644 index 0000000..c4dc75f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/emc/MaterialEntity.java @@ -0,0 +1,165 @@ +package com.jingyi.iotserver.firestationport.model.emc; + +public class MaterialEntity { + private String id; + + private String majortype; + private String subtype; + private String status; + + private String storageType; //存储方式:独立存储/仓储. 如为仓储,必须提供仓库ID + private String warehouseId; + private String address; + + private double longitude; + private double latitude; + private double quantity; + private String quantityUnit; + + private double minQuantity; + + private String ownership; + private double ownerPercent; + + private String purpose; + + private String contactName; + private String contactPhone; + private String contactCompany; + private String position; + + private String comment; + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + public String getMajortype() { + return majortype; + } + public void setMajortype(String majortype) { + this.majortype = majortype; + } + public String getSubtype() { + return subtype; + } + public void setSubtype(String subtype) { + this.subtype = subtype; + } + + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public String getStorageType() { + return storageType; + } + public void setStorageType(String storageType) { + this.storageType = storageType; + } + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public double getLongitude() { + return longitude; + } + public void setLongitude(double longitude) { + this.longitude = longitude; + } + public double getLatitude() { + return latitude; + } + public void setLatitude(double latitude) { + this.latitude = latitude; + } + public String getContactName() { + return contactName; + } + public void setContactName(String contactName) { + this.contactName = contactName; + } + public String getContactPhone() { + return contactPhone; + } + public void setContactPhone(String contactPhone) { + this.contactPhone = contactPhone; + } + public String getContactCompany() { + return contactCompany; + } + public void setContactCompany(String contactCompany) { + this.contactCompany = contactCompany; + } + public String getPosition() { + return position; + } + public void setPosition(String position) { + this.position = position; + } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } + + public String getWarehouseId() { + return warehouseId; + } + + public void setWarehouseId(String warehouseId) { + this.warehouseId = warehouseId; + } + + public double getQuantity() { + return quantity; + } + + public void setQuantity(double quantity) { + this.quantity = quantity; + } + + public String getQuantityUnit() { + return quantityUnit; + } + + public void setQuantityUnit(String quantityUnit) { + this.quantityUnit = quantityUnit; + } + + public double getMinQuantity() { + return minQuantity; + } + + public void setMinQuantity(double minQuantity) { + this.minQuantity = minQuantity; + } + + public String getOwnership() { + return ownership; + } + + public void setOwnership(String ownership) { + this.ownership = ownership; + } + + public double getOwnerPercent() { + return ownerPercent; + } + + public void setOwnerPercent(double ownerPercent) { + this.ownerPercent = ownerPercent; + } + + public String getPurpose() { + return purpose; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/EquipmentVerifyEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/EquipmentVerifyEntity.java new file mode 100644 index 0000000..7b77022 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/EquipmentVerifyEntity.java @@ -0,0 +1,141 @@ +package com.jingyi.iotserver.firestationport.model.equipment; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class EquipmentVerifyEntity extends SQLDataObject { + @JPos(index=0,primary = true,orderkey = true) + private int number; + @JPos(index=1,primary = true,filter = true) + private String name; + @JPos(index=2,timekey = true) + private Date timestamp; + @JPos(index=3,filter = true) + private String status; // apply | pass | refuse + @JPos(index=4,strlen = 4096) + private String newSetting; + @JPos(index=5,strlen = 4096) + private String oldSetting; + + public void setNumber(int number) { + this.number = number; + } + + public int getNumber() { + return number; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setNewSetting(String newSetting) { + this.newSetting = newSetting; + } + + public String getNewSetting() { + return newSetting; + } + + public void setOldSetting(String oldSetting) { + this.oldSetting = oldSetting; + } + + public String getOldSetting() { + return oldSetting; + } + + public String tableName(){ + return "equipment_verify_table"; + } + + + + public boolean Insert(DataSource dataSource){ + try{ + timestamp = new Date(); + if(IsExist(dataSource,number)){ + return Update(dataSource); + } + + String sql = InsertSql(); + if(!SQLTools.ExecuteSQL(dataSource,sql)){ + createTable(dataSource); + if(!SQLTools.ExecuteSQL(dataSource,sql)) + return false; + } + }catch (Exception e){ + return false; + } + + return true; + } + + public boolean Delete(DataSource dataSource){ + String sql; + if(name!=null&&name.length()>0) + sql = "DELETE FROM "+tableName()+" WHERE name='"+name+"'"; + else if(number>0) + sql = "DELETE FROM "+tableName()+" WHERE number="+number; + else + return false; + try{ + if(SQLTools.ExecuteSQL(dataSource, sql)) + return true; + }catch (Exception e){ + + } + return false; + } + + public static EquipmentVerifyEntity Query(DataSource dataSource,String name){ + EquipmentVerifyEntity verify = new EquipmentVerifyEntity(); + String sql = "select * from "+verify.tableName()+" where name='"+name+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,EquipmentVerifyEntity.class); + if(list!=null&&list.size()>0){ + return list.get(0); + } + }catch (Exception e){ + + } + return null; + } + + public static boolean IsExist(DataSource dataSource,int number){ + EquipmentVerifyEntity verify = new EquipmentVerifyEntity(); + String sql = "select count(*) from "+verify.tableName()+" where number="+number; + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + if(count>0) + return true; + }catch (Exception e){ + + } + return false; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireCtrlInfoDescriptEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireCtrlInfoDescriptEntity.java new file mode 100644 index 0000000..9e1420b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireCtrlInfoDescriptEntity.java @@ -0,0 +1,64 @@ +package com.jingyi.iotserver.firestationport.model.equipment; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class FireCtrlInfoDescriptEntity extends SQLDataObject { + @JPos(index=0,identify = true,orderkey = true) + private int number; + @JPos(index=1,primary = true,filter = true) + private String info_class; + @JPos(index=2,primary = true,filter = true) + private String title; + @JPos(index=3) + private String descript; + @JPos(index=4,filter = true) + private String type; + + public void setNumber(int number) { + this.number = number; + } + + public int getNumber() { + return number; + } + + public void setInfo_class(String info_class) { + this.info_class = info_class; + } + + public String getInfo_class() { + return info_class; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setDescript(String descript) { + this.descript = descript; + } + + public String getDescript() { + return descript; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public String tableName( ){ + return "firectrl_info_define_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireStationEquipmentEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireStationEquipmentEntity.java new file mode 100644 index 0000000..ecdeb8f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireStationEquipmentEntity.java @@ -0,0 +1,45 @@ +package com.jingyi.iotserver.firestationport.model.equipment; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class FireStationEquipmentEntity extends SQLDataObject { + @JPos(index=0,primary = true,orderkey = true) + private int info_number; + @JPos(index=1,threshold = -1) + private int count; + @JPos(index=2) + private int type;// 0 可选 1必需 + + public void setInfo_number(int info_number) { + this.info_number = info_number; + } + + public int getInfo_number() { + return info_number; + } + + public void setCount(int count) { + this.count = count; + } + + public int getCount() { + return count; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public String tableName(){ + return "firectrl_"+tableExtName+"_equipments_table"; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireStationEquipmentInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireStationEquipmentInfoEntity.java new file mode 100644 index 0000000..9b4bf1b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/FireStationEquipmentInfoEntity.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.equipment; + +public class FireStationEquipmentInfoEntity { + private String title; + private String name; + private int count; + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setCount(int count) { + this.count = count; + } + + public int getCount() { + return count; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/StationEquipmentDescript.java b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/StationEquipmentDescript.java new file mode 100644 index 0000000..b749b8b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/equipment/StationEquipmentDescript.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.equipment; + +public class StationEquipmentDescript { + private int index; + private String title; + private String type; + + public void setIndex(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/InspectStationEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/InspectStationEntity.java new file mode 100644 index 0000000..d7302e8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/InspectStationEntity.java @@ -0,0 +1,152 @@ +package com.jingyi.iotserver.firestationport.model.inspection; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +//微站查岗,检查微站 +public class InspectStationEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String number; + @JPos(index=1,filter = true) + private String station; + @JPos(index=2,filter = true) + private String type; + @JPos(index=3,timekey = true,orderkey = true,update = false) + private Date timestamp; + @JPos(index=4,filter = true) + private String brigade; + @JPos(index=5,filter = true) + private String borough; + @JPos(index=6,filter = true) + private String detachment; + @JPos(index=7,filter = true) + private String reply; + @JPos(index=8) + private String staff; + @JPos(index=9,filter = true) + private String status; + @JPos(index=10,strlen = 2048) + private String remark; + + public void setNumber(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setReply(String reply) { + this.reply = reply; + } + + public String getReply() { + return reply; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getStaff() { + return staff; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getRemark() { + return remark; + } + + public String tableName(){ + return "firectrl_station_inspection_info_table"; + } + + + public static InspectStationEntity Query(DataSource dataSource, Date time){ + InspectStationEntity in = new InspectStationEntity(); + String sql = "select * from "+in.tableName()+" where timestamp='"+SQLTools.formatDate(time)+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, InspectStationEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + public static InspectStationEntity Query(DataSource dataSource, String numb){ + InspectStationEntity in = new InspectStationEntity(); + String sql = "select * from "+in.tableName()+" where number='"+numb+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, InspectStationEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionDeviceEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionDeviceEntity.java new file mode 100644 index 0000000..6d4601e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionDeviceEntity.java @@ -0,0 +1,116 @@ +package com.jingyi.iotserver.firestationport.model.inspection; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +//巡检设备 +public class RoundInspectionDeviceEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String deviceid; + @JPos(index=1,filter = true) + private String type; + @JPos(index=2,filter = true) + private String model; + @JPos(index=3,timekey = true,orderkey = true,update = false) + private Date createtime; + @JPos(index=4) + private Date producttime; + @JPos(index=5,filter = true) + private String manufacturer; + @JPos(index=6,filter = true) + private String station; + @JPos(index=7) + private String address; + @JPos(index=8) + private double longitude; + @JPos(index=9) + private double latitude; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setProducttime(Date producttime) { + this.producttime = producttime; + } + + public Date getProducttime() { + return producttime; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public String getManufacturer() { + return manufacturer; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public String tableName(){ + return "firectrl_round_inspection_device_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionResultEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionResultEntity.java new file mode 100644 index 0000000..01fb80c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionResultEntity.java @@ -0,0 +1,215 @@ +package com.jingyi.iotserver.firestationport.model.inspection; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class RoundInspectionResultEntity extends SQLDataObject { + @JPos(index=0,filter = true) + private String station; + @JPos(index=1,filter = true) + private String deviceid; + @JPos(index=2,filter = true) + private String username; + @JPos(index=3,filter = true) + private String userphone; + + @JPos(index=4,filter = true) + private String taskid; + @JPos(index=5,filter = true) + private String target; + @JPos(index=6,filter = true) + private String status; + @JPos(index=7,filter = true) + private String remark; + + @JPos(index=8,filter = true,strlen = 1024) + private String filepath; + @JPos(index=9,filter = true) + private String filetype; + @JPos(index=10,filter = true,strlen = 1024) + private String url; + @JPos(index=11,orderkey = true,timekey = true,update = false) + private Date timestamp; + @JPos(index=12) + private Date uploadtime; + @JPos(index=13) + private double longitude; + @JPos(index=14) + private double latitude; + @JPos(index=15) + private String address; + @JPos(index=16) + private String fileinfo; + + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setUserphone(String userphone) { + this.userphone = userphone; + } + + public String getUserphone() { + return userphone; + } + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getTarget() { + return target; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getRemark() { + return remark; + } + + public void setFilepath(String filepath) { + this.filepath = filepath; + } + + public String getFilepath() { + return filepath; + } + + public void setFiletype(String filetype) { + this.filetype = filetype; + } + + public String getFiletype() { + return filetype; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUrl() { + return url; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setUploadtime(Date uploadtime) { + this.uploadtime = uploadtime; + } + + public Date getUploadtime() { + return uploadtime; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setFileinfo(String fileinfo) { + this.fileinfo = fileinfo; + } + + public String getFileinfo() { + return fileinfo; + } + + public String tableName(){ + return "firectrl_round_inspection_result_table"; + } + + + public RoundInspectionResultEntity QueryIt(DataSource dataSource){ + String sql = "select * from "+tableName(); + String con = queryCondition(); + if(con!=null) + sql += " where "+con; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, RoundInspectionResultEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + public static List queryTaskResult(DataSource dataSource,String task){ + RoundInspectionResultEntity round = new RoundInspectionResultEntity(); + String sql = "select * from "+round.tableName()+" where taskid='"+task+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, RoundInspectionResultEntity.class); + return list; + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionTaskEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionTaskEntity.java new file mode 100644 index 0000000..781a092 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/inspection/RoundInspectionTaskEntity.java @@ -0,0 +1,140 @@ +package com.jingyi.iotserver.firestationport.model.inspection; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class RoundInspectionTaskEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String taskid; + @JPos(index=1,filter = true) + private String type; + @JPos(index=2,filter = true) + private String sender; + @JPos(index=3,filter = true) + private String receiver; + @JPos(index=4) + private String targets; + @JPos(index=5,timekey = true,orderkey = true,update = false) + private Date timestamp; + @JPos(index=6) + private Date receivedtime; + @JPos(index=7) + private Date completedtime; + @JPos(index=8,filter = true) + private String status;//sent received completed canceled + @JPos(index=9) + private String description; + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setTargets(String targets) { + this.targets = targets; + } + + public String getTargets() { + return targets; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setReceivedtime(Date receivedtime) { + this.receivedtime = receivedtime; + } + + public Date getReceivedtime() { + return receivedtime; + } + + public void setCompletedtime(Date completedtime) { + this.completedtime = completedtime; + } + + public Date getCompletedtime() { + return completedtime; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public String tableName(){ + return "firectrl_round_inspection_task_table"; + } + + + + public static RoundInspectionTaskEntity QueryRoundInspectionTask(DataSource dataSource, String taskid){ + RoundInspectionTaskEntity round = new RoundInspectionTaskEntity(); + String sql = "select * from "+round.tableName()+" where taskid='"+taskid+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, RoundInspectionTaskEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + public boolean UpdateStatus(DataSource dataSource){ + if(status.equals("received")){ + receivedtime = new Date(); + Update(dataSource); + return true; + }else if(status.equals("completed")){ + completedtime = new Date(); + Update(dataSource); + return true; + } + return false; + } + + + public static List queryUnprocessTask(DataSource dataSource , String station){ + RoundInspectionTaskEntity round = new RoundInspectionTaskEntity(); + String sql = "select * from "+round.tableName()+" where receiver='"+station+"' and (status='sent' or status='received')"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, RoundInspectionTaskEntity.class); + + return list; + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/mdev/MDevPartnerInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/mdev/MDevPartnerInfo.java new file mode 100644 index 0000000..706190d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/mdev/MDevPartnerInfo.java @@ -0,0 +1,62 @@ +package com.jingyi.iotserver.firestationport.model.mdev; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class MDevPartnerInfo extends SQLDataObject { + @JPos(index = 0, identify = true) + private int id; + @JPos(index = 1, primary = true, filter = true, update = false) + private String partner; + @JPos(index = 2, filter = true) + private String name; + @JPos(index = 3, filter = true) + private String appkey; + + @JPos(index = 4, filter = true) + private String station; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setPartner(String partner) { + this.partner = partner; + } + + public String getPartner() { + return partner; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setAppkey(String appkey) { + this.appkey = appkey; + } + + public String getAppkey() { + return appkey; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName() { + return "mdev_partner_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/mdev/MDevPictureEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/mdev/MDevPictureEntity.java new file mode 100644 index 0000000..0f8202f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/mdev/MDevPictureEntity.java @@ -0,0 +1,123 @@ +package com.jingyi.iotserver.firestationport.model.mdev; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class MDevPictureEntity extends SQLDataObject { + @JPos(index = 0,primary = true,identify = true) + private String id; + @JPos(index = 1,filter = true) + private String creator; + @JPos(index = 2,filter = true) + private String business; + @JPos(index = 3,filter = true) + private String type; + @JPos(index = 4,filter = true) + private String deviceid; + @JPos(index = 5,update = false,orderkey = true) + private Date uploadtime; + @JPos(index = 6,filter = true) + private Date createtime; + @JPos(index = 7,strlen = 4096) + private String description; + @JPos(index = 8,strlen = 4096) + private String comment; + @JPos(index = 9) + private String filename; + @JPos(index = 10) + private String uri; + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getCreator() { + return creator; + } + + public void setBusiness(String business) { + this.business = business; + } + + public String getBusiness() { + return business; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setUploadtime(Date uploadtime) { + this.uploadtime = uploadtime; + } + + public Date getUploadtime() { + return uploadtime; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getFilename() { + return filename; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getUri() { + return uri; + } + + public String tableName() { + return "station_picture_info_table"; + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/AlarmFileInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/AlarmFileInfo.java new file mode 100644 index 0000000..c85c5af --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/AlarmFileInfo.java @@ -0,0 +1,25 @@ +package com.jingyi.iotserver.firestationport.model.multiPlatform; + +import lombok.Data; + +import java.util.Date; + +@Data +public class AlarmFileInfo { + private String fileName; + private String type; + private String eventId; + private String level; + private String comment; + private String storageType; + private String bucket; + private String path; + private String url; + private String city; + private String district; + private String town; + private String sourceInfo; + private String creatorName; + private Date createTime; + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/MultiAlarmEvent.java b/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/MultiAlarmEvent.java new file mode 100644 index 0000000..cf4c652 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/MultiAlarmEvent.java @@ -0,0 +1,146 @@ +package com.jingyi.iotserver.firestationport.model.multiPlatform; + + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.firestationport.model.publicsafe.PublicAlarmEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JPos; + +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.util.Date; + +import com.jingyi.iotserver.utils.SQLTools; +import lombok.Data; + +@Data +public class MultiAlarmEvent { + + private String eventId; + private String deviceId; + private String deviceType; + private String state; + private String timestamp; + private String city; + private String district; + private String town; + private String station; + private String alarmSource; + private String alarmType; // 刑事民事 + private String alarmCode; //偷盗入侵,打架斗殴,纠纷。。。。。 + private String description; + private String address; + private double longitude; + private double latitude; + private String checkTime; + private String readState; + private String readTime; + private String alarmTarget; + private String pointId; + private String user1Name; + private String user1Phone; + private String user2Name; + private String user2Phone; + private String user3Name; + private String user3Phone; + private String fakeState; + + public MultiAlarmEvent(){ + + } + + public MultiAlarmEvent(SensorAlarmEventEntity myAlarm){ + eventId = myAlarm.getEventId(); + deviceId = myAlarm.getDeviceId(); + deviceType = myAlarm.getDevicetype(); + state = myAlarm.getState(); + timestamp = SQLTools.formatDate(myAlarm.getTimestamp()); + city = myAlarm.getCity(); + district = myAlarm.getDistrict(); + town = myAlarm.getTown(); + station = myAlarm.getStation(); + alarmSource = myAlarm.getAlarmSource(); + alarmType = myAlarm.getAlarmType(); + alarmCode = myAlarm.getAlarmCode(); + address = myAlarm.getAddress(); + longitude = myAlarm.getLongitude(); + latitude = myAlarm.getLatitude(); + + readState = myAlarm.getReadState(); + //readTime = SQLTools.formatDate(myAlarm.getStateTime()) ; + alarmTarget = myAlarm.getAlarmTarget(); + pointId = myAlarm.getDeviceId(); + user1Name = myAlarm.getUser1Name(); + user1Phone = myAlarm.getUser1Phone(); + user2Name = myAlarm.getUser2Name(); + user2Phone = myAlarm.getUser2Phone(); + user3Name = myAlarm.getUser3Name(); + user3Phone = myAlarm.getUser3Phone(); + fakeState = "1"; + } + + public MultiAlarmEvent(PublicAlarmEntity myAlarm){ + eventId = myAlarm.getAlarmId(); + deviceId = myAlarm.getReporterAccount(); + deviceType = "app"; + state = SensorAlarmEventEntity.STATE_Read; + timestamp = SQLTools.formatDate(myAlarm.getReportTime()); + city = myAlarm.getCity(); + district = myAlarm.getDistrict(); + town = myAlarm.getStreet(); + station = ""; + alarmSource = "wechat"; + alarmType = "求助"; + alarmCode = myAlarm.getAlarmType(); + address = myAlarm.getAddress(); + longitude = myAlarm.getLongitude(); + latitude = myAlarm.getLatitude(); + + readState = SensorAlarmEventEntity.STATE_Read; + readTime = SQLTools.formatDate(myAlarm.getCheckTime()) ; + alarmTarget = ""; + pointId = ""; + user1Name = myAlarm.getReporterName(); + user1Phone = myAlarm.getReporterPhone(); + user2Name = ""; + user2Phone = ""; + user3Name = ""; + user3Phone = ""; + fakeState = "1"; + } + + public boolean reportToMultiPlat(){ + boolean reportState = true; + String payload = JSON.toJSONString(this); + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://175.6.124.250:8082/multialarm/alarm/report" ; + System.out.println("process reportToMultiPlat: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("platKey", "LS0001"); + connLogin.setRequestProperty("platToken", "LS0001"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(payload); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("reportToMultiPlat: fail = " + responseCode); + }else{ + System.out.println("reportToMultiPlat: ok = " + responseCode); + } + }catch (Exception e){ + System.out.println("reportToMultiPlat: fail = " + e.getMessage()); + }finally { + + } + + return reportState; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/MultiAlarmPoint.java b/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/MultiAlarmPoint.java new file mode 100644 index 0000000..01354a4 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/multiPlatform/MultiAlarmPoint.java @@ -0,0 +1,423 @@ +package com.jingyi.iotserver.firestationport.model.multiPlatform; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; + +import java.util.Date; + +public class MultiAlarmPoint { + private String pointId; + private String account; + private String pointCode; + private String pointName; + private String pointAddress; + private String sensorType; + private int sensorCount; + private String subCode; + private String status; + private String alarmType; + private Date setupTime; + private String ip; + private String dwbs; + private String dwmc; + private String dwdz; + private String sfnb; + private String userName; + private String userPhone; + private double latitude; + private double longitude; + private String hylxdm; + private String hylx; + private String zdjbdm; + private String zdjb; + private String fenceData; + private String needTranslate; + private String user2Name; + private String user2Phone; + private String user3Name; + private String user3Phone; + private String linkISC; + private String linkICC; + private String linkMobile; + private String deviceType; + private String deviceId; + + private String city; + private String district; + private String town; + private String street; + + private String platKey; + private Date createTime; + + public String getDwbs() { + return dwbs; + } + + public void setDwbs(String dwbs) { + this.dwbs = dwbs; + } + + public String getDwmc() { + return dwmc; + } + + public void setDwmc(String dwmc) { + this.dwmc = dwmc; + } + + public String getDwdz() { + return dwdz; + } + + public void setDwdz(String dwdz) { + this.dwdz = dwdz; + } + + public String getSfnb() { + return sfnb; + } + + public void setSfnb(String sfnb) { + this.sfnb = sfnb; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserPhone() { + return userPhone; + } + + public void setUserPhone(String userPhone) { + this.userPhone = userPhone; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getFenceData() { + return fenceData; + } + + public void setFenceData(String fenceData) { + this.fenceData = fenceData; + } + + public String getHylxdm() { + return hylxdm; + } + + public void setHylxdm(String hylxdm) { + this.hylxdm = hylxdm; + } + + public String getHylx() { + return hylx; + } + + public void setHylx(String hylx) { + this.hylx = hylx; + } + + public String getZdjbdm() { + return zdjbdm; + } + + public void setZdjbdm(String zdjbdm) { + this.zdjbdm = zdjbdm; + } + + public String getZdjb() { + return zdjb; + } + + public void setZdjb(String zdjb) { + this.zdjb = zdjb; + } + + public String getNeedTranslate() { + return needTranslate; + } + + public void setNeedTranslate(String needTranslate) { + this.needTranslate = needTranslate; + } + + public String getPointId() { + return pointId; + } + + public void setPointId(String pointId) { + this.pointId = pointId; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getPointCode() { + return pointCode; + } + + public void setPointCode(String pointCode) { + this.pointCode = pointCode; + } + + public String getPointName() { + return pointName; + } + + public void setPointName(String pointName) { + this.pointName = pointName; + } + + public String getPointAddress() { + return pointAddress; + } + + public void setPointAddress(String pointAddress) { + this.pointAddress = pointAddress; + } + + public String getSensorType() { + return sensorType; + } + + public void setSensorType(String sensorType) { + this.sensorType = sensorType; + } + + public int getSensorCount() { + return sensorCount; + } + + public void setSensorCount(int sensorCount) { + this.sensorCount = sensorCount; + } + + public String getSubCode() { + return subCode; + } + + public void setSubCode(String subCode) { + this.subCode = subCode; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public Date getSetupTime() { + return setupTime; + } + + public void setSetupTime(Date setupTime) { + this.setupTime = setupTime; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getUser2Name() { + return user2Name; + } + + public void setUser2Name(String user2Name) { + this.user2Name = user2Name; + } + + public String getUser2Phone() { + return user2Phone; + } + + public void setUser2Phone(String user2Phone) { + this.user2Phone = user2Phone; + } + + public String getUser3Name() { + return user3Name; + } + + public void setUser3Name(String user3Name) { + this.user3Name = user3Name; + } + + public String getUser3Phone() { + return user3Phone; + } + + public void setUser3Phone(String user3Phone) { + this.user3Phone = user3Phone; + } + + public String getLinkISC() { + return linkISC; + } + + public void setLinkISC(String linkISC) { + this.linkISC = linkISC; + } + + public String getLinkICC() { + return linkICC; + } + + public void setLinkICC(String linkICC) { + this.linkICC = linkICC; + } + + public String getLinkMobile() { + return linkMobile; + } + + public void setLinkMobile(String linkMobile) { + this.linkMobile = linkMobile; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } + + public String getTown() { + return town; + } + + public void setTown(String town) { + this.town = town; + } + + public String getPlatKey() { + return platKey; + } + + public void setPlatKey(String platKey) { + this.platKey = platKey; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public static MultiAlarmPoint copyFromPushPoint(PushAlarmPointEntity pushAlarmPoint){ + MultiAlarmPoint multiAlarmPoint = new MultiAlarmPoint(); + + multiAlarmPoint.pointId = pushAlarmPoint.getPointId(); + multiAlarmPoint.account = pushAlarmPoint.getAccount(); + multiAlarmPoint.pointCode = pushAlarmPoint.getPointCode(); + multiAlarmPoint.pointName = pushAlarmPoint.getPointName(); + multiAlarmPoint.pointAddress = pushAlarmPoint.getPointAddress(); + multiAlarmPoint.sensorType = pushAlarmPoint.getSensorType(); + multiAlarmPoint.sensorCount = pushAlarmPoint.getSensorCount(); + multiAlarmPoint.subCode = pushAlarmPoint.getSubCode(); + multiAlarmPoint.status = pushAlarmPoint.getStatus(); + multiAlarmPoint.alarmType = pushAlarmPoint.getAlarmType(); + multiAlarmPoint.setupTime = pushAlarmPoint.getSetupTime(); + multiAlarmPoint.ip = pushAlarmPoint.getIp(); + multiAlarmPoint.dwbs = pushAlarmPoint.getDwbs(); + multiAlarmPoint.dwmc = pushAlarmPoint.getDwmc(); + multiAlarmPoint.dwdz = pushAlarmPoint.getDwdz(); + multiAlarmPoint.sfnb = pushAlarmPoint.getSfnb(); + multiAlarmPoint.userName = pushAlarmPoint.getUserName(); + multiAlarmPoint.userPhone = pushAlarmPoint.getUserPhone(); + multiAlarmPoint.latitude = pushAlarmPoint.getLatitude(); + multiAlarmPoint.longitude = pushAlarmPoint.getLongitude(); + multiAlarmPoint.hylxdm = pushAlarmPoint.getHylxdm(); + multiAlarmPoint.hylx = pushAlarmPoint.getHylx(); + multiAlarmPoint.zdjbdm = pushAlarmPoint.getZdjbdm(); + multiAlarmPoint.zdjb = pushAlarmPoint.getZdjb(); + multiAlarmPoint.fenceData = pushAlarmPoint.getFenceData(); + multiAlarmPoint.user2Name = pushAlarmPoint.getUser2Name(); + multiAlarmPoint.user2Phone = pushAlarmPoint.getUser2Phone(); + multiAlarmPoint.user3Name = pushAlarmPoint.getUser3Name(); + multiAlarmPoint.user3Phone = pushAlarmPoint.getUser3Phone(); + multiAlarmPoint.linkISC = pushAlarmPoint.getLinkISC(); + multiAlarmPoint.linkICC = pushAlarmPoint.getLinkICC(); + multiAlarmPoint.linkMobile = pushAlarmPoint.getLinkAgora(); + multiAlarmPoint.deviceType = pushAlarmPoint.getDeviceType(); + multiAlarmPoint.deviceId = pushAlarmPoint.getDeviceId(); + multiAlarmPoint.street = pushAlarmPoint.getStreet(); + multiAlarmPoint.city = pushAlarmPoint.getCity(); + multiAlarmPoint.district = pushAlarmPoint.getDistrict(); + multiAlarmPoint.town = pushAlarmPoint.getTown(); + multiAlarmPoint.platKey = "LS0001"; + return multiAlarmPoint; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/partner/CityTruckOrderEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/partner/CityTruckOrderEntity.java new file mode 100644 index 0000000..f09a0f8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/partner/CityTruckOrderEntity.java @@ -0,0 +1,246 @@ +package com.jingyi.iotserver.firestationport.model.partner; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class CityTruckOrderEntity extends SQLDataObject { + @JPos(index = 0, primary = true, filter = true) + private String taskid; + + @JPos(index = 1, filter = true) + private String gatheringaddress; + + @JPos(index = 2) + private int vehiclecount; + + @JPos(index = 3) + private int vehicletimes; + + @JPos(index = 4, filter = true) + private String alarmtype; + + @JPos(index = 5) + private double longitude; + @JPos(index = 6) + private double latitude; + @JPos(index = 7, filter = true) + private String street; + @JPos(index = 8) + private String address; + + @JPos(index = 9, timekey = true, orderkey = true) + private Date pushtime; + + @JPos(index = 10, filter = true) + private String source; + + @JPos(index = 11, filter = true) + private String processor; + + @JPos(index = 12, strlen = 512) + private String vehicles; + + @JPos(index = 13, filter = true) + private Date processtime; + + @JPos(index = 14, filter = true) + private String status; + + @JPos(index = 15, strlen = 1024) + private String sceneimage; + @JPos(index = 16, strlen = 1024) + private String plateiamge; + @JPos(index = 17, strlen = 1024) + private String vehicleimage; + + @JPos(index = 18, strlen = 4096) + private String description; + @JPos(index = 19, filter = true) + private String establish; + @JPos(index = 20, filter = true) + private String readstate; + @JPos(index = 21, filter = true) + private String deviceid; + + public String getTaskid() { + return taskid; + } + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public int getVehiclecount() { + return vehiclecount; + } + + public void setVehiclecount(int vehiclecount) { + this.vehiclecount = vehiclecount; + } + + public int getVehicletimes() { + return vehicletimes; + } + + public void setVehicletimes(int vehicletimes) { + this.vehicletimes = vehicletimes; + } + + public String getGatheringaddress() { + return gatheringaddress; + } + + public void setGatheringaddress(String gatheringaddress) { + this.gatheringaddress = gatheringaddress; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Date getPushtime() { + return pushtime; + } + + public void setPushtime(Date pushtime) { + this.pushtime = pushtime; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getProcessor() { + return processor; + } + + public void setProcessor(String processor) { + this.processor = processor; + } + + public String getVehicles() { + return vehicles; + } + + public void setVehicles(String vehicles) { + this.vehicles = vehicles; + } + + public Date getProcesstime() { + return processtime; + } + + public void setProcesstime(Date processtime) { + this.processtime = processtime; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getSceneimage() { + return sceneimage; + } + + public void setSceneimage(String sceneimage) { + this.sceneimage = sceneimage; + } + + public String getPlateiamge() { + return plateiamge; + } + + public void setPlateiamge(String plateiamge) { + this.plateiamge = plateiamge; + } + + public String getVehicleimage() { + return vehicleimage; + } + + public void setVehicleimage(String vehicleimage) { + this.vehicleimage = vehicleimage; + } + + public String getDescription() { + return description; + } + + public String getEstablish() { + return establish; + } + + public void setEstablish(String establish) { + this.establish = establish; + } + + public void setDescription(String description) { + this.description = description; + } + + public String tableName(){ + return "iotserver_sensor_city_gathering_task_table"; + } + + public String getReadstate() { + return readstate; + } + + public void setReadstate(String readstate) { + this.readstate = readstate; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/partner/PartnerAlarm.java b/src/main/java/com/jingyi/iotserver/firestationport/model/partner/PartnerAlarm.java new file mode 100644 index 0000000..57f597d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/partner/PartnerAlarm.java @@ -0,0 +1,114 @@ +package com.jingyi.iotserver.firestationport.model.partner; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class PartnerAlarm extends SQLDataObject { + @JPos(index = 0, identify = true) + private int id; + @JPos(index = 1, primary = true, filter = true, update = false) + private int parterid; + @JPos(index = 2, filter = true) + private String name; + @JPos(index = 3, filter = true) + private String source;// station | sensor + @JPos(index = 4, filter = true) + private String deviceid; + @JPos(index = 5, filter = true) + private String devicetype; + @JPos(index = 6, filter = true) + private String alarmtype; + @JPos(index = 7, primary = true, timekey = true, orderkey = true, update = false) + private Date timestamp; + @JPos(index = 8, filter = true) + private String state; + @JPos(index = 9) + private String address; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setParterid(int parterid) { + this.parterid = parterid; + } + + public int getParterid() { + return parterid; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setSource(String source) { + this.source = source; + } + + public String getSource() { + return source; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public String tableName() { + return "firectrl_partner_alarm_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/person/PersonLogEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/person/PersonLogEntity.java new file mode 100644 index 0000000..80a5f4f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/person/PersonLogEntity.java @@ -0,0 +1,70 @@ +package com.jingyi.iotserver.firestationport.model.person; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; +import java.util.UUID; + +@Data +public class PersonLogEntity extends SQLDataObject { + + public static final String Operation_Type_Info_Add = "info.add"; + public static final String Operation_Type_Info_Modify = "info.modify"; + public static final String Operation_Type_Info_Delete = "info.delete"; + public static final String Operation_Type_Org_Modify = "org.modify"; + public static final String Operation_Type_Status_Modify = "status.modify"; + public static final String Operation_Type_Device_Change = "device.change"; + + public static final String Status_Onboard = "status.onboard"; + public static final String Status_Leave = "status.leave"; + public static final String Status_Quit = "status.quit"; + + @JPos(index = 0,primary = true, filter = true) + private String logId; + @JPos(index = 1,filter = true) + private String staffId; + @JPos(index = 2, filter = true) + private String operationType; + @JPos(index = 3,filter = true) + private String previousData; + @JPos(index = 4, filter = true,strlen = 1024) + private String nowData; + @JPos(index = 5, filter = true,strlen = 1024) + private String comment; + @JPos(index = 6, timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 7, filter = true) + private String station; + @JPos(index = 8, filter = true) + private String detachment; + @JPos(index = 9, filter = true) + private String borough; + @JPos(index = 10, filter = true) + private String brigade; + @JPos(index = 11, filter = true) + private String department; + @JPos(index = 12, filter = true) + private String company; + + public String tableName( ){ + return "person_operation_log_table"; + } + + public PersonLogEntity(){ + + } + + public PersonLogEntity(SecurityPersonEntity personEntity){ + logId = UUID.randomUUID().toString(); + staffId = personEntity.getStaffId(); + timestamp = new Date(); + station = personEntity.getStation(); + detachment = personEntity.getDetachment(); + borough = personEntity.getBorough(); + brigade = personEntity.getBrigade(); + department = personEntity.getDepartment(); + company = personEntity.getCompany(); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/person/SecurityPersonEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/person/SecurityPersonEntity.java new file mode 100644 index 0000000..39f686e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/person/SecurityPersonEntity.java @@ -0,0 +1,55 @@ +package com.jingyi.iotserver.firestationport.model.person; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class SecurityPersonEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true) + private String staffId; + @JPos(index = 1, filter = true) + private String name; + @JPos(index = 2, filter = true) + private String title; + @JPos(index = 3,filter = true) + private String idCode; + @JPos(index = 4, filter = true) + private String deviceId; + @JPos(index = 5, filter = true) + private String phone; + @JPos(index = 6, filter = true) + private String status; + @JPos(index = 7,timekey = true,orderkey = true) + private Date birthday; + @JPos(index = 8, filter = true) + private String gender; + @JPos(index = 9) + private String address; + @JPos(index = 10) + private String password; + @JPos(index = 11) + private String type; + @JPos(index = 12) + private String level; + @JPos(index = 13, filter = true) + private String station; + @JPos(index = 14, filter = true) + private String detachment; + @JPos(index = 15, filter = true) + private String borough; + @JPos(index = 16, filter = true) + private String brigade; + @JPos(index = 17, filter = true) + private String department; + @JPos(index = 18, filter = true) + private String company; + @JPos(index = 19, filter = true) + private String wechatAccount; + + public String tableName( ){ + return "security_person_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/pluginfo/PlugInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/pluginfo/PlugInfoEntity.java new file mode 100644 index 0000000..29ae502 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/pluginfo/PlugInfoEntity.java @@ -0,0 +1,131 @@ +package com.jingyi.iotserver.firestationport.model.pluginfo; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class PlugInfoEntity extends SQLDataObject { + + @JPos(index = 0, primary = true,filter = true,update = false) + private String id; + + @JPos(index = 1, filter = true) + private String maintype; + + @JPos(index = 2,filter = true) + private String subtype; + + @JPos(index = 3, timekey = true,orderkey = true,update=false) + private Date createtime; + + @JPos(index = 4, strlen = 2048) + private String content;// + + @JPos(index = 5, strlen = 512) + private String comment;// + + @JPos(index = 6, filter = true) + private String createuser;// + + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String station; + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setMaintype(String maintype) { + this.maintype = maintype; + } + + public String getMaintype() { + return maintype; + } + + public void setSubtype(String subtype) { + this.subtype = subtype; + } + + public String getSubtype() { + return subtype; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public void setCreateuser(String createuser) { + this.createuser = createuser; + } + + public String getCreateuser() { + return createuser; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "iotserver_plug_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/publicsafe/PublicAlarmEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/publicsafe/PublicAlarmEntity.java new file mode 100644 index 0000000..fb02541 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/publicsafe/PublicAlarmEntity.java @@ -0,0 +1,142 @@ +package com.jingyi.iotserver.firestationport.model.publicsafe; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.firestationport.model.multiPlatform.AlarmFileInfo; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.util.Date; +import java.util.List; + +@Data +public class PublicAlarmEntity extends SQLDataObject { + public static final String STATE_OPEN= "new"; + public static final String STATE_CHECKED= "checked"; + public static final String STATE_Dispatch = "dispatched"; + public static final String STATE_Closed = "closed"; + + public static final String RESULT_NO = "not"; + public static final String RESULT_PENDING = "pending"; + public static final String RESULT_TRUE = "real"; + public static final String RESULT_FALSE = "fake"; + + @JPos(index = 0,primary = true,filter = true) + private String alarmId; + @JPos(index = 1,filter = true) + private String reporterAccount; + @JPos(index = 2,filter = true) + private String reporterName; + @JPos(index = 3,filter = true) + private String reporterPhone; + @JPos(index = 4) + private String reporterGender; + @JPos(index = 5) + private String address; + @JPos(index = 6) + private double latitude; + @JPos(index = 7) + private double longitude; + @JPos(index = 8,filter = true) + private String province; + @JPos(index = 9,filter = true) + private String city; + @JPos(index = 10,filter = true) + private String district; + @JPos(index = 11,filter = true) + private String street; + @JPos(index = 12,filter = true) + private String adcode; + @JPos(index = 13,filter = true) + private String city_code; + @JPos(index = 14,filter = true) + private String phone_area_code; + @JPos(index = 15) + private String description; + @JPos(index = 16,strlen = 2048) + private String imageUrls; + @JPos(index = 17) + private String checkComment; + @JPos(index = 18,filter = true) + private String status; + @JPos(index = 19,filter = true) + private String checkResult; + @JPos(index = 20,filter = true) + private String mergedAlarmId; + @JPos(index = 21,timekey = true,orderkey = true) + private Date reportTime; + @JPos(index = 22) + private Date checkTime; + @JPos(index = 23) + private Date dispatchTime; + @JPos(index = 24) + private Date closeTime; + @JPos(index = 25,filter = true) + private String alarmType; + + public String tableName( ){ + return "public_alarm_table"; + } + + public boolean reportImageToMultiPlat(){ + boolean reportState = true; + + HttpURLConnection connLogin; + try { + + AlarmFileInfo fileInfo = new AlarmFileInfo(); + fileInfo.setEventId(this.getAlarmId()); + fileInfo.setCity(this.getCity()); + fileInfo.setFileName(this.getImageUrls()); + fileInfo.setDistrict(this.getDistrict()); + fileInfo.setTown(this.getStreet()); + try { + List imageList = JSON.parseArray(this.getImageUrls(), String.class); + if(!imageList.isEmpty()){ + fileInfo.setUrl("https://www.lonsungsh.com:8083/" + imageList.get(0)); + } + + }catch (Exception e){ + fileInfo.setUrl("https://www.lonsungsh.com:8083/" + this.getImageUrls()); + } + + fileInfo.setSourceInfo("wechat"); + fileInfo.setStorageType("plat"); + fileInfo.setCreatorName(this.getReporterName()); + fileInfo.setCreateTime(this.getReportTime()); + fileInfo.setType("image"); + + String payload = JSON.toJSONString(fileInfo); + + String agentUrlLong = "http://175.6.124.250:8082/multialarm/alarm/file/add" ; + System.out.println("process reportToMultiPlat: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("platKey", "LS0001"); + connLogin.setRequestProperty("platToken", "LS0001"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(payload); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("reportToMultiPlat: fail = " + responseCode); + }else{ + System.out.println("reportToMultiPlat: ok = " + responseCode); + } + }catch (Exception e){ + System.out.println("reportToMultiPlat: fail = " + e.getMessage()); + }finally { + + } + + return reportState; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/rollcall/FireStationRollCallAckEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/rollcall/FireStationRollCallAckEntity.java new file mode 100644 index 0000000..2f33292 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/rollcall/FireStationRollCallAckEntity.java @@ -0,0 +1,70 @@ +package com.jingyi.iotserver.firestationport.model.rollcall; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationRollCallAckEntity extends SQLDataObject { + + @JPos(index = 0, identify = true) + private int id; + + @JPos(index = 1, primary = true,filter = true) + private String rollcallnumber; + + @JPos(index = 2, primary = true,filter = true) + private String stationname; + + @JPos(index = 3, timekey = true,orderkey = true) + private Date acktime; + + @JPos(index = 4, filter = true) + private String state;// + + public void setRollcallnumber(String rollcallnumber) { + this.rollcallnumber = rollcallnumber; + } + + public String getRollcallnumber() { + return rollcallnumber; + } + + public void setStationname(String stationname) { + this.stationname = stationname; + } + + public String getStationname() { + return stationname; + } + + public void setAcktime(Date acktime) { + this.acktime = acktime; + } + + public Date getAcktime() { + return acktime; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public String tableName(){ + return "firectrl_roll_call_ack_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/rollcall/FireStationRollCallEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/rollcall/FireStationRollCallEntity.java new file mode 100644 index 0000000..648ec5a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/rollcall/FireStationRollCallEntity.java @@ -0,0 +1,62 @@ +package com.jingyi.iotserver.firestationport.model.rollcall; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationRollCallEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String number; + @JPos(index = 1, filter = true) + private String username; + @JPos(index = 2, filter = true) + private String scope; + @JPos(index = 3, timekey = true,orderkey = true, update = false) + private Date starttime; + + public void setNumber(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getScope() { + return scope; + } + + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public String tableName( ){ + return "firectrl_roll_call_table"; + } + + + public static FireStationRollCallEntity Query(DataSource dataSource,String numb){ + FireStationRollCallEntity roll = new FireStationRollCallEntity(); + roll.setNumber(numb); + return (FireStationRollCallEntity)roll.QueryIt(dataSource); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/AdviceEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/AdviceEntity.java new file mode 100644 index 0000000..305361c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/AdviceEntity.java @@ -0,0 +1,148 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class AdviceEntity extends SQLDataObject { + + public static final String STATE_OPEN= "open"; + public static final String STATE_Closed = "closed"; + public static final String STATE_Dispatch = "dispatched"; + + @JPos(index = 0,primary = true,filter = true) + private String recordId; + @JPos(index = 1,filter = true) + private String adviceId; + @JPos(index = 2,filter = true) + private String sourceId; + @JPos(index = 3) + private String content; + @JPos(index = 4) + private String images; + @JPos(index = 5,filter = true) + private String type; + @JPos(index = 6,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 7,filter = true) + private String station; + @JPos(index = 8,filter = true) + private String detachment; + @JPos(index = 9,filter = true) + private String borough; + @JPos(index = 10,filter = true) + private String brigade; + @JPos(index = 11,filter = true) + private String creatorId; + @JPos(index = 12,filter = true) + private String status; + + public String tableName( ){ + return "advice_info_table"; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getAdviceId() { + return adviceId; + } + + public void setAdviceId(String adviceId) { + this.adviceId = adviceId; + } + + public String getSourceId() { + return sourceId; + } + + public void setSourceId(String sourceId) { + this.sourceId = sourceId; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getImages() { + return images; + } + + public void setImages(String images) { + this.images = images; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getCreatorId() { + return creatorId; + } + + public void setCreatorId(String creatorId) { + this.creatorId = creatorId; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/AlarmFenceEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/AlarmFenceEntity.java new file mode 100644 index 0000000..09104cb --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/AlarmFenceEntity.java @@ -0,0 +1,121 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class AlarmFenceEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String detachment; + @JPos(index = 2,filter = true) + private String borough; + @JPos(index = 3,filter = true) + private String brigade; + @JPos(index = 4,strlen = 8192) + private String redData; + @JPos(index = 5,strlen = 8192) + private String orangeData; + @JPos(index = 6,strlen = 8192) + private String yellowData; + @JPos(index = 7,strlen = 8192) + private String redIPCs; + @JPos(index = 8,strlen = 8192) + private String orangeIPCs; + @JPos(index = 9,strlen = 8192) + private String yellowIPCs; + @JPos(index = 10,strlen = 8192) + private String stationFence; + + public String tableName(){ + return "skynet_alarm_fence_table"; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getRedData() { + return redData; + } + + public void setRedData(String redData) { + this.redData = redData; + } + + public String getOrangeData() { + return orangeData; + } + + public void setOrangeData(String orangeData) { + this.orangeData = orangeData; + } + + public String getYellowData() { + return yellowData; + } + + public void setYellowData(String yellowData) { + this.yellowData = yellowData; + } + + public String getRedIPCs() { + return redIPCs; + } + + public void setRedIPCs(String redIPCs) { + this.redIPCs = redIPCs; + } + + public String getOrangeIPCs() { + return orangeIPCs; + } + + public void setOrangeIPCs(String orangeIPCs) { + this.orangeIPCs = orangeIPCs; + } + + public String getYellowIPCs() { + return yellowIPCs; + } + + public void setYellowIPCs(String yellowIPCs) { + this.yellowIPCs = yellowIPCs; + } + + public String getStationFence() { + return stationFence; + } + + public void setStationFence(String stationFence) { + this.stationFence = stationFence; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/BrigadeColorRatingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/BrigadeColorRatingEntity.java new file mode 100644 index 0000000..99cbfbb --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/BrigadeColorRatingEntity.java @@ -0,0 +1,253 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class BrigadeColorRatingEntity extends SQLDataObject { + @JPos(index = 0, primary = true, filter = true) + private String brigade; + @JPos(index = 4, timekey = true) + private Date timestamp; + @JPos(index = 5, orderkey = true) + private int scoreTotal; + @JPos(index = 6) + private int scoreHuman; + @JPos(index = 7) + private int scoreDevices; + @JPos(index = 8) + private int scoreTech; + @JPos(index = 9) + private int scoreDesire; + @JPos(index = 10) + private int scoreScheme; + @JPos(index = 11, threshold = -100) + private int scoreCase; + + private int humanGreenStations; + private int humanYellowStations; + private int humanRedStations; + + private int deviceGreenStations; + private int deviceYellowStations; + private int deviceRedStations; + + private int techGreenStations; + private int techYellowStations; + private int techRedStations; + + private int desireGreenStations; + private int desireYellowStations; + private int desireRedStations; + + private int schemeGreenStations; + private int schemeYellowStations; + private int schemeRedStations; + + private int caseStations; + + public String tableName() {return "brigade_color_rating_table"; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreHuman() { + return scoreHuman; + } + + public void setScoreHuman(int scoreHuman) { + this.scoreHuman = scoreHuman; + } + + public int getScoreDevices() { + return scoreDevices; + } + + public void setScoreDevices(int scoreDevices) { + this.scoreDevices = scoreDevices; + } + + public int getScoreTech() { + return scoreTech; + } + + public void setScoreTech(int scoreTech) { + this.scoreTech = scoreTech; + } + + public int getScoreDesire() { + return scoreDesire; + } + + public void setScoreDesire(int scoreDesire) { + this.scoreDesire = scoreDesire; + } + + public int getScoreScheme() { + return scoreScheme; + } + + public void setScoreScheme(int scoreScheme) { + this.scoreScheme = scoreScheme; + } + + public int getScoreCase() { + return scoreCase; + } + + public void setScoreCase(int scoreCase) { + this.scoreCase = scoreCase; + } + + public int getHumanGreenStations() { + return humanGreenStations; + } + + public void setHumanGreenStations(int humanGreenStations) { + this.humanGreenStations = humanGreenStations; + } + + public int getHumanYellowStations() { + return humanYellowStations; + } + + public void setHumanYellowStations(int humanYellowStations) { + this.humanYellowStations = humanYellowStations; + } + + public int getHumanRedStations() { + return humanRedStations; + } + + public void setHumanRedStations(int humanRedStations) { + this.humanRedStations = humanRedStations; + } + + public int getDeviceGreenStations() { + return deviceGreenStations; + } + + public void setDeviceGreenStations(int deviceGreenStations) { + this.deviceGreenStations = deviceGreenStations; + } + + public int getDeviceYellowStations() { + return deviceYellowStations; + } + + public void setDeviceYellowStations(int deviceYellowStations) { + this.deviceYellowStations = deviceYellowStations; + } + + public int getDeviceRedStations() { + return deviceRedStations; + } + + public void setDeviceRedStations(int deviceRedStations) { + this.deviceRedStations = deviceRedStations; + } + + public int getTechGreenStations() { + return techGreenStations; + } + + public void setTechGreenStations(int techGreenStations) { + this.techGreenStations = techGreenStations; + } + + public int getTechYellowStations() { + return techYellowStations; + } + + public void setTechYellowStations(int techYellowStations) { + this.techYellowStations = techYellowStations; + } + + public int getTechRedStations() { + return techRedStations; + } + + public void setTechRedStations(int techRedStations) { + this.techRedStations = techRedStations; + } + + public int getDesireGreenStations() { + return desireGreenStations; + } + + public void setDesireGreenStations(int desireGreenStations) { + this.desireGreenStations = desireGreenStations; + } + + public int getDesireYellowStations() { + return desireYellowStations; + } + + public void setDesireYellowStations(int desireYellowStations) { + this.desireYellowStations = desireYellowStations; + } + + public int getDesireRedStations() { + return desireRedStations; + } + + public void setDesireRedStations(int desireRedStations) { + this.desireRedStations = desireRedStations; + } + + public int getSchemeGreenStations() { + return schemeGreenStations; + } + + public void setSchemeGreenStations(int schemeGreenStations) { + this.schemeGreenStations = schemeGreenStations; + } + + public int getSchemeYellowStations() { + return schemeYellowStations; + } + + public void setSchemeYellowStations(int schemeYellowStations) { + this.schemeYellowStations = schemeYellowStations; + } + + public int getSchemeRedStations() { + return schemeRedStations; + } + + public void setSchemeRedStations(int schemeRedStations) { + this.schemeRedStations = schemeRedStations; + } + + public int getCaseStations() { + return caseStations; + } + + public void setCaseStations(int caseStations) { + this.caseStations = caseStations; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignEventEntity.java new file mode 100644 index 0000000..d0a47bc --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignEventEntity.java @@ -0,0 +1,223 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class GuardSignEventEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String signId; + @JPos(index = 1,filter = true) + private String tagId; + @JPos(index = 2,filter = true) + private String personId; + @JPos(index = 3,filter = true) + private String personName; + @JPos(index = 4,filter = true) + private String personType; + @JPos(index = 5,timekey = true,orderkey = true) + private Date signTimestamp; + @JPos(index = 6,filter = true) + private String taskId; + @JPos(index = 7,filter = true) + private int year; + @JPos(index = 8,filter = true) + private int month; + @JPos(index = 9,filter = true) + private int day; + @JPos(index = 10,filter = true) + private String targetId; + @JPos(index = 11,filter = true) + private String station; + @JPos(index = 12,filter = true) + private String detachment; + @JPos(index = 13,filter = true) + private String borough; + @JPos(index = 14,filter = true) + private String brigade; + @JPos(index=15,floatthreshold = -1.0f) + private double longitude; + @JPos(index=16,floatthreshold = -1.0f) + private double latitude; + @JPos(index = 17) + private String address; + @JPos(index = 18, strlen = 1024) + private String images; + @JPos(index = 19, strlen = 2048) + private String imageUrls; + + private String post; + + public String tableName(){ + return "guard_sign_event_record_table"; + } + + public String getTagId() { + return tagId; + } + + public void setTagId(String tagId) { + this.tagId = tagId; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getPersonType() { + return personType; + } + + public void setPersonType(String personType) { + this.personType = personType; + } + + public Date getSignTimestamp() { + return signTimestamp; + } + + public void setSignTimestamp(Date signTimestamp) { + this.signTimestamp = signTimestamp; + } + + public String getSignId() { + return signId; + } + + public void setSignId(String signId) { + this.signId = signId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getTargetId() { + return targetId; + } + + public void setTargetId(String targetId) { + this.targetId = targetId; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getImages() { + return images; + } + + public void setImages(String images) { + this.images = images; + } + + public String getImageUrls() { + return imageUrls; + } + + public void setImageUrls(String imageUrls) { + this.imageUrls = imageUrls; + } + + public String getPost() { + return post; + } + + public void setPost(String post) { + this.post = post; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignTargetEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignTargetEntity.java new file mode 100644 index 0000000..b63aade --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignTargetEntity.java @@ -0,0 +1,110 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class GuardSignTargetEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String targetId; + @JPos(index = 1,filter = true) + private String tagId; + @JPos(index = 2) + private String address; + @JPos(index = 3) + private double longitude; + @JPos(index = 4) + private double latitude; + @JPos(index = 5,filter = true) + private String station; + @JPos(index = 6,filter = true) + private String detachment; + @JPos(index = 7,filter = true) + private String borough; + @JPos(index = 8,filter = true) + private String brigade; + + public String tableName(){ + return "guard_sign_target_table"; + } + + public GuardSignTargetEntity(){ + + } + + public GuardSignTargetEntity(String nfcId){ + tagId = nfcId; + } + + public String getTagId() { + return tagId; + } + + public void setTagId(String tagId) { + this.tagId = tagId; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public void setTargetId(String targetId) { + this.targetId = targetId; + } + public String getTargetId() { + return targetId; + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignTaskEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignTaskEntity.java new file mode 100644 index 0000000..275ea12 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/GuardSignTaskEntity.java @@ -0,0 +1,133 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class GuardSignTaskEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String taskId; + @JPos(index = 1,filter = true) + private String tagId; + @JPos(index = 2,filter = true) + private String personType; + @JPos(index = 3) + private Date startTime; + @JPos(index = 4) + private Date endTime; + @JPos(index = 5) + private String address; + @JPos(index = 6) + private double longitude; + @JPos(index = 7) + private double latitude; + @JPos(index = 8,filter = true) + private String station; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index = 11,filter = true) + private String brigade; + + public String tableName(){ + return "guard_sign_task_table"; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getTagId() { + return tagId; + } + + public void setTagId(String tagId) { + this.tagId = tagId; + } + + public String getPersonType() { + return personType; + } + + public void setPersonType(String personType) { + this.personType = personType; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/ImportantStation.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/ImportantStation.java new file mode 100644 index 0000000..b414be6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/ImportantStation.java @@ -0,0 +1,101 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class ImportantStation extends SQLDataObject { + @JPos(index = 0,orderkey = true) + private int number; + @JPos(index = 1,primary = true,filter = true) + private String name; + @JPos(index = 2,filter = true) + private String brigade; + @JPos(index = 3,filter = true) + private String policeStation; + @JPos(index = 4) + private String address; + @JPos(index = 5,filter = true) + private String type; + @JPos(index = 6,filter = true) + private String level; + @JPos(index = 7) + private String legalPerson; + @JPos(index = 8) + private String legalPersonPhone; + + public String tableName(){ + return "important_station_table"; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getPoliceStation() { + return policeStation; + } + + public void setPoliceStation(String policeStation) { + this.policeStation = policeStation; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getLegalPerson() { + return legalPerson; + } + + public void setLegalPerson(String legalPerson) { + this.legalPerson = legalPerson; + } + + public String getLegalPersonPhone() { + return legalPersonPhone; + } + + public void setLegalPersonPhone(String legalPersonPhone) { + this.legalPersonPhone = legalPersonPhone; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/NewsOpRecordEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/NewsOpRecordEntity.java new file mode 100644 index 0000000..5b999a3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/NewsOpRecordEntity.java @@ -0,0 +1,104 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class NewsOpRecordEntity extends SQLDataObject { + + public static final String OP_CREATE = "create"; + public static final String OP_MODIFY = "modify"; + public static final String OP_DELETE = "delete"; + + public static final String OP_SET_OPEN= "open"; + public static final String OP_SET_HIDE = "hide"; + + public static final String OP_PRAISE = "praise"; + public static final String OP_REMARK = "remark"; + + @JPos(index = 0,primary = true,filter = true) + private String recordId; + @JPos(index = 1,filter = true) + private String newsId; + @JPos(index = 2,filter = true) + private String personId; + @JPos(index = 3,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 4,filter = true) + private String personName; + @JPos(index = 5) + private String personType; + @JPos(index = 6,filter = true) + private String op; + @JPos(index = 7,strlen = 1024) + private String data; + + public String tableName(){ + return "news_op_record_table"; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getNewsId() { + return newsId; + } + + public void setNewsId(String newsId) { + this.newsId = newsId; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getPersonType() { + return personType; + } + + public void setPersonType(String personType) { + this.personType = personType; + } + + public String getOp() { + return op; + } + + public void setOp(String op) { + this.op = op; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/NewsRemarkEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/NewsRemarkEntity.java new file mode 100644 index 0000000..8059b9f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/NewsRemarkEntity.java @@ -0,0 +1,107 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class NewsRemarkEntity extends SQLDataObject { + public static final String STATE_OPEN= "open"; + public static final String STATE_HIDE = "hide"; + + @JPos(index = 0,primary = true,filter = true) + private String recordId; + @JPos(index = 1,filter = true) + private String newsId; + @JPos(index = 2,filter = true) + private String personId; + @JPos(index = 3,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 4,filter = true) + private String personName; + @JPos(index = 5,strlen = 1024) + private String data; + @JPos(index = 6,filter = true) + private String state; + @JPos(index = 7) + private String checker; + @JPos(index = 8) + private Date checkTime; + + public String tableName(){ + return "news_remark_table"; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getNewsId() { + return newsId; + } + + public void setNewsId(String newsId) { + this.newsId = newsId; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getChecker() { + return checker; + } + + public void setChecker(String checker) { + this.checker = checker; + } + + public Date getCheckTime() { + return checkTime; + } + + public void setCheckTime(Date checkTime) { + this.checkTime = checkTime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/PendingProcessItem.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PendingProcessItem.java new file mode 100644 index 0000000..252d80b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PendingProcessItem.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class PendingProcessItem { + + private String station; + private String itemCode; + + private String itemValue; + + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getItemCode() { + return itemCode; + } + + public void setItemCode(String itemCode) { + this.itemCode = itemCode; + } + + public String getItemValue() { + return itemValue; + } + + public void setItemValue(String itemValue) { + this.itemValue = itemValue; + } + + public String toString(){ + return itemValue + ";"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/PersonBlacklistEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PersonBlacklistEntity.java new file mode 100644 index 0000000..5f43aa8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PersonBlacklistEntity.java @@ -0,0 +1,103 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class PersonBlacklistEntity extends SQLDataObject { + + @JPos(index=0,primary = true, filter = true) + private String personId; + @JPos(index=1,filter = true) + private String personName; + @JPos(index=2) + private String genderName; + @JPos(index=3,filter = true) + private String groupType; + @JPos(index=4,filter = true) + private String groupLevel; + @JPos(index=5,filter = true) + private String personLevel; + @JPos(index=6,strlen = 512000) + private String imageData; + @JPos(index=7,strlen = 2048) + private String imageUrl; + @JPos(index=8,filter = true) + private String controlStatus; + + + public String tableName( ){ + return "person_blacklist_table"; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getGenderName() { + return genderName; + } + + public void setGenderName(String genderName) { + this.genderName = genderName; + } + + public String getGroupType() { + return groupType; + } + + public void setGroupType(String groupType) { + this.groupType = groupType; + } + + public String getGroupLevel() { + return groupLevel; + } + + public void setGroupLevel(String groupLevel) { + this.groupLevel = groupLevel; + } + + public String getPersonLevel() { + return personLevel; + } + + public void setPersonLevel(String personLevel) { + this.personLevel = personLevel; + } + + public String getImageData() { + return imageData; + } + + public void setImageData(String imageData) { + this.imageData = imageData; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public String getControlStatus() { + return controlStatus; + } + + public void setControlStatus(String controlStatus) { + this.controlStatus = controlStatus; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/PoliceNewsEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PoliceNewsEntity.java new file mode 100644 index 0000000..0784547 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PoliceNewsEntity.java @@ -0,0 +1,154 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class PoliceNewsEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String newsId; + @JPos(index = 1,filter = true) + private String creator; + @JPos(index = 2,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 3,filter = true) + private String title; + @JPos(index = 4, strlen = 1024) + private String overview; + @JPos(index = 5, strlen = 1024) + private String imageUrl; + @JPos(index = 6, strlen = 2048) + private String docUrl; + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String station; + @JPos(index = 11,filter = true) + private String type; + @JPos(index = 12) + private int remarkCount; + @JPos(index = 13) + private int praiseCount; + + + public String tableName() { + return "police_news_report_table"; + } + public String getNewsId() { + return newsId; + } + + public void setNewsId(String newsId) { + this.newsId = newsId; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getOverview() { + return overview; + } + + public void setOverview(String overview) { + this.overview = overview; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDocUrl() { + return docUrl; + } + + public void setDocUrl(String docUrl) { + this.docUrl = docUrl; + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public int getRemarkCount() { + return remarkCount; + } + + public void setRemarkCount(int remarkCount) { + this.remarkCount = remarkCount; + } + + public int getPraiseCount() { + return praiseCount; + } + + public void setPraiseCount(int praiseCount) { + this.praiseCount = praiseCount; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/PublicNewsEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PublicNewsEntity.java new file mode 100644 index 0000000..e66240d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/PublicNewsEntity.java @@ -0,0 +1,125 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class PublicNewsEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String newsId; + @JPos(index = 1,filter = true) + private String creator; + @JPos(index = 2,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 3,filter = true) + private String title; + @JPos(index = 4, strlen = 1024) + private String description; + @JPos(index = 5, strlen = 1024) + private String images; + @JPos(index = 6, strlen = 2048) + private String webUrl; + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String type; + + + public String tableName() { + return "public_news_table"; + } + public String getNewsId() { + return newsId; + } + + public void setNewsId(String newsId) { + this.newsId = newsId; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getImages() { + return images; + } + + public void setImages(String images) { + this.images = images; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getWebUrl() { + return webUrl; + } + + public void setWebUrl(String webUrl) { + this.webUrl = webUrl; + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} + diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorDetailEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorDetailEntity.java new file mode 100644 index 0000000..9ee7c9e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorDetailEntity.java @@ -0,0 +1,760 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolColorDetailEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + + @JPos(index = 4,timekey = true) + private Date timestamp; + + @JPos(index = 5,orderkey = true) + private int scoreTotal; + @JPos(index = 6) + private int scoreHuman; + @JPos(index = 7) + private int scoreDevices; + @JPos(index = 8) + private int scoreTech; + @JPos(index = 9) + private int scoreDesire; + @JPos(index = 10) + private int scoreScheme; + @JPos(index = 11) + private int scoreCase; + + @JPos(index = 12) + private String guarderCountDetail; + @JPos(index = 13) + private int guarderCount; + @JPos(index = 14) + private String guarderCertDetail; + @JPos(index = 15) + private int guarderCert; + @JPos(index = 16) + private String guarderOverAgeDetail; + @JPos(index = 17) + private int guarderOverAge; + @JPos(index = 18) + private String peakGuarderArmedDetail; + @JPos(index = 19) + private int peakGuarderArmed; + @JPos(index = 20) + private String peakProtectSchemeDetail; + @JPos(index = 21) + private int peakProtectScheme; + @JPos(index = 22) + private String peakStaffDetail; + @JPos(index = 23) + private int peakStaff; + @JPos(index = 24) + private String zoneClosedDetail; + @JPos(index = 25) + private int zoneClosed; + @JPos(index = 26) + private String equipCountDetail; + @JPos(index = 27) + private int equipCount; + @JPos(index = 28) + private String collisionDetail; + @JPos(index = 29) + private int collision; + @JPos(index = 30) + private String ipcCoverDetail; + @JPos(index = 31) + private int ipcCover; + @JPos(index = 32) + private String alarmSystemDetail; + @JPos(index = 33) + private int alarmSystem; + @JPos(index = 34) + private String ipcGateDetail; + @JPos(index = 35) + private int ipcGate; + @JPos(index = 36) + private String ipcRecordDetail; + @JPos(index = 37) + private int ipcRecord; + @JPos(index = 38) + private String lawEducationDetail; + @JPos(index = 39) + private int lawEducation; + @JPos(index = 40) + private String conflictDetail; + @JPos(index = 41) + private int conflict; + @JPos(index = 42) + private String guarderSchemeDetail; + @JPos(index = 43) + private int guarderScheme; + @JPos(index = 44) + private String buildingSchemeDetail; + @JPos(index = 45) + private int buildingScheme; + @JPos(index = 46) + private String fireSchemeDetail; + @JPos(index = 47) + private int fireScheme; + @JPos(index = 48) + private String dangerousSchemeDetail; + @JPos(index = 49) + private int dangerousScheme; + @JPos(index = 50) + private String conflictSchemeDetail; + @JPos(index = 51) + private int conflictScheme; + @JPos(index = 52) + private String guarderPMISchemeDetail; + @JPos(index = 53) + private int guarderPMIScheme; + @JPos(index = 54) + private String securityServiceSchemeDetail; + @JPos(index = 55) + private int securityServiceScheme; + @JPos(index = 56) + private String criminalCaseDetail; + @JPos(index = 57,threshold = -100) + private int criminalCase; + @JPos(index = 58, filter = true) + private String checkerName; + @JPos(index = 59, primary = true, filter = true) + private String schoolTime; + + @JPos(index = 60,strlen = 10240) + private String signatureImage; + + @JPos(index = 61,strlen = 10240) + private String signatureImageSchool; + @JPos(index = 62,strlen = 1024) + private String comment; + + public String tableName(){ + return "school_color_detail_table"; + } + + public SchoolColorDetailEntity(){ + this.station = ""; + this.brigade = ""; + this.detachment = ""; + this.borough = ""; + this.timestamp = new Date(); + this.scoreTotal = 0; + this.scoreHuman = 0; + this.scoreDevices = 0; + this.scoreTech = 0; + this.scoreDesire = 0; + this.scoreScheme = 0; + this.scoreCase = 0; + this.guarderCountDetail = ""; + this.guarderCount = 0; + this.guarderCertDetail = ""; + this.guarderCert = 0; + this.guarderOverAgeDetail = ""; + this.guarderOverAge = 0; + this.peakGuarderArmedDetail = ""; + this.peakGuarderArmed = 0; + this.peakProtectSchemeDetail = ""; + this.peakProtectScheme = 0; + this.peakStaffDetail = ""; + this.peakStaff = 0; + this.zoneClosedDetail = ""; + this.zoneClosed = 0; + this.equipCountDetail = ""; + this.equipCount = 0; + this.collisionDetail = ""; + this.collision = 0; + this.ipcCoverDetail = ""; + this.ipcCover = 0; + this.alarmSystemDetail = ""; + this.alarmSystem = 0; + this.ipcGateDetail = ""; + this.ipcGate = 0; + this.ipcRecordDetail = ""; + this.ipcRecord = 0; + this.lawEducationDetail = ""; + this.lawEducation = 0; + this.conflictDetail = ""; + this.conflict = 0; + this.guarderSchemeDetail = ""; + this.guarderScheme = 0; + this.buildingSchemeDetail = ""; + this.buildingScheme = 0; + this.fireSchemeDetail = ""; + this.fireScheme = 0; + this.dangerousSchemeDetail = ""; + this.dangerousScheme = 0; + this.conflictSchemeDetail = ""; + this.conflictScheme = 0; + this.guarderPMISchemeDetail = ""; + this.guarderPMIScheme = 0; + this.securityServiceSchemeDetail = ""; + this.securityServiceScheme = 0; + this.criminalCaseDetail = ""; + this.criminalCase = 0; + this.checkerName = ""; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreHuman() { + return scoreHuman; + } + + public void setScoreHuman(int scoreHuman) { + this.scoreHuman = scoreHuman; + } + + public int getScoreDevices() { + return scoreDevices; + } + + public void setScoreDevices(int scoreDevices) { + this.scoreDevices = scoreDevices; + } + + public int getScoreTech() { + return scoreTech; + } + + public void setScoreTech(int scoreTech) { + this.scoreTech = scoreTech; + } + + public int getScoreDesire() { + return scoreDesire; + } + + public void setScoreDesire(int scoreDesire) { + this.scoreDesire = scoreDesire; + } + + public int getScoreScheme() { + return scoreScheme; + } + + public void setScoreScheme(int scoreScheme) { + this.scoreScheme = scoreScheme; + } + + public int getScoreCase() { + return scoreCase; + } + + public void setScoreCase(int scoreCase) { + this.scoreCase = scoreCase; + } + + public String getGuarderCountDetail() { + return guarderCountDetail; + } + + public void setGuarderCountDetail(String guarderCountDetail) { + this.guarderCountDetail = guarderCountDetail; + } + + public int getGuarderCount() { + return guarderCount; + } + + public void setGuarderCount(int guarderCount) { + this.guarderCount = guarderCount; + } + + public String getGuarderCertDetail() { + return guarderCertDetail; + } + + public void setGuarderCertDetail(String guarderCertDetail) { + this.guarderCertDetail = guarderCertDetail; + } + + public int getGuarderCert() { + return guarderCert; + } + + public void setGuarderCert(int guarderCert) { + this.guarderCert = guarderCert; + } + + public String getGuarderOverAgeDetail() { + return guarderOverAgeDetail; + } + + public void setGuarderOverAgeDetail(String guarderOverAgeDetail) { + this.guarderOverAgeDetail = guarderOverAgeDetail; + } + + public int getGuarderOverAge() { + return guarderOverAge; + } + + public void setGuarderOverAge(int guarderOverAge) { + this.guarderOverAge = guarderOverAge; + } + + public String getPeakGuarderArmedDetail() { + return peakGuarderArmedDetail; + } + + public void setPeakGuarderArmedDetail(String peakGuarderArmedDetail) { + this.peakGuarderArmedDetail = peakGuarderArmedDetail; + } + + public int getPeakGuarderArmed() { + return peakGuarderArmed; + } + + public void setPeakGuarderArmed(int peakGuarderArmed) { + this.peakGuarderArmed = peakGuarderArmed; + } + + public String getPeakProtectSchemeDetail() { + return peakProtectSchemeDetail; + } + + public void setPeakProtectSchemeDetail(String peakProtectSchemeDetail) { + this.peakProtectSchemeDetail = peakProtectSchemeDetail; + } + + public int getPeakProtectScheme() { + return peakProtectScheme; + } + + public void setPeakProtectScheme(int peakProtectScheme) { + this.peakProtectScheme = peakProtectScheme; + } + + public String getPeakStaffDetail() { + return peakStaffDetail; + } + + public void setPeakStaffDetail(String peakStaffDetail) { + this.peakStaffDetail = peakStaffDetail; + } + + public int getPeakStaff() { + return peakStaff; + } + + public void setPeakStaff(int peakStaff) { + this.peakStaff = peakStaff; + } + + public String getZoneClosedDetail() { + return zoneClosedDetail; + } + + public void setZoneClosedDetail(String zoneClosedDetail) { + this.zoneClosedDetail = zoneClosedDetail; + } + + public int getZoneClosed() { + return zoneClosed; + } + + public void setZoneClosed(int zoneClosed) { + this.zoneClosed = zoneClosed; + } + + public String getEquipCountDetail() { + return equipCountDetail; + } + + public void setEquipCountDetail(String equipCountDetail) { + this.equipCountDetail = equipCountDetail; + } + + public int getEquipCount() { + return equipCount; + } + + public void setEquipCount(int equipCount) { + this.equipCount = equipCount; + } + + public String getCollisionDetail() { + return collisionDetail; + } + + public void setCollisionDetail(String collisionDetail) { + this.collisionDetail = collisionDetail; + } + + public int getCollision() { + return collision; + } + + public void setCollision(int collision) { + this.collision = collision; + } + + public String getIpcCoverDetail() { + return ipcCoverDetail; + } + + public void setIpcCoverDetail(String ipcCoverDetail) { + this.ipcCoverDetail = ipcCoverDetail; + } + + public int getIpcCover() { + return ipcCover; + } + + public void setIpcCover(int ipcCover) { + this.ipcCover = ipcCover; + } + + public String getAlarmSystemDetail() { + return alarmSystemDetail; + } + + public void setAlarmSystemDetail(String alarmSystemDetail) { + this.alarmSystemDetail = alarmSystemDetail; + } + + public int getAlarmSystem() { + return alarmSystem; + } + + public void setAlarmSystem(int alarmSystem) { + this.alarmSystem = alarmSystem; + } + + public String getIpcGateDetail() { + return ipcGateDetail; + } + + public void setIpcGateDetail(String ipcGateDetail) { + this.ipcGateDetail = ipcGateDetail; + } + + public int getIpcGate() { + return ipcGate; + } + + public void setIpcGate(int ipcGate) { + this.ipcGate = ipcGate; + } + + public String getIpcRecordDetail() { + return ipcRecordDetail; + } + + public void setIpcRecordDetail(String ipcRecordDetail) { + this.ipcRecordDetail = ipcRecordDetail; + } + + public int getIpcRecord() { + return ipcRecord; + } + + public void setIpcRecord(int ipcRecord) { + this.ipcRecord = ipcRecord; + } + + public String getLawEducationDetail() { + return lawEducationDetail; + } + + public void setLawEducationDetail(String lawEducationDetail) { + this.lawEducationDetail = lawEducationDetail; + } + + public int getLawEducation() { + return lawEducation; + } + + public void setLawEducation(int lawEducation) { + this.lawEducation = lawEducation; + } + + public String getConflictDetail() { + return conflictDetail; + } + + public void setConflictDetail(String conflictDetail) { + this.conflictDetail = conflictDetail; + } + + public int getConflict() { + return conflict; + } + + public void setConflict(int conflict) { + this.conflict = conflict; + } + + public String getGuarderSchemeDetail() { + return guarderSchemeDetail; + } + + public void setGuarderSchemeDetail(String guarderSchemeDetail) { + this.guarderSchemeDetail = guarderSchemeDetail; + } + + public int getGuarderScheme() { + return guarderScheme; + } + + public void setGuarderScheme(int guarderScheme) { + this.guarderScheme = guarderScheme; + } + + public String getBuildingSchemeDetail() { + return buildingSchemeDetail; + } + + public void setBuildingSchemeDetail(String buildingSchemeDetail) { + this.buildingSchemeDetail = buildingSchemeDetail; + } + + public int getBuildingScheme() { + return buildingScheme; + } + + public void setBuildingScheme(int buildingScheme) { + this.buildingScheme = buildingScheme; + } + + public String getFireSchemeDetail() { + return fireSchemeDetail; + } + + public void setFireSchemeDetail(String fireSchemeDetail) { + this.fireSchemeDetail = fireSchemeDetail; + } + + public int getFireScheme() { + return fireScheme; + } + + public void setFireScheme(int fireScheme) { + this.fireScheme = fireScheme; + } + + public String getDangerousSchemeDetail() { + return dangerousSchemeDetail; + } + + public void setDangerousSchemeDetail(String dangerousSchemeDetail) { + this.dangerousSchemeDetail = dangerousSchemeDetail; + } + + public int getDangerousScheme() { + return dangerousScheme; + } + + public void setDangerousScheme(int dangerousScheme) { + this.dangerousScheme = dangerousScheme; + } + + public String getConflictSchemeDetail() { + return conflictSchemeDetail; + } + + public void setConflictSchemeDetail(String conflictSchemeDetail) { + this.conflictSchemeDetail = conflictSchemeDetail; + } + + public int getConflictScheme() { + return conflictScheme; + } + + public void setConflictScheme(int conflictScheme) { + this.conflictScheme = conflictScheme; + } + + public String getGuarderPMISchemeDetail() { + return guarderPMISchemeDetail; + } + + public void setGuarderPMISchemeDetail(String guarderPMISchemeDetail) { + this.guarderPMISchemeDetail = guarderPMISchemeDetail; + } + + public int getGuarderPMIScheme() { + return guarderPMIScheme; + } + + public void setGuarderPMIScheme(int guarderPMIScheme) { + this.guarderPMIScheme = guarderPMIScheme; + } + + public String getSecurityServiceSchemeDetail() { + return securityServiceSchemeDetail; + } + + public void setSecurityServiceSchemeDetail(String securityServiceSchemeDetail) { + this.securityServiceSchemeDetail = securityServiceSchemeDetail; + } + + public int getSecurityServiceScheme() { + return securityServiceScheme; + } + + public void setSecurityServiceScheme(int securityServiceScheme) { + this.securityServiceScheme = securityServiceScheme; + } + + public String getCriminalCaseDetail() { + return criminalCaseDetail; + } + + public void setCriminalCaseDetail(String criminalCaseDetail) { + this.criminalCaseDetail = criminalCaseDetail; + } + + public int getCriminalCase() { + return criminalCase; + } + + public void setCriminalCase(int criminalCase) { + this.criminalCase = criminalCase; + } + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public SchoolColorDetailEntity calcScore(){ + scoreTotal = 1000; + scoreHuman = 200; + scoreDevices = 200; + scoreTech = 300; + scoreDesire = 100; + scoreScheme = 200; + scoreCase = 0; + + int scoreHumanDec = guarderCount +guarderCert +guarderOverAge + peakGuarderArmed+ peakProtectScheme+ peakStaff; + if(scoreHumanDec >= 200){ + scoreHuman = 0; + }else{ + scoreHuman = 200 - scoreHumanDec; + } + + int scoreEquipDec = zoneClosed + equipCount+collision; + if(scoreEquipDec >= 200){ + scoreDevices = 0; + }else{ + scoreDevices = 200 - scoreEquipDec; + } + + int scoreTechDec = ipcCover +alarmSystem +ipcGate +ipcRecord; + if(scoreTechDec >= 300){ + scoreTech = 0; + }else{ + scoreTech = 300 - scoreTechDec; + } + + int scoreDesireDec = lawEducation + conflict; + if(scoreDesireDec >= 100){ + scoreDesire = 0; + }else{ + scoreDesire = 100 - scoreDesireDec; + } + + int scoreSchemeDec = guarderScheme +buildingScheme +fireScheme +dangerousScheme +conflictScheme + guarderPMIScheme + securityServiceScheme; + if(scoreSchemeDec >= 200){ + scoreScheme = 0; + }else{ + scoreScheme = 200 - scoreSchemeDec; + } + scoreCase = 0-criminalCase; + scoreTotal = ( scoreHuman + scoreDevices + scoreTech + scoreDesire + scoreScheme + scoreCase); + return this; + } + + public String getCheckerName() { + return checkerName; + } + + public void setCheckerName(String checkerName) { + this.checkerName = checkerName; + } + + + + public String getSignatureImage() { + return signatureImage; + } + + public void setSignatureImage(String signatureImage) { + this.signatureImage = signatureImage; + } + + public String getSignatureImageSchool() { + return signatureImageSchool; + } + + public void setSignatureImageSchool(String signatureImageSchool) { + this.signatureImageSchool = signatureImageSchool; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorPoliceCheck.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorPoliceCheck.java new file mode 100644 index 0000000..28e99a1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorPoliceCheck.java @@ -0,0 +1,926 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class SchoolColorPoliceCheck extends SQLDataObject { + @JPos(index = 0,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + + @JPos(index = 4,timekey = true,orderkey = true) + private Date timestamp; + + @JPos(index = 5) + private int scoreTotal; + @JPos(index = 6) + private int scoreHuman; + @JPos(index = 7) + private int scoreDevices; + @JPos(index = 8) + private int scoreTech; + @JPos(index = 9) + private int scoreDesire; + @JPos(index = 10) + private int scoreScheme; + @JPos(index = 11) + private int scoreCase; + + @JPos(index = 12) + private String guarderCountDetail; + @JPos(index = 13) + private int guarderCount; + @JPos(index = 14) + private String guarderCertDetail; + @JPos(index = 15) + private int guarderCert; + @JPos(index = 16) + private String guarderOverAgeDetail; + @JPos(index = 17) + private int guarderOverAge; + @JPos(index = 18) + private String peakGuarderArmedDetail; + @JPos(index = 19) + private int peakGuarderArmed; + @JPos(index = 20) + private String peakProtectSchemeDetail; + @JPos(index = 21) + private int peakProtectScheme; + @JPos(index = 22) + private String peakStaffDetail; + @JPos(index = 23) + private int peakStaff; + @JPos(index = 24) + private String zoneClosedDetail; + @JPos(index = 25) + private int zoneClosed; + @JPos(index = 26) + private String equipCountDetail; + @JPos(index = 27) + private int equipCount; + @JPos(index = 28) + private String collisionDetail; + @JPos(index = 29) + private int collision; + @JPos(index = 30) + private String ipcCoverDetail; + @JPos(index = 31) + private int ipcCover; + @JPos(index = 32) + private String alarmSystemDetail; + @JPos(index = 33) + private int alarmSystem; + @JPos(index = 34) + private String ipcGateDetail; + @JPos(index = 35) + private int ipcGate; + @JPos(index = 36) + private String ipcRecordDetail; + @JPos(index = 37) + private int ipcRecord; + @JPos(index = 38) + private String lawEducationDetail; + @JPos(index = 39) + private int lawEducation; + @JPos(index = 40) + private String conflictDetail; + @JPos(index = 41) + private int conflict; + @JPos(index = 42) + private String guarderSchemeDetail; + @JPos(index = 43) + private int guarderScheme; + @JPos(index = 44) + private String buildingSchemeDetail; + @JPos(index = 45) + private int buildingScheme; + @JPos(index = 46) + private String fireSchemeDetail; + @JPos(index = 47) + private int fireScheme; + @JPos(index = 48) + private String dangerousSchemeDetail; + @JPos(index = 49) + private int dangerousScheme; + @JPos(index = 50) + private String conflictSchemeDetail; + @JPos(index = 51) + private int conflictScheme; + @JPos(index = 52) + private String guarderPMISchemeDetail; + @JPos(index = 53) + private int guarderPMIScheme; + @JPos(index = 54) + private String securityServiceSchemeDetail; + @JPos(index = 55) + private int securityServiceScheme; + @JPos(index = 56) + private String criminalCaseDetail; + @JPos(index = 57,threshold = -100) + private int criminalCase; + @JPos(index = 58, filter = true) + private String checkerName; + @JPos(index = 59, filter = true) + private String schoolTime; + + @JPos(index = 60,strlen = 10240) + private String signatureImage; + + @JPos(index = 61,strlen = 10240) + private String signatureImageSchool; + @JPos(index = 62,strlen = 1024) + private String comment; + @JPos(index = 63,primary = true) + private String recordId; + + public String tableName(){ + return "school_color_police_check_table"; + } + + public SchoolColorPoliceCheck(){ + this.station = ""; + this.brigade = ""; + this.detachment = ""; + this.borough = ""; + this.timestamp = new Date(); + this.scoreTotal = 0; + this.scoreHuman = 0; + this.scoreDevices = 0; + this.scoreTech = 0; + this.scoreDesire = 0; + this.scoreScheme = 0; + this.scoreCase = 0; + this.guarderCountDetail = ""; + this.guarderCount = 0; + this.guarderCertDetail = ""; + this.guarderCert = 0; + this.guarderOverAgeDetail = ""; + this.guarderOverAge = 0; + this.peakGuarderArmedDetail = ""; + this.peakGuarderArmed = 0; + this.peakProtectSchemeDetail = ""; + this.peakProtectScheme = 0; + this.peakStaffDetail = ""; + this.peakStaff = 0; + this.zoneClosedDetail = ""; + this.zoneClosed = 0; + this.equipCountDetail = ""; + this.equipCount = 0; + this.collisionDetail = ""; + this.collision = 0; + this.ipcCoverDetail = ""; + this.ipcCover = 0; + this.alarmSystemDetail = ""; + this.alarmSystem = 0; + this.ipcGateDetail = ""; + this.ipcGate = 0; + this.ipcRecordDetail = ""; + this.ipcRecord = 0; + this.lawEducationDetail = ""; + this.lawEducation = 0; + this.conflictDetail = ""; + this.conflict = 0; + this.guarderSchemeDetail = ""; + this.guarderScheme = 0; + this.buildingSchemeDetail = ""; + this.buildingScheme = 0; + this.fireSchemeDetail = ""; + this.fireScheme = 0; + this.dangerousSchemeDetail = ""; + this.dangerousScheme = 0; + this.conflictSchemeDetail = ""; + this.conflictScheme = 0; + this.guarderPMISchemeDetail = ""; + this.guarderPMIScheme = 0; + this.securityServiceSchemeDetail = ""; + this.securityServiceScheme = 0; + this.criminalCaseDetail = ""; + this.criminalCase = 0; + this.checkerName = ""; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreHuman() { + return scoreHuman; + } + + public void setScoreHuman(int scoreHuman) { + this.scoreHuman = scoreHuman; + } + + public int getScoreDevices() { + return scoreDevices; + } + + public void setScoreDevices(int scoreDevices) { + this.scoreDevices = scoreDevices; + } + + public int getScoreTech() { + return scoreTech; + } + + public void setScoreTech(int scoreTech) { + this.scoreTech = scoreTech; + } + + public int getScoreDesire() { + return scoreDesire; + } + + public void setScoreDesire(int scoreDesire) { + this.scoreDesire = scoreDesire; + } + + public int getScoreScheme() { + return scoreScheme; + } + + public void setScoreScheme(int scoreScheme) { + this.scoreScheme = scoreScheme; + } + + public int getScoreCase() { + return scoreCase; + } + + public void setScoreCase(int scoreCase) { + this.scoreCase = scoreCase; + } + + public String getGuarderCountDetail() { + return guarderCountDetail; + } + + public void setGuarderCountDetail(String guarderCountDetail) { + this.guarderCountDetail = guarderCountDetail; + } + + public int getGuarderCount() { + return guarderCount; + } + + public void setGuarderCount(int guarderCount) { + this.guarderCount = guarderCount; + } + + public String getGuarderCertDetail() { + return guarderCertDetail; + } + + public void setGuarderCertDetail(String guarderCertDetail) { + this.guarderCertDetail = guarderCertDetail; + } + + public int getGuarderCert() { + return guarderCert; + } + + public void setGuarderCert(int guarderCert) { + this.guarderCert = guarderCert; + } + + public String getGuarderOverAgeDetail() { + return guarderOverAgeDetail; + } + + public void setGuarderOverAgeDetail(String guarderOverAgeDetail) { + this.guarderOverAgeDetail = guarderOverAgeDetail; + } + + public int getGuarderOverAge() { + return guarderOverAge; + } + + public void setGuarderOverAge(int guarderOverAge) { + this.guarderOverAge = guarderOverAge; + } + + public String getPeakGuarderArmedDetail() { + return peakGuarderArmedDetail; + } + + public void setPeakGuarderArmedDetail(String peakGuarderArmedDetail) { + this.peakGuarderArmedDetail = peakGuarderArmedDetail; + } + + public int getPeakGuarderArmed() { + return peakGuarderArmed; + } + + public void setPeakGuarderArmed(int peakGuarderArmed) { + this.peakGuarderArmed = peakGuarderArmed; + } + + public String getPeakProtectSchemeDetail() { + return peakProtectSchemeDetail; + } + + public void setPeakProtectSchemeDetail(String peakProtectSchemeDetail) { + this.peakProtectSchemeDetail = peakProtectSchemeDetail; + } + + public int getPeakProtectScheme() { + return peakProtectScheme; + } + + public void setPeakProtectScheme(int peakProtectScheme) { + this.peakProtectScheme = peakProtectScheme; + } + + public String getPeakStaffDetail() { + return peakStaffDetail; + } + + public void setPeakStaffDetail(String peakStaffDetail) { + this.peakStaffDetail = peakStaffDetail; + } + + public int getPeakStaff() { + return peakStaff; + } + + public void setPeakStaff(int peakStaff) { + this.peakStaff = peakStaff; + } + + public String getZoneClosedDetail() { + return zoneClosedDetail; + } + + public void setZoneClosedDetail(String zoneClosedDetail) { + this.zoneClosedDetail = zoneClosedDetail; + } + + public int getZoneClosed() { + return zoneClosed; + } + + public void setZoneClosed(int zoneClosed) { + this.zoneClosed = zoneClosed; + } + + public String getEquipCountDetail() { + return equipCountDetail; + } + + public void setEquipCountDetail(String equipCountDetail) { + this.equipCountDetail = equipCountDetail; + } + + public int getEquipCount() { + return equipCount; + } + + public void setEquipCount(int equipCount) { + this.equipCount = equipCount; + } + + public String getCollisionDetail() { + return collisionDetail; + } + + public void setCollisionDetail(String collisionDetail) { + this.collisionDetail = collisionDetail; + } + + public int getCollision() { + return collision; + } + + public void setCollision(int collision) { + this.collision = collision; + } + + public String getIpcCoverDetail() { + return ipcCoverDetail; + } + + public void setIpcCoverDetail(String ipcCoverDetail) { + this.ipcCoverDetail = ipcCoverDetail; + } + + public int getIpcCover() { + return ipcCover; + } + + public void setIpcCover(int ipcCover) { + this.ipcCover = ipcCover; + } + + public String getAlarmSystemDetail() { + return alarmSystemDetail; + } + + public void setAlarmSystemDetail(String alarmSystemDetail) { + this.alarmSystemDetail = alarmSystemDetail; + } + + public int getAlarmSystem() { + return alarmSystem; + } + + public void setAlarmSystem(int alarmSystem) { + this.alarmSystem = alarmSystem; + } + + public String getIpcGateDetail() { + return ipcGateDetail; + } + + public void setIpcGateDetail(String ipcGateDetail) { + this.ipcGateDetail = ipcGateDetail; + } + + public int getIpcGate() { + return ipcGate; + } + + public void setIpcGate(int ipcGate) { + this.ipcGate = ipcGate; + } + + public String getIpcRecordDetail() { + return ipcRecordDetail; + } + + public void setIpcRecordDetail(String ipcRecordDetail) { + this.ipcRecordDetail = ipcRecordDetail; + } + + public int getIpcRecord() { + return ipcRecord; + } + + public void setIpcRecord(int ipcRecord) { + this.ipcRecord = ipcRecord; + } + + public String getLawEducationDetail() { + return lawEducationDetail; + } + + public void setLawEducationDetail(String lawEducationDetail) { + this.lawEducationDetail = lawEducationDetail; + } + + public int getLawEducation() { + return lawEducation; + } + + public void setLawEducation(int lawEducation) { + this.lawEducation = lawEducation; + } + + public String getConflictDetail() { + return conflictDetail; + } + + public void setConflictDetail(String conflictDetail) { + this.conflictDetail = conflictDetail; + } + + public int getConflict() { + return conflict; + } + + public void setConflict(int conflict) { + this.conflict = conflict; + } + + public String getGuarderSchemeDetail() { + return guarderSchemeDetail; + } + + public void setGuarderSchemeDetail(String guarderSchemeDetail) { + this.guarderSchemeDetail = guarderSchemeDetail; + } + + public int getGuarderScheme() { + return guarderScheme; + } + + public void setGuarderScheme(int guarderScheme) { + this.guarderScheme = guarderScheme; + } + + public String getBuildingSchemeDetail() { + return buildingSchemeDetail; + } + + public void setBuildingSchemeDetail(String buildingSchemeDetail) { + this.buildingSchemeDetail = buildingSchemeDetail; + } + + public int getBuildingScheme() { + return buildingScheme; + } + + public void setBuildingScheme(int buildingScheme) { + this.buildingScheme = buildingScheme; + } + + public String getFireSchemeDetail() { + return fireSchemeDetail; + } + + public void setFireSchemeDetail(String fireSchemeDetail) { + this.fireSchemeDetail = fireSchemeDetail; + } + + public int getFireScheme() { + return fireScheme; + } + + public void setFireScheme(int fireScheme) { + this.fireScheme = fireScheme; + } + + public String getDangerousSchemeDetail() { + return dangerousSchemeDetail; + } + + public void setDangerousSchemeDetail(String dangerousSchemeDetail) { + this.dangerousSchemeDetail = dangerousSchemeDetail; + } + + public int getDangerousScheme() { + return dangerousScheme; + } + + public void setDangerousScheme(int dangerousScheme) { + this.dangerousScheme = dangerousScheme; + } + + public String getConflictSchemeDetail() { + return conflictSchemeDetail; + } + + public void setConflictSchemeDetail(String conflictSchemeDetail) { + this.conflictSchemeDetail = conflictSchemeDetail; + } + + public int getConflictScheme() { + return conflictScheme; + } + + public void setConflictScheme(int conflictScheme) { + this.conflictScheme = conflictScheme; + } + + public String getGuarderPMISchemeDetail() { + return guarderPMISchemeDetail; + } + + public void setGuarderPMISchemeDetail(String guarderPMISchemeDetail) { + this.guarderPMISchemeDetail = guarderPMISchemeDetail; + } + + public int getGuarderPMIScheme() { + return guarderPMIScheme; + } + + public void setGuarderPMIScheme(int guarderPMIScheme) { + this.guarderPMIScheme = guarderPMIScheme; + } + + public String getSecurityServiceSchemeDetail() { + return securityServiceSchemeDetail; + } + + public void setSecurityServiceSchemeDetail(String securityServiceSchemeDetail) { + this.securityServiceSchemeDetail = securityServiceSchemeDetail; + } + + public int getSecurityServiceScheme() { + return securityServiceScheme; + } + + public void setSecurityServiceScheme(int securityServiceScheme) { + this.securityServiceScheme = securityServiceScheme; + } + + public String getCriminalCaseDetail() { + return criminalCaseDetail; + } + + public void setCriminalCaseDetail(String criminalCaseDetail) { + this.criminalCaseDetail = criminalCaseDetail; + } + + public int getCriminalCase() { + return criminalCase; + } + + public void setCriminalCase(int criminalCase) { + this.criminalCase = criminalCase; + } + + public SchoolColorPoliceCheck calcScore(){ + scoreTotal = 1000; + scoreHuman = 200; + scoreDevices = 200; + scoreTech = 300; + scoreDesire = 100; + scoreScheme = 200; + scoreCase = 0; + + int scoreHumanDec = guarderCount +guarderCert +guarderOverAge + peakGuarderArmed+ peakProtectScheme+ peakStaff; + if(scoreHumanDec >= 200){ + scoreHuman = 0; + }else{ + scoreHuman = 200 - scoreHumanDec; + } + + int scoreEquipDec = zoneClosed + equipCount+collision; + if(scoreEquipDec >= 200){ + scoreDevices = 0; + }else{ + scoreDevices = 200 - scoreEquipDec; + } + + int scoreTechDec = ipcCover +alarmSystem +ipcGate +ipcRecord; + if(scoreTechDec >= 300){ + scoreTech = 0; + }else{ + scoreTech = 300 - scoreTechDec; + } + + int scoreDesireDec = lawEducation + conflict; + if(scoreDesireDec >= 100){ + scoreDesire = 0; + }else{ + scoreDesire = 100 - scoreDesireDec; + } + + int scoreSchemeDec = guarderScheme +buildingScheme +fireScheme +dangerousScheme +conflictScheme + guarderPMIScheme + securityServiceScheme; + if(scoreSchemeDec >= 200){ + scoreScheme = 0; + }else{ + scoreScheme = 200 - scoreSchemeDec; + } + scoreCase = 0-criminalCase; + scoreTotal = ( scoreHuman + scoreDevices + scoreTech + scoreDesire + scoreScheme + scoreCase); + return this; + } + + public String getCheckerName() { + return checkerName; + } + + public void setCheckerName(String checkerName) { + this.checkerName = checkerName; + } + + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + + public String getSignatureImage() { + return signatureImage; + } + + public void setSignatureImage(String signatureImage) { + this.signatureImage = signatureImage; + } + + public String getSignatureImageSchool() { + return signatureImageSchool; + } + + public void setSignatureImageSchool(String signatureImageSchool) { + this.signatureImageSchool = signatureImageSchool; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + + public List buildPendingItemList(){ + List pendingProcessItemList = new ArrayList<>(); + + if(this.guarderCount > 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardCount"); + tmpItem.setItemValue(this.getGuarderCountDetail()); + pendingProcessItemList.add(tmpItem); + } + + if(this.getGuarderCert() > 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardCert"); + tmpItem.setItemValue(this.getGuarderCertDetail()); + pendingProcessItemList.add(tmpItem); + } + + if(this.getGuarderOverAge() > 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardDress"); + tmpItem.setItemValue(this.getGuarderOverAgeDetail()); + pendingProcessItemList.add(tmpItem); + } + if(this.getPeakGuarderArmed() > 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardDress"); + tmpItem.setItemValue(this.getPeakGuarderArmedDetail()); + pendingProcessItemList.add(tmpItem); + } + + if(peakProtectScheme >0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("entranceManage"); + tmpItem.setItemValue(peakProtectSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + if(peakStaff > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("antiTheftDevice"); + tmpItem.setItemValue(peakStaffDetail); + pendingProcessItemList.add(tmpItem); + } + + if(zoneClosed > 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("pushAlarmSys"); + tmpItem.setItemValue(zoneClosedDetail); + pendingProcessItemList.add(tmpItem); + } + if(equipCount > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("accessControl"); + tmpItem.setItemValue(equipCountDetail); + pendingProcessItemList.add(tmpItem); + } + if(collision > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("invadeAlarmSys"); + tmpItem.setItemValue(collisionDetail); + pendingProcessItemList.add(tmpItem); + } + + if(ipcCover >0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("ipcSys"); + tmpItem.setItemValue(ipcCoverDetail); + pendingProcessItemList.add(tmpItem); + } + if(alarmSystem > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("ipcStorage"); + tmpItem.setItemValue(alarmSystemDetail); + pendingProcessItemList.add(tmpItem); + } + if(ipcGate > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("importantAccessControl"); + tmpItem.setItemValue(ipcGateDetail); + pendingProcessItemList.add(tmpItem); + } + + if(ipcRecord > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("vipCensor"); + tmpItem.setItemValue(ipcRecordDetail); + pendingProcessItemList.add(tmpItem); + } + if(lawEducation > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("conciliation"); + tmpItem.setItemValue(lawEducationDetail); + pendingProcessItemList.add(tmpItem); + } + if(conflict >0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("lawEducate"); + tmpItem.setItemValue(conflictDetail); + pendingProcessItemList.add(tmpItem); + } + if(guarderScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("innerProtectScheme"); + tmpItem.setItemValue(guarderSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + if(buildingScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guarderDutyScheme"); + tmpItem.setItemValue(buildingSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + + if(fireScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("fireScheme"); + tmpItem.setItemValue(fireSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + if(dangerousScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guarderPMIScheme"); + tmpItem.setItemValue(dangerousSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + + if(conflictScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("conflictScheme"); + tmpItem.setItemValue(conflictSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + if(guarderPMIScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guarderPMIScheme"); + tmpItem.setItemValue(guarderPMISchemeDetail); + pendingProcessItemList.add(tmpItem); + } + if(securityServiceScheme > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("securityServiceScheme"); + tmpItem.setItemValue(securityServiceSchemeDetail); + pendingProcessItemList.add(tmpItem); + } + if(criminalCase > 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("criminalCase"); + tmpItem.setItemValue(criminalCaseDetail); + pendingProcessItemList.add(tmpItem); + } + + return pendingProcessItemList; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorRatingCompose.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorRatingCompose.java new file mode 100644 index 0000000..eca5c7a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorRatingCompose.java @@ -0,0 +1,273 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; + +public class SchoolColorRatingCompose { + private int colorGreen; + private int colorYellow; + private int colorRed; + + private int humanBad; + private int humanGood; + private int humanGreat; + private int devicesBad; + private int devicesGood; + private int devicesGreat; + private int techBad; + private int techGood; + private int techGreat; + private int desireBad; + private int desireGood; + private int desireGreat; + + private int schemeBad; + private int schemeGood; + private int schemeGreat; + + private int caseTotal; + + + public int getColorGreen() { + return colorGreen; + } + + public void setColorGreen(int colorGreen) { + this.colorGreen = colorGreen; + } + + public int getColorYellow() { + return colorYellow; + } + + public void setColorYellow(int colorYellow) { + this.colorYellow = colorYellow; + } + + public int getColorRed() { + return colorRed; + } + + public void setColorRed(int colorRed) { + this.colorRed = colorRed; + } + + public int getHumanBad() { + return humanBad; + } + + public void setHumanBad(int humanBad) { + this.humanBad = humanBad; + } + + public int getHumanGood() { + return humanGood; + } + + public void setHumanGood(int humanGood) { + this.humanGood = humanGood; + } + + public int getHumanGreat() { + return humanGreat; + } + + public void setHumanGreat(int humanGreat) { + this.humanGreat = humanGreat; + } + + public int getDevicesBad() { + return devicesBad; + } + + public void setDevicesBad(int devicesBad) { + this.devicesBad = devicesBad; + } + + public int getDevicesGood() { + return devicesGood; + } + + public void setDevicesGood(int devicesGood) { + this.devicesGood = devicesGood; + } + + public int getDevicesGreat() { + return devicesGreat; + } + + public void setDevicesGreat(int devicesGreat) { + this.devicesGreat = devicesGreat; + } + + public int getTechBad() { + return techBad; + } + + public void setTechBad(int techBad) { + this.techBad = techBad; + } + + public int getTechGood() { + return techGood; + } + + public void setTechGood(int techGood) { + this.techGood = techGood; + } + + public int getTechGreat() { + return techGreat; + } + + public void setTechGreat(int techGreat) { + this.techGreat = techGreat; + } + + public int getDesireBad() { + return desireBad; + } + + public void setDesireBad(int desireBad) { + this.desireBad = desireBad; + } + + public int getDesireGood() { + return desireGood; + } + + public void setDesireGood(int desireGood) { + this.desireGood = desireGood; + } + + public int getDesireGreat() { + return desireGreat; + } + + public void setDesireGreat(int desireGreat) { + this.desireGreat = desireGreat; + } + + public int getSchemeBad() { + return schemeBad; + } + + public void setSchemeBad(int schemeBad) { + this.schemeBad = schemeBad; + } + + public int getSchemeGood() { + return schemeGood; + } + + public void setSchemeGood(int schemeGood) { + this.schemeGood = schemeGood; + } + + public int getSchemeGreat() { + return schemeGreat; + } + + public void setSchemeGreat(int schemeGreat) { + this.schemeGreat = schemeGreat; + } + + public int getCaseTotal() { + return caseTotal; + } + + public void setCaseTotal(int caseTotal) { + this.caseTotal = caseTotal; + } + + + + public void addColorGreen(int colorGreen) { + this.colorGreen += colorGreen; + } + + + public void addColorYellow(int colorYellow) { + this.colorYellow += colorYellow; + } + + + public void addColorRed(int colorRed) { + this.colorRed += colorRed; + } + + public void addHumanBad(int humanBad) { + this.humanBad += humanBad; + } + + + public void addHumanGood(int humanGood) { + this.humanGood += humanGood; + } + + + public void addHumanGreat(int humanGreat) { + this.humanGreat += humanGreat; + } + + + public void addDevicesBad(int devicesBad) { + this.devicesBad += devicesBad; + } + + + public void addDevicesGood(int devicesGood) { + this.devicesGood += devicesGood; + } + + + public void addDevicesGreat(int devicesGreat) { + this.devicesGreat += devicesGreat; + } + + + public void addTechBad(int techBad) { + this.techBad += techBad; + } + + + public void addTechGood(int techGood) { + this.techGood += techGood; + } + + + public void addTechGreat(int techGreat) { + this.techGreat += techGreat; + } + + + public void addDesireBad(int desireBad) { + this.desireBad += desireBad; + } + + + public void addDesireGood(int desireGood) { + this.desireGood += desireGood; + } + + + public void addDesireGreat(int desireGreat) { + this.desireGreat += desireGreat; + } + + + public void addSchemeBad(int schemeBad) { + this.schemeBad += schemeBad; + } + + public void addSchemeGood(int schemeGood) { + this.schemeGood += schemeGood; + } + + public void addSchemeGreat(int schemeGreat) { + this.schemeGreat += schemeGreat; + } + + public void addCaseTotal(int caseTotal) { + this.caseTotal += caseTotal; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorRatingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorRatingEntity.java new file mode 100644 index 0000000..a1a86ff --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorRatingEntity.java @@ -0,0 +1,161 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.firestationport.model.statistics.StationDaySummaryEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SchoolColorRatingEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + @JPos(index = 4,timekey = true) + private Date timestamp; + @JPos(index = 5,orderkey = true) + private int scoreTotal; + @JPos(index = 6) + private int scoreHuman; + @JPos(index = 7) + private int scoreDevices; + @JPos(index = 8) + private int scoreTech; + @JPos(index = 9) + private int scoreDesire; + @JPos(index = 10) + private int scoreScheme; + @JPos(index = 11,threshold = -100) + private int scoreCase; + @JPos(index = 12, primary = true, filter = true) + private String schoolTime; + + public String tableName(){ + return "school_color_rating_table"; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreHuman() { + return scoreHuman; + } + + public void setScoreHuman(int scoreHuman) { + this.scoreHuman = scoreHuman; + } + + public int getScoreDevices() { + return scoreDevices; + } + + public void setScoreDevices(int scoreDevices) { + this.scoreDevices = scoreDevices; + } + + public int getScoreTech() { + return scoreTech; + } + + public void setScoreTech(int scoreTech) { + this.scoreTech = scoreTech; + } + + public int getScoreDesire() { + return scoreDesire; + } + + public void setScoreDesire(int scoreDesire) { + this.scoreDesire = scoreDesire; + } + + public int getScoreScheme() { + return scoreScheme; + } + + public void setScoreScheme(int scoreScheme) { + this.scoreScheme = scoreScheme; + } + + public int getScoreCase() { + return scoreCase; + } + + public void setScoreCase(int scoreCase) { + this.scoreCase = scoreCase; + } + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public static List QueryCase(DataSource dataSource, String brigadeName, String schoolTime) { + SchoolColorRatingEntity info = new SchoolColorRatingEntity(); + String sql = "select * from " + info.tableName() + " where brigade='" + brigadeName +"' and schoolTime='"+ schoolTime +"' and scoreCase < 0 order by scoreCase"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SchoolColorRatingEntity.class); + + return list; + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorStationCheck.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorStationCheck.java new file mode 100644 index 0000000..96253b5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolColorStationCheck.java @@ -0,0 +1,727 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolColorStationCheck extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + + @JPos(index = 4,timekey = true) + private Date timestamp; + + @JPos(index = 5,orderkey = true) + private int scoreTotal; + @JPos(index = 6) + private int scoreHuman; + @JPos(index = 7) + private int scoreDevices; + @JPos(index = 8) + private int scoreTech; + @JPos(index = 9) + private int scoreDesire; + @JPos(index = 10) + private int scoreScheme; + @JPos(index = 11) + private int scoreCase; + + @JPos(index = 12) + private String guarderCountDetail; + @JPos(index = 13) + private int guarderCount; + @JPos(index = 14) + private String guarderCertDetail; + @JPos(index = 15) + private int guarderCert; + @JPos(index = 16) + private String guarderOverAgeDetail; + @JPos(index = 17) + private int guarderOverAge; + @JPos(index = 18) + private String peakGuarderArmedDetail; + @JPos(index = 19) + private int peakGuarderArmed; + @JPos(index = 20) + private String peakProtectSchemeDetail; + @JPos(index = 21) + private int peakProtectScheme; + @JPos(index = 22) + private String peakStaffDetail; + @JPos(index = 23) + private int peakStaff; + @JPos(index = 24) + private String zoneClosedDetail; + @JPos(index = 25) + private int zoneClosed; + @JPos(index = 26) + private String equipCountDetail; + @JPos(index = 27) + private int equipCount; + @JPos(index = 28) + private String collisionDetail; + @JPos(index = 29) + private int collision; + @JPos(index = 30) + private String ipcCoverDetail; + @JPos(index = 31) + private int ipcCover; + @JPos(index = 32) + private String alarmSystemDetail; + @JPos(index = 33) + private int alarmSystem; + @JPos(index = 34) + private String ipcGateDetail; + @JPos(index = 35) + private int ipcGate; + @JPos(index = 36) + private String ipcRecordDetail; + @JPos(index = 37) + private int ipcRecord; + @JPos(index = 38) + private String lawEducationDetail; + @JPos(index = 39) + private int lawEducation; + @JPos(index = 40) + private String conflictDetail; + @JPos(index = 41) + private int conflict; + @JPos(index = 42) + private String guarderSchemeDetail; + @JPos(index = 43) + private int guarderScheme; + @JPos(index = 44) + private String buildingSchemeDetail; + @JPos(index = 45) + private int buildingScheme; + @JPos(index = 46) + private String fireSchemeDetail; + @JPos(index = 47) + private int fireScheme; + @JPos(index = 48) + private String dangerousSchemeDetail; + @JPos(index = 49) + private int dangerousScheme; + @JPos(index = 50) + private String conflictSchemeDetail; + @JPos(index = 51) + private int conflictScheme; + @JPos(index = 52) + private String guarderPMISchemeDetail; + @JPos(index = 53) + private int guarderPMIScheme; + @JPos(index = 54) + private String securityServiceSchemeDetail; + @JPos(index = 55) + private int securityServiceScheme; + @JPos(index = 56) + private String criminalCaseDetail; + @JPos(index = 57,threshold = -100) + private int criminalCase; + @JPos(index = 58, filter = true) + private String checkerName; + @JPos(index = 59, primary = true, filter = true) + private String schoolTime; + + public String tableName(){ + return "school_color_station_check_table"; + } + + public SchoolColorStationCheck(){ + this.station = ""; + this.brigade = ""; + this.detachment = ""; + this.borough = ""; + this.timestamp = new Date(); + this.scoreTotal = 0; + this.scoreHuman = 0; + this.scoreDevices = 0; + this.scoreTech = 0; + this.scoreDesire = 0; + this.scoreScheme = 0; + this.scoreCase = 0; + this.guarderCountDetail = ""; + this.guarderCount = 0; + this.guarderCertDetail = ""; + this.guarderCert = 0; + this.guarderOverAgeDetail = ""; + this.guarderOverAge = 0; + this.peakGuarderArmedDetail = ""; + this.peakGuarderArmed = 0; + this.peakProtectSchemeDetail = ""; + this.peakProtectScheme = 0; + this.peakStaffDetail = ""; + this.peakStaff = 0; + this.zoneClosedDetail = ""; + this.zoneClosed = 0; + this.equipCountDetail = ""; + this.equipCount = 0; + this.collisionDetail = ""; + this.collision = 0; + this.ipcCoverDetail = ""; + this.ipcCover = 0; + this.alarmSystemDetail = ""; + this.alarmSystem = 0; + this.ipcGateDetail = ""; + this.ipcGate = 0; + this.ipcRecordDetail = ""; + this.ipcRecord = 0; + this.lawEducationDetail = ""; + this.lawEducation = 0; + this.conflictDetail = ""; + this.conflict = 0; + this.guarderSchemeDetail = ""; + this.guarderScheme = 0; + this.buildingSchemeDetail = ""; + this.buildingScheme = 0; + this.fireSchemeDetail = ""; + this.fireScheme = 0; + this.dangerousSchemeDetail = ""; + this.dangerousScheme = 0; + this.conflictSchemeDetail = ""; + this.conflictScheme = 0; + this.guarderPMISchemeDetail = ""; + this.guarderPMIScheme = 0; + this.securityServiceSchemeDetail = ""; + this.securityServiceScheme = 0; + this.criminalCaseDetail = ""; + this.criminalCase = 0; + this.checkerName = ""; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreHuman() { + return scoreHuman; + } + + public void setScoreHuman(int scoreHuman) { + this.scoreHuman = scoreHuman; + } + + public int getScoreDevices() { + return scoreDevices; + } + + public void setScoreDevices(int scoreDevices) { + this.scoreDevices = scoreDevices; + } + + public int getScoreTech() { + return scoreTech; + } + + public void setScoreTech(int scoreTech) { + this.scoreTech = scoreTech; + } + + public int getScoreDesire() { + return scoreDesire; + } + + public void setScoreDesire(int scoreDesire) { + this.scoreDesire = scoreDesire; + } + + public int getScoreScheme() { + return scoreScheme; + } + + public void setScoreScheme(int scoreScheme) { + this.scoreScheme = scoreScheme; + } + + public int getScoreCase() { + return scoreCase; + } + + public void setScoreCase(int scoreCase) { + this.scoreCase = scoreCase; + } + + public String getGuarderCountDetail() { + return guarderCountDetail; + } + + public void setGuarderCountDetail(String guarderCountDetail) { + this.guarderCountDetail = guarderCountDetail; + } + + public int getGuarderCount() { + return guarderCount; + } + + public void setGuarderCount(int guarderCount) { + this.guarderCount = guarderCount; + } + + public String getGuarderCertDetail() { + return guarderCertDetail; + } + + public void setGuarderCertDetail(String guarderCertDetail) { + this.guarderCertDetail = guarderCertDetail; + } + + public int getGuarderCert() { + return guarderCert; + } + + public void setGuarderCert(int guarderCert) { + this.guarderCert = guarderCert; + } + + public String getGuarderOverAgeDetail() { + return guarderOverAgeDetail; + } + + public void setGuarderOverAgeDetail(String guarderOverAgeDetail) { + this.guarderOverAgeDetail = guarderOverAgeDetail; + } + + public int getGuarderOverAge() { + return guarderOverAge; + } + + public void setGuarderOverAge(int guarderOverAge) { + this.guarderOverAge = guarderOverAge; + } + + public String getPeakGuarderArmedDetail() { + return peakGuarderArmedDetail; + } + + public void setPeakGuarderArmedDetail(String peakGuarderArmedDetail) { + this.peakGuarderArmedDetail = peakGuarderArmedDetail; + } + + public int getPeakGuarderArmed() { + return peakGuarderArmed; + } + + public void setPeakGuarderArmed(int peakGuarderArmed) { + this.peakGuarderArmed = peakGuarderArmed; + } + + public String getPeakProtectSchemeDetail() { + return peakProtectSchemeDetail; + } + + public void setPeakProtectSchemeDetail(String peakProtectSchemeDetail) { + this.peakProtectSchemeDetail = peakProtectSchemeDetail; + } + + public int getPeakProtectScheme() { + return peakProtectScheme; + } + + public void setPeakProtectScheme(int peakProtectScheme) { + this.peakProtectScheme = peakProtectScheme; + } + + public String getPeakStaffDetail() { + return peakStaffDetail; + } + + public void setPeakStaffDetail(String peakStaffDetail) { + this.peakStaffDetail = peakStaffDetail; + } + + public int getPeakStaff() { + return peakStaff; + } + + public void setPeakStaff(int peakStaff) { + this.peakStaff = peakStaff; + } + + public String getZoneClosedDetail() { + return zoneClosedDetail; + } + + public void setZoneClosedDetail(String zoneClosedDetail) { + this.zoneClosedDetail = zoneClosedDetail; + } + + public int getZoneClosed() { + return zoneClosed; + } + + public void setZoneClosed(int zoneClosed) { + this.zoneClosed = zoneClosed; + } + + public String getEquipCountDetail() { + return equipCountDetail; + } + + public void setEquipCountDetail(String equipCountDetail) { + this.equipCountDetail = equipCountDetail; + } + + public int getEquipCount() { + return equipCount; + } + + public void setEquipCount(int equipCount) { + this.equipCount = equipCount; + } + + public String getCollisionDetail() { + return collisionDetail; + } + + public void setCollisionDetail(String collisionDetail) { + this.collisionDetail = collisionDetail; + } + + public int getCollision() { + return collision; + } + + public void setCollision(int collision) { + this.collision = collision; + } + + public String getIpcCoverDetail() { + return ipcCoverDetail; + } + + public void setIpcCoverDetail(String ipcCoverDetail) { + this.ipcCoverDetail = ipcCoverDetail; + } + + public int getIpcCover() { + return ipcCover; + } + + public void setIpcCover(int ipcCover) { + this.ipcCover = ipcCover; + } + + public String getAlarmSystemDetail() { + return alarmSystemDetail; + } + + public void setAlarmSystemDetail(String alarmSystemDetail) { + this.alarmSystemDetail = alarmSystemDetail; + } + + public int getAlarmSystem() { + return alarmSystem; + } + + public void setAlarmSystem(int alarmSystem) { + this.alarmSystem = alarmSystem; + } + + public String getIpcGateDetail() { + return ipcGateDetail; + } + + public void setIpcGateDetail(String ipcGateDetail) { + this.ipcGateDetail = ipcGateDetail; + } + + public int getIpcGate() { + return ipcGate; + } + + public void setIpcGate(int ipcGate) { + this.ipcGate = ipcGate; + } + + public String getIpcRecordDetail() { + return ipcRecordDetail; + } + + public void setIpcRecordDetail(String ipcRecordDetail) { + this.ipcRecordDetail = ipcRecordDetail; + } + + public int getIpcRecord() { + return ipcRecord; + } + + public void setIpcRecord(int ipcRecord) { + this.ipcRecord = ipcRecord; + } + + public String getLawEducationDetail() { + return lawEducationDetail; + } + + public void setLawEducationDetail(String lawEducationDetail) { + this.lawEducationDetail = lawEducationDetail; + } + + public int getLawEducation() { + return lawEducation; + } + + public void setLawEducation(int lawEducation) { + this.lawEducation = lawEducation; + } + + public String getConflictDetail() { + return conflictDetail; + } + + public void setConflictDetail(String conflictDetail) { + this.conflictDetail = conflictDetail; + } + + public int getConflict() { + return conflict; + } + + public void setConflict(int conflict) { + this.conflict = conflict; + } + + public String getGuarderSchemeDetail() { + return guarderSchemeDetail; + } + + public void setGuarderSchemeDetail(String guarderSchemeDetail) { + this.guarderSchemeDetail = guarderSchemeDetail; + } + + public int getGuarderScheme() { + return guarderScheme; + } + + public void setGuarderScheme(int guarderScheme) { + this.guarderScheme = guarderScheme; + } + + public String getBuildingSchemeDetail() { + return buildingSchemeDetail; + } + + public void setBuildingSchemeDetail(String buildingSchemeDetail) { + this.buildingSchemeDetail = buildingSchemeDetail; + } + + public int getBuildingScheme() { + return buildingScheme; + } + + public void setBuildingScheme(int buildingScheme) { + this.buildingScheme = buildingScheme; + } + + public String getFireSchemeDetail() { + return fireSchemeDetail; + } + + public void setFireSchemeDetail(String fireSchemeDetail) { + this.fireSchemeDetail = fireSchemeDetail; + } + + public int getFireScheme() { + return fireScheme; + } + + public void setFireScheme(int fireScheme) { + this.fireScheme = fireScheme; + } + + public String getDangerousSchemeDetail() { + return dangerousSchemeDetail; + } + + public void setDangerousSchemeDetail(String dangerousSchemeDetail) { + this.dangerousSchemeDetail = dangerousSchemeDetail; + } + + public int getDangerousScheme() { + return dangerousScheme; + } + + public void setDangerousScheme(int dangerousScheme) { + this.dangerousScheme = dangerousScheme; + } + + public String getConflictSchemeDetail() { + return conflictSchemeDetail; + } + + public void setConflictSchemeDetail(String conflictSchemeDetail) { + this.conflictSchemeDetail = conflictSchemeDetail; + } + + public int getConflictScheme() { + return conflictScheme; + } + + public void setConflictScheme(int conflictScheme) { + this.conflictScheme = conflictScheme; + } + + public String getGuarderPMISchemeDetail() { + return guarderPMISchemeDetail; + } + + public void setGuarderPMISchemeDetail(String guarderPMISchemeDetail) { + this.guarderPMISchemeDetail = guarderPMISchemeDetail; + } + + public int getGuarderPMIScheme() { + return guarderPMIScheme; + } + + public void setGuarderPMIScheme(int guarderPMIScheme) { + this.guarderPMIScheme = guarderPMIScheme; + } + + public String getSecurityServiceSchemeDetail() { + return securityServiceSchemeDetail; + } + + public void setSecurityServiceSchemeDetail(String securityServiceSchemeDetail) { + this.securityServiceSchemeDetail = securityServiceSchemeDetail; + } + + public int getSecurityServiceScheme() { + return securityServiceScheme; + } + + public void setSecurityServiceScheme(int securityServiceScheme) { + this.securityServiceScheme = securityServiceScheme; + } + + public String getCriminalCaseDetail() { + return criminalCaseDetail; + } + + public void setCriminalCaseDetail(String criminalCaseDetail) { + this.criminalCaseDetail = criminalCaseDetail; + } + + public int getCriminalCase() { + return criminalCase; + } + + public void setCriminalCase(int criminalCase) { + this.criminalCase = criminalCase; + } + + public SchoolColorStationCheck calcScore(){ + scoreTotal = 1000; + scoreHuman = 200; + scoreDevices = 200; + scoreTech = 300; + scoreDesire = 100; + scoreScheme = 200; + scoreCase = 0; + + int scoreHumanDec = guarderCount +guarderCert +guarderOverAge + peakGuarderArmed+ peakProtectScheme+ peakStaff; + if(scoreHumanDec >= 200){ + scoreHuman = 0; + }else{ + scoreHuman = 200 - scoreHumanDec; + } + + int scoreEquipDec = zoneClosed + equipCount+collision; + if(scoreEquipDec >= 200){ + scoreDevices = 0; + }else{ + scoreDevices = 200 - scoreEquipDec; + } + + int scoreTechDec = ipcCover +alarmSystem +ipcGate +ipcRecord; + if(scoreTechDec >= 300){ + scoreTech = 0; + }else{ + scoreTech = 300 - scoreTechDec; + } + + int scoreDesireDec = lawEducation + conflict; + if(scoreDesireDec >= 100){ + scoreDesire = 0; + }else{ + scoreDesire = 100 - scoreDesireDec; + } + + int scoreSchemeDec = guarderScheme +buildingScheme +fireScheme +dangerousScheme +conflictScheme + guarderPMIScheme + securityServiceScheme; + if(scoreSchemeDec >= 200){ + scoreScheme = 0; + }else{ + scoreScheme = 200 - scoreSchemeDec; + } + scoreCase = 0-criminalCase; + scoreTotal = ( scoreHuman + scoreDevices + scoreTech + scoreDesire + scoreScheme + scoreCase); + return this; + } + + public String getCheckerName() { + return checkerName; + } + + public void setCheckerName(String checkerName) { + this.checkerName = checkerName; + } + + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolCommonFileEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolCommonFileEntity.java new file mode 100644 index 0000000..6fe7c06 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolCommonFileEntity.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; +@Data +public class SchoolCommonFileEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String fileId; + @JPos(index = 1,filter = true) + private String creator; + @JPos(index = 2,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 3,filter = true) + private String type; + @JPos(index = 4, strlen = 1024) + private String comment; + @JPos(index = 5, strlen = 1024) + private String images; + @JPos(index = 6, strlen = 2048) + private String imageUrls; + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String station; + @JPos(index = 11,filter = true) + private String deviceId; + + private String post; + + public String tableName() { + return "school_common_files_table"; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolNewsEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolNewsEntity.java new file mode 100644 index 0000000..b9b0e4d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolNewsEntity.java @@ -0,0 +1,201 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolNewsEntity extends SQLDataObject { + + public static final String STATE_OPEN= "open"; + public static final String STATE_HIDE = "hide"; + public static final String TYPE_PeakGuard = "护学岗"; + public static final String TYPE_Law = "法制宣讲"; + public static final String TYPE_Exercise = "应急演练"; + public static final String TYPE_OTHER = "其他"; + + + @JPos(index = 0,primary = true,filter = true) + private String newsId; + @JPos(index = 1,filter = true) + private String creator; + @JPos(index = 2,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 3,filter = true) + private String title; + @JPos(index = 4, strlen = 1024) + private String comment; + @JPos(index = 5, strlen = 1024) + private String images; + @JPos(index = 6, strlen = 2048) + private String imageUrls; + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String station; + @JPos(index = 11,filter = true) + private String type; + @JPos(index = 12) + private int remarkCount; + @JPos(index = 13) + private int praiseCount; + @JPos(index = 14,filter = true) + private String status; + @JPos(index = 15) + private String checker; + @JPos(index = 16,filter = true) + private String creatorId; + + private String post; + + public String tableName() { + return "school_news_report_table"; + } + public String getNewsId() { + return newsId; + } + + public void setNewsId(String newsId) { + this.newsId = newsId; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getImages() { + return images; + } + + public void setImages(String images) { + this.images = images; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getImageUrls() { + return imageUrls; + } + + public void setImageUrls(String imageUrls) { + this.imageUrls = imageUrls; + } + + public String getPost() { + return post; + } + + public void setPost(String post) { + this.post = post; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public int getRemarkCount() { + return remarkCount; + } + + public void setRemarkCount(int remarkCount) { + this.remarkCount = remarkCount; + } + + public int getPraiseCount() { + return praiseCount; + } + + public void setPraiseCount(int praiseCount) { + this.praiseCount = praiseCount; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getChecker() { + return checker; + } + + public void setChecker(String checker) { + this.checker = checker; + } + + public String getCreatorId() { + return creatorId; + } + + public void setCreatorId(String creatorId) { + this.creatorId = creatorId; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolPendingItem.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolPendingItem.java new file mode 100644 index 0000000..cfd69eb --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolPendingItem.java @@ -0,0 +1,140 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolPendingItem extends SQLDataObject { + + public static final String STATE_PENDING = "pending"; + public static final String STATE_REVISE = "revise"; + public static final String STATE_CLOSE = "close"; + + @JPos(index = 0,primary = true,filter = true) + private String id; + @JPos(index = 1,filter = true) + private String creator; + @JPos(index = 2,strlen = 1024) + private String problemDesc; + @JPos(index = 3,strlen = 1024) + private String reviseDesc; + @JPos(index = 4,filter = true) + private String state; + @JPos(index = 5,strlen = 5120) + private String problemImages; + @JPos(index = 6,timekey = true, orderkey = true) + private Date timestamp; + @JPos(index = 7,filter = true) + private String station; + @JPos(index = 8,filter = true) + private String brigade; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index = 11,strlen = 10240) + private String signatureImage; + + public String tableName(){ + return "school_pending_revise_table"; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getProblemDesc() { + return problemDesc; + } + + public void setProblemDesc(String problemDesc) { + this.problemDesc = problemDesc; + } + + public String getReviseDesc() { + return reviseDesc; + } + + public void setReviseDesc(String reviseDesc) { + this.reviseDesc = reviseDesc; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getProblemImages() { + return problemImages; + } + + public void setProblemImages(String problemImages) { + this.problemImages = problemImages; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getSignatureImage() { + return signatureImage; + } + + public void setSignatureImage(String signatureImage) { + this.signatureImage = signatureImage; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolPendingProcessRecordEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolPendingProcessRecordEntity.java new file mode 100644 index 0000000..40c4f6b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolPendingProcessRecordEntity.java @@ -0,0 +1,161 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolPendingProcessRecordEntity extends SQLDataObject { + + public static final String OP_CREATE = "create"; + public static final String OP_UPDATE = "update"; + public static final String OP_DELETE = "delete"; + public static final String OP_REVISE = "revise"; + public static final String OP_REJECT = "reject"; + public static final String OP_CLOSE = "close"; + + @JPos(index = 0,primary = true,filter = true) + private String recordId; + @JPos(index = 1,filter = true) + private String itemId; + @JPos(index = 2) + private String eventType; + @JPos(index = 3) + private String userAccount; + @JPos(index = 4) + private String userName; + @JPos(index = 5) + private String userType; + @JPos(index = 6,strlen = 10240) + private String userSignature; + @JPos(index = 7) + private String processDesc; + @JPos(index = 8) + private String processUrls; + @JPos(index = 9,timekey = true, orderkey = true) + private Date timestamp; + @JPos(index = 10,filter = true) + private String station; + @JPos(index = 11,filter = true) + private String brigade; + @JPos(index = 12,filter = true) + private String detachment; + @JPos(index = 13,filter = true) + private String borough; + + public String tableName(){ + return "school_pending_operate_table"; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public String getUserAccount() { + return userAccount; + } + + public void setUserAccount(String userAccount) { + this.userAccount = userAccount; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + public String getUserSignature() { + return userSignature; + } + + public void setUserSignature(String userSignature) { + this.userSignature = userSignature; + } + + public String getProcessDesc() { + return processDesc; + } + + public void setProcessDesc(String processDesc) { + this.processDesc = processDesc; + } + + public String getProcessUrls() { + return processUrls; + } + + public void setProcessUrls(String processUrls) { + this.processUrls = processUrls; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolRatingSummary.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolRatingSummary.java new file mode 100644 index 0000000..a47cdf7 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolRatingSummary.java @@ -0,0 +1,153 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; + +public class SchoolRatingSummary { + + public static final int School_Star_Level_1 = 950; + public static final int School_Star_Level_2 = 850; + public static final int School_Star_Level_3 = 750; + public static final int School_Star_Level_4 = 650; + + + private String station; + private String brigade; + private String detachment; + private String borough; + + private String stationNickname; + + private String ratingDescriptionStation; + private String ratingBonusStation; + private String ratingCasesStation; + private int scoreTotalStation; + private int levelStation; + + private String ratingDescriptionBrigade; + private String ratingBonusBrigade; + private String ratingCasesBrigade; + private int scoreTotalBrigade; + private int levelBrigade; + + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getStationNickname() { + return stationNickname; + } + + public void setStationNickname(String stationNickname) { + this.stationNickname = stationNickname; + } + + public String getRatingDescriptionStation() { + return ratingDescriptionStation; + } + + public void setRatingDescriptionStation(String ratingDescriptionStation) { + this.ratingDescriptionStation = ratingDescriptionStation; + } + + public String getRatingBonusStation() { + return ratingBonusStation; + } + + public void setRatingBonusStation(String ratingBonusStation) { + this.ratingBonusStation = ratingBonusStation; + } + + public String getRatingCasesStation() { + return ratingCasesStation; + } + + public void setRatingCasesStation(String ratingCasesStation) { + this.ratingCasesStation = ratingCasesStation; + } + + public int getScoreTotalStation() { + return scoreTotalStation; + } + + public void setScoreTotalStation(int scoreTotalStation) { + this.scoreTotalStation = scoreTotalStation; + } + + public int getLevelStation() { + return levelStation; + } + + public void setLevelStation(int levelStation) { + this.levelStation = levelStation; + } + + public String getRatingDescriptionBrigade() { + return ratingDescriptionBrigade; + } + + public void setRatingDescriptionBrigade(String ratingDescriptionBrigade) { + this.ratingDescriptionBrigade = ratingDescriptionBrigade; + } + + public String getRatingBonusBrigade() { + return ratingBonusBrigade; + } + + public void setRatingBonusBrigade(String ratingBonusBrigade) { + this.ratingBonusBrigade = ratingBonusBrigade; + } + + public String getRatingCasesBrigade() { + return ratingCasesBrigade; + } + + public void setRatingCasesBrigade(String ratingCasesBrigade) { + this.ratingCasesBrigade = ratingCasesBrigade; + } + + public int getScoreTotalBrigade() { + return scoreTotalBrigade; + } + + public void setScoreTotalBrigade(int scoreTotalBrigade) { + this.scoreTotalBrigade = scoreTotalBrigade; + } + + public int getLevelBrigade() { + return levelBrigade; + } + + public void setLevelBrigade(int levelBrigade) { + this.levelBrigade = levelBrigade; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolSecurityCheckEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolSecurityCheckEntity.java new file mode 100644 index 0000000..eeb41d5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolSecurityCheckEntity.java @@ -0,0 +1,495 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class SchoolSecurityCheckEntity extends SQLDataObject { + + @JPos(index = 0,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + + @JPos(index = 4,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 5) + private String checkerName; + + @JPos(index = 6) + private int guardCert;/*保安持证上岗 0无,1有*/ + @JPos(index = 7) + private int guardDress;/*保安着装 0无,1有*/ + @JPos(index = 8) + private int guardCount;/*保安配备是否达标 0无,1有*/ + @JPos(index = 9) + private int guardImportant;/*重点部位值守 */ + + @JPos(index = 10) + private int entranceManage;/* 门禁管理制度,0无,1有*/ + @JPos(index = 11) + private int antiTheftDevice;/* 防盗设施,0无,1有*/ + + @JPos(index = 12) + private int pushAlarmSys; /*一键报警设施,0无,1*/ + @JPos(index = 13) + private int accessControl;/*主要出入口安装门禁访客系统,0无,1*/ + @JPos(index = 14) + private int invadeAlarmSys;/*安装防入侵报警设施并联网,0无,1*/ + @JPos(index = 15) + private int ipcSys;/*建立视频监控系统并联网,0无,1*/ + @JPos(index = 16) + private int ipcStorage;/*视频监控图像清晰,存储时间至少30天,0无,1*/ + @JPos(index = 17) + private int importantAccessControl; /*要害部位有出入控制系统,进出有特别授权,0无,1有未联网,2已联网*/ + + @JPos(index = 18) + private int vipCensor; /* 进行重点人员审查,0否,1是*/ + @JPos(index = 19) + private int conciliation;/*矛盾纠纷调解,0无,1有*/ + @JPos(index = 20) + private int lawEducate;/*开展法制教育培训,0无,1至少1次*/ + + @JPos(index = 21) + private int innerProtectScheme;/* 内部保卫工作的检查考核奖惩制度,0无,1有*/ + @JPos(index = 22) + private int guarderDutyScheme;/* 落实内部治安保卫制度,0无,1有*/ + @JPos(index = 23) + private int fireScheme;/* 制定应急处突反恐防火防盗制度,0无,1有*/ + @JPos(index = 24) + private int guarderPMIScheme;/* 保安员管理考核制度,0无,1有*/ + @JPos(index = 25) + private int generalCase;/* 是否同比上年度持平或低于发生的刑事案件*/ + @JPos(index = 26) + private int seriousCase;/* 是否未发生重特大刑事案件*/ + + @JPos(index = 27,primary = true,filter = true) + private String recordId; + @JPos(index = 28,strlen = 1024) + private String signatureImage; + @JPos(index = 29,strlen = 1024) + private String signatureImageSchool; + @JPos(index = 30,strlen = 1024) + private String comment; + + private int autoCreatePendingItem; + + public String tableName(){ + return "school_security_check_table"; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getCheckerName() { + return checkerName; + } + + public void setCheckerName(String checkerName) { + this.checkerName = checkerName; + } + + public int getGuardCount() { + return guardCount; + } + + public void setGuardCount(int guardCount) { + this.guardCount = guardCount; + } + + public int getGuardCert() { + return guardCert; + } + + public void setGuardCert(int guardCert) { + this.guardCert = guardCert; + } + + + public int getGuardDress() { + return guardDress; + } + + public void setGuardDress(int guardDress) { + this.guardDress = guardDress; + } + + + public int getPushAlarmSys() { + return pushAlarmSys; + } + + public void setPushAlarmSys(int pushAlarmSys) { + this.pushAlarmSys = pushAlarmSys; + } + + public int getAccessControl() { + return accessControl; + } + + public void setAccessControl(int accessControl) { + this.accessControl = accessControl; + } + + public int getInvadeAlarmSys() { + return invadeAlarmSys; + } + + public void setInvadeAlarmSys(int invadeAlarmSys) { + this.invadeAlarmSys = invadeAlarmSys; + } + + public int getIpcSys() { + return ipcSys; + } + + public void setIpcSys(int ipcSys) { + this.ipcSys = ipcSys; + } + + + public int getIpcStorage() { + return ipcStorage; + } + + public void setIpcStorage(int ipcStorage) { + this.ipcStorage = ipcStorage; + } + + public int getImportantAccessControl() { + return importantAccessControl; + } + + public void setImportantAccessControl(int importantAccessControl) { + this.importantAccessControl = importantAccessControl; + } + + + public int getLawEducate() { + return lawEducate; + } + + public void setLawEducate(int lawEducate) { + this.lawEducate = lawEducate; + } + + public int getConciliation() { + return conciliation; + } + + public void setConciliation(int conciliation) { + this.conciliation = conciliation; + } + + public int getVipCensor() { + return vipCensor; + } + + public void setVipCensor(int vipCensor) { + this.vipCensor = vipCensor; + } + + + public int getEntranceManage() { + return entranceManage; + } + + public void setEntranceManage(int entranceManage) { + this.entranceManage = entranceManage; + } + + public int getAntiTheftDevice() { + return antiTheftDevice; + } + + public void setAntiTheftDevice(int antiTheftDevice) { + this.antiTheftDevice = antiTheftDevice; + } + + public int getGuarderDutyScheme() { + return guarderDutyScheme; + } + + public void setGuarderDutyScheme(int guarderDutyScheme) { + this.guarderDutyScheme = guarderDutyScheme; + } + + public int getFireScheme() { + return fireScheme; + } + + public void setFireScheme(int fireScheme) { + this.fireScheme = fireScheme; + } + + public int getInnerProtectScheme() { + return innerProtectScheme; + } + + public void setInnerProtectScheme(int innerProtectScheme) { + this.innerProtectScheme = innerProtectScheme; + } + + public int getGuarderPMIScheme() { + return guarderPMIScheme; + } + + public void setGuarderPMIScheme(int guarderPMIScheme) { + this.guarderPMIScheme = guarderPMIScheme; + } + + + public int getGeneralCase() { + return generalCase; + } + + public void setGeneralCase(int generalCase) { + this.generalCase = generalCase; + } + + public int getSeriousCase() { + return seriousCase; + } + + public void setSeriousCase(int seriousCase) { + this.seriousCase = seriousCase; + } + + public List buildPendingItemList(){ + List pendingProcessItemList = new ArrayList<>(); + + if(guardCount == 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardCount"); + tmpItem.setStation(station); + tmpItem.setItemValue("保卫人员配备数量未达标"); + pendingProcessItemList.add(tmpItem); + } + + if(guardCert == 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardCert"); + tmpItem.setStation(station); + tmpItem.setItemValue("保安员未持证上岗"); + pendingProcessItemList.add(tmpItem); + } + + if(guardDress == 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardDress"); + tmpItem.setStation(station); + tmpItem.setItemValue("保安执勤时未规范着装"); + pendingProcessItemList.add(tmpItem); + } + if(guardImportant == 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guardDress"); + tmpItem.setStation(station); + tmpItem.setItemValue("重点要害部位值守力量未到位"); + pendingProcessItemList.add(tmpItem); + } + + if(entranceManage == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("entranceManage"); + tmpItem.setStation(station); + tmpItem.setItemValue("未实行车辆出入管理"); + pendingProcessItemList.add(tmpItem); + } + if(antiTheftDevice == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("antiTheftDevice"); + tmpItem.setStation(station); + tmpItem.setItemValue("重点要害部位出入口未安装防盗门防盗窗"); + pendingProcessItemList.add(tmpItem); + } + + if(pushAlarmSys == 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("pushAlarmSys"); + tmpItem.setStation(station); + tmpItem.setItemValue("重点区域未安装报警设施"); + pendingProcessItemList.add(tmpItem); + } + if(accessControl == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("accessControl"); + tmpItem.setStation(station); + tmpItem.setItemValue("主要出入口未安装门禁系统、访客系统"); + pendingProcessItemList.add(tmpItem); + } + if(invadeAlarmSys == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("invadeAlarmSys"); + tmpItem.setStation(station); + tmpItem.setItemValue("重点要害部分未安装防入侵报警设施,或设施未联网在线"); + pendingProcessItemList.add(tmpItem); + } + + if(ipcSys == 0){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("ipcSys"); + tmpItem.setStation(station); + tmpItem.setItemValue("未建立视频监控系统,或不健全"); + pendingProcessItemList.add(tmpItem); + } + if(ipcStorage == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("ipcStorage"); + tmpItem.setStation(station); + tmpItem.setItemValue("视频监控系统图像不清晰,或存储时间未达30天"); + pendingProcessItemList.add(tmpItem); + } + if(importantAccessControl == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("importantAccessControl"); + tmpItem.setStation(station); + tmpItem.setItemValue("要害部位无出入控制系统"); + pendingProcessItemList.add(tmpItem); + } + + if(vipCensor == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("vipCensor"); + tmpItem.setStation(station); + tmpItem.setItemValue("未进行重点人员排查"); + pendingProcessItemList.add(tmpItem); + } + if(conciliation == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("conciliation"); + tmpItem.setStation(station); + tmpItem.setItemValue("未建立矛盾纠纷排查调解制度"); + pendingProcessItemList.add(tmpItem); + } + if(lawEducate == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("lawEducate"); + tmpItem.setStation(station); + tmpItem.setItemValue("未进行法治教育培训"); + pendingProcessItemList.add(tmpItem); + } + if(innerProtectScheme == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("innerProtectScheme"); + tmpItem.setStation(station); + tmpItem.setItemValue("无内部保卫工作的检查考核奖惩制度"); + pendingProcessItemList.add(tmpItem); + } + if(guarderDutyScheme == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guarderDutyScheme"); + tmpItem.setStation(station); + tmpItem.setItemValue("未落实内部治安保卫制度"); + pendingProcessItemList.add(tmpItem); + } + + if(fireScheme == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("fireScheme"); + tmpItem.setStation(station); + tmpItem.setItemValue("未制定应急处突、反恐、防火、防盗制度"); + pendingProcessItemList.add(tmpItem); + } + if(guarderPMIScheme == 0 ){ + PendingProcessItem tmpItem = new PendingProcessItem(); + tmpItem.setItemCode("guarderPMIScheme"); + tmpItem.setStation(station); + tmpItem.setItemValue("未建立保安员管理考核制度"); + pendingProcessItemList.add(tmpItem); + } + return pendingProcessItemList; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public int getGuardImportant() { + return guardImportant; + } + + public void setGuardImportant(int guardImportant) { + this.guardImportant = guardImportant; + } + + public String getSignatureImage() { + return signatureImage; + } + + public void setSignatureImage(String signatureImage) { + this.signatureImage = signatureImage; + } + + public String getSignatureImageSchool() { + return signatureImageSchool; + } + + public void setSignatureImageSchool(String signatureImageSchool) { + this.signatureImageSchool = signatureImageSchool; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public int getAutoCreatePendingItem() { + return autoCreatePendingItem; + } + + public void setAutoCreatePendingItem(int autoCreatePendingItem) { + this.autoCreatePendingItem = autoCreatePendingItem; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarDetailEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarDetailEntity.java new file mode 100644 index 0000000..f8d0b13 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarDetailEntity.java @@ -0,0 +1,756 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolStarDetailEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + @JPos(index = 4,timekey = true) + private Date timestamp; + @JPos(index = 5,threshold = -1,orderkey = true) + private int scoreTotal; + @JPos(index = 6,threshold = -1) + private int scoreInsideManage; + @JPos(index = 7,threshold = -1) + private int scoreOutsideManage; + @JPos(index = 8,threshold = -1) + private int scoreRiskManage; + @JPos(index = 9,threshold = -1) + private int scoreLawEducation; + @JPos(index = 10,threshold = -1) + private int scoreEmcManage; + @JPos(index = 11,threshold = -1) + private int scoreBonus; + @JPos(index = 12, filter = true) + private String checkerName; + @JPos(index = 13) + private String inResponsibilityDetail; + @JPos(index = 14,threshold = -1) + private int inResponsibility; + @JPos(index = 15) + private String inTeamBuildDetail; + @JPos(index = 16,threshold = -1) + private int inTeamBuild; + @JPos(index = 17) + private String inDevicesSetupDetail; + @JPos(index = 18,threshold = -1) + private int inDevicesSetup; + @JPos(index = 19) + private String inFireManageDetail; + @JPos(index = 20,threshold = -1) + private int inFireManage; + @JPos(index = 21) + private String inDangerousManageDetail; + @JPos(index = 22,threshold = -1) + private int inDangerousManage; + @JPos(index = 23) + private String inSmartSecurityDetail; + @JPos(index = 24,threshold = -1) + private int inSmartSecurity; + @JPos(index = 25) + private String inSecuritySchemeDetail; + @JPos(index = 26,threshold = -1) + private int inSecurityScheme; + @JPos(index = 27) + private String outPeakGuardDetail; + @JPos(index = 28,threshold = -1) + private int outPeakGuard; + @JPos(index = 29) + private String outRiskPreventDetail; + @JPos(index = 30,threshold = -1) + private int outRiskPrevent; + @JPos(index = 31) + private String outTrafficDetail; + @JPos(index = 32,threshold = -1) + private int outTraffic; + @JPos(index = 33) + private String outCaseManageDetail; + @JPos(index = 34,threshold = -1) + private int outCaseManage; + @JPos(index = 35) + private String riskDangerManageDetail; + @JPos(index = 36,threshold = -1) + private int riskDangerManage; + @JPos(index = 37) + private String riskConflictManageDetail; + @JPos(index = 38,threshold = -1) + private int riskConflictManage; + @JPos(index = 39) + private String riskProcessDetail; + @JPos(index = 40,threshold = -1) + private int riskProcess; + @JPos(index = 41) + private String lawEducationDetail; + @JPos(index = 42,threshold = -1) + private int lawEducation; + @JPos(index = 43) + private String lawFirstClassDetail; + @JPos(index = 44,threshold = -1) + private int lawFirstClass; + @JPos(index = 45) + private String emcPlanDetail; + @JPos(index = 46,threshold = -1) + private int emcPlan; + @JPos(index = 47) + private String emcDrillDetail; + @JPos(index = 48,threshold = -1) + private int emcDrill; + @JPos(index = 49) + private String bonus1Detail; + @JPos(index = 50,threshold = -1) + private int bonus1; + @JPos(index = 51) + private String bonus2Detail; + @JPos(index = 52,threshold = -1) + private int bonus2; + @JPos(index = 53) + private String bonus3Detail; + @JPos(index = 54,threshold = -1) + private int bonus3; + @JPos(index = 55) + private String bonus4Detail; + @JPos(index = 56,threshold = -1) + private int bonus4; + @JPos(index = 57) + private String bonus5Detail; + @JPos(index = 58,threshold = -1) + private int bonus5; + @JPos(index = 59, primary = true, filter = true) + private String schoolTime; + @JPos(index = 60,strlen = 10240) + private String signatureImage; + @JPos(index = 61,strlen = 10240) + private String signatureImageSchool; + @JPos(index = 62,strlen = 1024) + private String comment; + + public String tableName(){ + return "school_star_detail_table"; + } + + public SchoolStarDetailEntity(){ + station = ""; + brigade = ""; + detachment = ""; + borough = ""; + timestamp = new Date(); + scoreTotal = 0; + scoreInsideManage= 0; + scoreOutsideManage= 0; + scoreRiskManage= 0; + scoreLawEducation= 0; + scoreEmcManage= 0; + scoreBonus= 0; + checkerName = ""; + inResponsibilityDetail = ""; + inResponsibility = 0; + inTeamBuildDetail = ""; + inTeamBuild = 0; + inDevicesSetupDetail = ""; + inDevicesSetup = 0; + inFireManageDetail = ""; + inFireManage = 0; + inDangerousManageDetail = ""; + inDangerousManage = 0; + inSmartSecurityDetail = ""; + inSmartSecurity = 0; + inSecuritySchemeDetail = ""; + inSecurityScheme = 0; + outPeakGuardDetail = ""; + outPeakGuard = 0; + outRiskPreventDetail = ""; + outRiskPrevent = 0; + outTrafficDetail = ""; + outTraffic = 0; + outCaseManageDetail = ""; + outCaseManage = 0; + riskDangerManageDetail = ""; + riskDangerManage = 0; + riskConflictManageDetail = ""; + riskConflictManage = 0; + riskProcessDetail = ""; + riskProcess = 0; + lawEducationDetail = ""; + lawEducation = 0; + lawFirstClassDetail = ""; + lawFirstClass = 0; + emcPlanDetail = ""; + emcPlan = 0; + emcDrillDetail = ""; + emcDrill = 0; + bonus1Detail = ""; + bonus1 = 0; + bonus2Detail = ""; + bonus2 = 0; + bonus3Detail = ""; + bonus3 = 0; + bonus4Detail = ""; + bonus4 = 0; + bonus5Detail = ""; + bonus5 = 0; + signatureImage = ""; + signatureImageSchool = ""; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreInsideManage() { + return scoreInsideManage; + } + + public void setScoreInsideManage(int scoreInsideManage) { + this.scoreInsideManage = scoreInsideManage; + } + + public int getScoreOutsideManage() { + return scoreOutsideManage; + } + + public void setScoreOutsideManage(int scoreOutsideManage) { + this.scoreOutsideManage = scoreOutsideManage; + } + + public int getScoreRiskManage() { + return scoreRiskManage; + } + + public void setScoreRiskManage(int scoreRiskManage) { + this.scoreRiskManage = scoreRiskManage; + } + + public int getScoreLawEducation() { + return scoreLawEducation; + } + + public void setScoreLawEducation(int scoreLawEducation) { + this.scoreLawEducation = scoreLawEducation; + } + + public int getScoreEmcManage() { + return scoreEmcManage; + } + + public void setScoreEmcManage(int scoreEmcManage) { + this.scoreEmcManage = scoreEmcManage; + } + + public int getScoreBonus() { + return scoreBonus; + } + + public void setScoreBonus(int scoreBonus) { + this.scoreBonus = scoreBonus; + } + + public String getCheckerName() { + return checkerName; + } + + public void setCheckerName(String checkerName) { + this.checkerName = checkerName; + } + + public String getInResponsibilityDetail() { + return inResponsibilityDetail; + } + + public void setInResponsibilityDetail(String inResponsibilityDetail) { + this.inResponsibilityDetail = inResponsibilityDetail; + } + + public int getInResponsibility() { + return inResponsibility; + } + + public void setInResponsibility(int inResponsibility) { + this.inResponsibility = inResponsibility; + } + + public String getInTeamBuildDetail() { + return inTeamBuildDetail; + } + + public void setInTeamBuildDetail(String inTeamBuildDetail) { + this.inTeamBuildDetail = inTeamBuildDetail; + } + + public int getInTeamBuild() { + return inTeamBuild; + } + + public void setInTeamBuild(int inTeamBuild) { + this.inTeamBuild = inTeamBuild; + } + + public String getInDevicesSetupDetail() { + return inDevicesSetupDetail; + } + + public void setInDevicesSetupDetail(String inDevicesSetupDetail) { + this.inDevicesSetupDetail = inDevicesSetupDetail; + } + + public int getInDevicesSetup() { + return inDevicesSetup; + } + + public void setInDevicesSetup(int inDevicesSetup) { + this.inDevicesSetup = inDevicesSetup; + } + + public String getInFireManageDetail() { + return inFireManageDetail; + } + + public void setInFireManageDetail(String inFireManageDetail) { + this.inFireManageDetail = inFireManageDetail; + } + + public int getInFireManage() { + return inFireManage; + } + + public void setInFireManage(int inFireManage) { + this.inFireManage = inFireManage; + } + + public String getInDangerousManageDetail() { + return inDangerousManageDetail; + } + + public void setInDangerousManageDetail(String inDangerousManageDetail) { + this.inDangerousManageDetail = inDangerousManageDetail; + } + + public int getInDangerousManage() { + return inDangerousManage; + } + + public void setInDangerousManage(int inDangerousManage) { + this.inDangerousManage = inDangerousManage; + } + + public String getInSmartSecurityDetail() { + return inSmartSecurityDetail; + } + + public void setInSmartSecurityDetail(String inSmartSecurityDetail) { + this.inSmartSecurityDetail = inSmartSecurityDetail; + } + + public int getInSmartSecurity() { + return inSmartSecurity; + } + + public void setInSmartSecurity(int inSmartSecurity) { + this.inSmartSecurity = inSmartSecurity; + } + + public String getInSecuritySchemeDetail() { + return inSecuritySchemeDetail; + } + + public void setInSecuritySchemeDetail(String inSecuritySchemeDetail) { + this.inSecuritySchemeDetail = inSecuritySchemeDetail; + } + + public int getInSecurityScheme() { + return inSecurityScheme; + } + + public void setInSecurityScheme(int inSecurityScheme) { + this.inSecurityScheme = inSecurityScheme; + } + + public String getOutPeakGuardDetail() { + return outPeakGuardDetail; + } + + public void setOutPeakGuardDetail(String outPeakGuardDetail) { + this.outPeakGuardDetail = outPeakGuardDetail; + } + + public int getOutPeakGuard() { + return outPeakGuard; + } + + public void setOutPeakGuard(int outPeakGuard) { + this.outPeakGuard = outPeakGuard; + } + + public String getOutRiskPreventDetail() { + return outRiskPreventDetail; + } + + public void setOutRiskPreventDetail(String outRiskPreventDetail) { + this.outRiskPreventDetail = outRiskPreventDetail; + } + + public int getOutRiskPrevent() { + return outRiskPrevent; + } + + public void setOutRiskPrevent(int outRiskPrevent) { + this.outRiskPrevent = outRiskPrevent; + } + + public String getOutTrafficDetail() { + return outTrafficDetail; + } + + public void setOutTrafficDetail(String outTrafficDetail) { + this.outTrafficDetail = outTrafficDetail; + } + + public int getOutTraffic() { + return outTraffic; + } + + public void setOutTraffic(int outTraffic) { + this.outTraffic = outTraffic; + } + + public String getOutCaseManageDetail() { + return outCaseManageDetail; + } + + public void setOutCaseManageDetail(String outCaseManageDetail) { + this.outCaseManageDetail = outCaseManageDetail; + } + + public int getOutCaseManage() { + return outCaseManage; + } + + public void setOutCaseManage(int outCaseManage) { + this.outCaseManage = outCaseManage; + } + + public String getRiskDangerManageDetail() { + return riskDangerManageDetail; + } + + public void setRiskDangerManageDetail(String riskDangerManageDetail) { + this.riskDangerManageDetail = riskDangerManageDetail; + } + + public int getRiskDangerManage() { + return riskDangerManage; + } + + public void setRiskDangerManage(int riskDangerManage) { + this.riskDangerManage = riskDangerManage; + } + + public String getRiskConflictManageDetail() { + return riskConflictManageDetail; + } + + public void setRiskConflictManageDetail(String riskConflictManageDetail) { + this.riskConflictManageDetail = riskConflictManageDetail; + } + + public int getRiskConflictManage() { + return riskConflictManage; + } + + public void setRiskConflictManage(int riskConflictManage) { + this.riskConflictManage = riskConflictManage; + } + + public String getRiskProcessDetail() { + return riskProcessDetail; + } + + public void setRiskProcessDetail(String riskProcessDetail) { + this.riskProcessDetail = riskProcessDetail; + } + + public int getRiskProcess() { + return riskProcess; + } + + public void setRiskProcess(int riskProcess) { + this.riskProcess = riskProcess; + } + + public String getLawEducationDetail() { + return lawEducationDetail; + } + + public void setLawEducationDetail(String lawEducationDetail) { + this.lawEducationDetail = lawEducationDetail; + } + + public int getLawEducation() { + return lawEducation; + } + + public void setLawEducation(int lawEducation) { + this.lawEducation = lawEducation; + } + + public String getLawFirstClassDetail() { + return lawFirstClassDetail; + } + + public void setLawFirstClassDetail(String lawFirstClassDetail) { + this.lawFirstClassDetail = lawFirstClassDetail; + } + + public int getLawFirstClass() { + return lawFirstClass; + } + + public void setLawFirstClass(int lawFirstClass) { + this.lawFirstClass = lawFirstClass; + } + + public String getEmcPlanDetail() { + return emcPlanDetail; + } + + public void setEmcPlanDetail(String emcPlanDetail) { + this.emcPlanDetail = emcPlanDetail; + } + + public int getEmcPlan() { + return emcPlan; + } + + public void setEmcPlan(int emcPlan) { + this.emcPlan = emcPlan; + } + + public String getEmcDrillDetail() { + return emcDrillDetail; + } + + public void setEmcDrillDetail(String emcDrillDetail) { + this.emcDrillDetail = emcDrillDetail; + } + + public int getEmcDrill() { + return emcDrill; + } + + public void setEmcDrill(int emcDrill) { + this.emcDrill = emcDrill; + } + + public String getBonus1Detail() { + return bonus1Detail; + } + + public void setBonus1Detail(String bonus1Detail) { + this.bonus1Detail = bonus1Detail; + } + + public int getBonus1() { + return bonus1; + } + + public void setBonus1(int bonus1) { + this.bonus1 = bonus1; + } + + public String getBonus2Detail() { + return bonus2Detail; + } + + public void setBonus2Detail(String bonus2Detail) { + this.bonus2Detail = bonus2Detail; + } + + public int getBonus2() { + return bonus2; + } + + public void setBonus2(int bonus2) { + this.bonus2 = bonus2; + } + + public String getBonus3Detail() { + return bonus3Detail; + } + + public void setBonus3Detail(String bonus3Detail) { + this.bonus3Detail = bonus3Detail; + } + + public int getBonus3() { + return bonus3; + } + + public void setBonus3(int bonus3) { + this.bonus3 = bonus3; + } + + public String getBonus4Detail() { + return bonus4Detail; + } + + public void setBonus4Detail(String bonus4Detail) { + this.bonus4Detail = bonus4Detail; + } + + public int getBonus4() { + return bonus4; + } + + public void setBonus4(int bonus4) { + this.bonus4 = bonus4; + } + + public String getBonus5Detail() { + return bonus5Detail; + } + + public void setBonus5Detail(String bonus5Detail) { + this.bonus5Detail = bonus5Detail; + } + + public int getBonus5() { + return bonus5; + } + + public void setBonus5(int bonus5) { + this.bonus5 = bonus5; + } + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public SchoolStarDetailEntity calcScore(){ + scoreTotal = 1000; + scoreInsideManage = 200; + scoreOutsideManage = 200; + scoreRiskManage = 300; + scoreLawEducation = 100; + scoreEmcManage= 200; + scoreBonus = 0; + + int scoreInsideDec = inResponsibility + inTeamBuild+ inDevicesSetup+inFireManage + inDangerousManage+inSmartSecurity + inSecurityScheme; + if(scoreInsideDec >= 200){ + scoreInsideManage = 0; + }else{ + scoreInsideManage = 200 - scoreInsideDec; + } + + int scoreOutsideDec = outPeakGuard + outRiskPrevent+ outTraffic+outCaseManage; + if(scoreOutsideDec >= 200){ + scoreOutsideManage = 0; + }else{ + scoreOutsideManage = 200 - scoreOutsideDec; + } + + int scoreRiskDec = riskDangerManage + riskConflictManage+ riskProcess; + if(scoreRiskDec >= 250){ + scoreRiskManage = 0; + }else{ + scoreRiskManage = 250 - scoreRiskDec; + } + + int scoreEducationDec = lawEducation + lawFirstClass; + if(scoreEducationDec >= 150){ + scoreLawEducation = 0; + }else{ + scoreLawEducation = 150 - scoreEducationDec; + } + + int scoreEmcDec = emcPlan +emcDrill ; + if(scoreEmcDec >= 200){ + scoreEmcManage = 0; + }else{ + scoreEmcManage = 200 - scoreEmcDec; + } + scoreBonus = bonus1 + bonus2+ bonus3+ bonus4+ bonus5; + scoreTotal = (scoreBonus + scoreInsideManage + scoreOutsideManage + scoreRiskManage + scoreLawEducation + scoreEmcManage); + return this; + } + + + public String getSignatureImage() { + return signatureImage; + } + + public void setSignatureImage(String signatureImage) { + this.signatureImage = signatureImage; + } + + public String getSignatureImageSchool() { + return signatureImageSchool; + } + + public void setSignatureImageSchool(String signatureImageSchool) { + this.signatureImageSchool = signatureImageSchool; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarDetailRecord.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarDetailRecord.java new file mode 100644 index 0000000..484fb1e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarDetailRecord.java @@ -0,0 +1,621 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SchoolStarDetailRecord extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + @JPos(index = 4,primary = true,timekey = true, orderkey = true) + private Date timestamp; + @JPos(index = 5, filter = true) + private String checkerName; + @JPos(index = 6) + private String checkerType; + @JPos(index = 7) + private String inResponsibilityDetail; + @JPos(index = 8,threshold = -1) + private int inResponsibility; + @JPos(index = 9) + private String inTeamBuildDetail; + @JPos(index = 10,threshold = -1) + private int inTeamBuild; + @JPos(index = 11) + private String inDevicesSetupDetail; + @JPos(index = 12,threshold = -1) + private int inDevicesSetup; + @JPos(index = 13) + private String inFireManageDetail; + @JPos(index = 14,threshold = -1) + private int inFireManage; + @JPos(index = 15) + private String inDangerousManageDetail; + @JPos(index = 16,threshold = -1) + private int inDangerousManage; + @JPos(index = 17) + private String inSmartSecurityDetail; + @JPos(index = 18,threshold = -1) + private int inSmartSecurity; + @JPos(index = 19) + private String inSecuritySchemeDetail; + @JPos(index = 20,threshold = -1) + private int inSecurityScheme; + @JPos(index = 21) + private String outPeakGuardDetail; + @JPos(index = 22,threshold = -1) + private int outPeakGuard; + @JPos(index = 23) + private String outRiskPreventDetail; + @JPos(index = 24,threshold = -1) + private int outRiskPrevent; + @JPos(index = 25) + private String outTrafficDetail; + @JPos(index = 26,threshold = -1) + private int outTraffic; + @JPos(index = 27) + private String outCaseManageDetail; + @JPos(index = 28,threshold = -1) + private int outCaseManage; + @JPos(index = 29) + private String riskDangerManageDetail; + @JPos(index = 30,threshold = -1) + private int riskDangerManage; + @JPos(index = 31) + private String riskConflictManageDetail; + @JPos(index = 32,threshold = -1) + private int riskConflictManage; + @JPos(index = 33) + private String riskProcessDetail; + @JPos(index = 34,threshold = -1) + private int riskProcess; + @JPos(index = 35) + private String lawEducationDetail; + @JPos(index = 36,threshold = -1) + private int lawEducation; + @JPos(index = 37) + private String lawFirstClassDetail; + @JPos(index = 38,threshold = -1) + private int lawFirstClass; + @JPos(index = 39) + private String emcPlanDetail; + @JPos(index = 40,threshold = -1) + private int emcPlan; + @JPos(index = 41) + private String emcDrillDetail; + @JPos(index = 42,threshold = -1) + private int emcDrill; + @JPos(index = 43) + private String bonus1Detail; + @JPos(index = 44,threshold = -1) + private int bonus1; + @JPos(index = 45) + private String bonus2Detail; + @JPos(index = 46,threshold = -1) + private int bonus2; + @JPos(index = 47) + private String bonus3Detail; + @JPos(index = 48,threshold = -1) + private int bonus3; + @JPos(index = 49) + private String bonus4Detail; + @JPos(index = 50,threshold = -1) + private int bonus4; + @JPos(index = 51) + private String bonus5Detail; + @JPos(index = 52,threshold = -1) + private int bonus5; + @JPos(index = 53, filter = true) + private String schoolTime; + + @JPos(index = 54, strlen = 8192) + private String checkerSignature; + + + public String tableName(){ + return "school_star_detail_record_table"; + } + + public SchoolStarDetailRecord(){ + station = ""; + brigade = ""; + detachment = ""; + borough = ""; + timestamp = new Date(); + checkerName = ""; + inResponsibilityDetail = ""; + inResponsibility = 0; + inTeamBuildDetail = ""; + inTeamBuild = 0; + inDevicesSetupDetail = ""; + inDevicesSetup = 0; + inFireManageDetail = ""; + inFireManage = 0; + inDangerousManageDetail = ""; + inDangerousManage = 0; + inSmartSecurityDetail = ""; + inSmartSecurity = 0; + inSecuritySchemeDetail = ""; + inSecurityScheme = 0; + outPeakGuardDetail = ""; + outPeakGuard = 0; + outRiskPreventDetail = ""; + outRiskPrevent = 0; + outTrafficDetail = ""; + outTraffic = 0; + outCaseManageDetail = ""; + outCaseManage = 0; + riskDangerManageDetail = ""; + riskDangerManage = 0; + riskConflictManageDetail = ""; + riskConflictManage = 0; + riskProcessDetail = ""; + riskProcess = 0; + lawEducationDetail = ""; + lawEducation = 0; + lawFirstClassDetail = ""; + lawFirstClass = 0; + emcPlanDetail = ""; + emcPlan = 0; + emcDrillDetail = ""; + emcDrill = 0; + bonus1Detail = ""; + bonus1 = 0; + bonus2Detail = ""; + bonus2 = 0; + bonus3Detail = ""; + bonus3 = 0; + bonus4Detail = ""; + bonus4 = 0; + bonus5Detail = ""; + bonus5 = 0; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getCheckerName() { + return checkerName; + } + + public void setCheckerName(String checkerName) { + this.checkerName = checkerName; + } + + public String getInResponsibilityDetail() { + return inResponsibilityDetail; + } + + public void setInResponsibilityDetail(String inResponsibilityDetail) { + this.inResponsibilityDetail = inResponsibilityDetail; + } + + public int getInResponsibility() { + return inResponsibility; + } + + public void setInResponsibility(int inResponsibility) { + this.inResponsibility = inResponsibility; + } + + public String getInTeamBuildDetail() { + return inTeamBuildDetail; + } + + public void setInTeamBuildDetail(String inTeamBuildDetail) { + this.inTeamBuildDetail = inTeamBuildDetail; + } + + public int getInTeamBuild() { + return inTeamBuild; + } + + public void setInTeamBuild(int inTeamBuild) { + this.inTeamBuild = inTeamBuild; + } + + public String getInDevicesSetupDetail() { + return inDevicesSetupDetail; + } + + public void setInDevicesSetupDetail(String inDevicesSetupDetail) { + this.inDevicesSetupDetail = inDevicesSetupDetail; + } + + public int getInDevicesSetup() { + return inDevicesSetup; + } + + public void setInDevicesSetup(int inDevicesSetup) { + this.inDevicesSetup = inDevicesSetup; + } + + public String getInFireManageDetail() { + return inFireManageDetail; + } + + public void setInFireManageDetail(String inFireManageDetail) { + this.inFireManageDetail = inFireManageDetail; + } + + public int getInFireManage() { + return inFireManage; + } + + public void setInFireManage(int inFireManage) { + this.inFireManage = inFireManage; + } + + public String getInDangerousManageDetail() { + return inDangerousManageDetail; + } + + public void setInDangerousManageDetail(String inDangerousManageDetail) { + this.inDangerousManageDetail = inDangerousManageDetail; + } + + public int getInDangerousManage() { + return inDangerousManage; + } + + public void setInDangerousManage(int inDangerousManage) { + this.inDangerousManage = inDangerousManage; + } + + public String getInSmartSecurityDetail() { + return inSmartSecurityDetail; + } + + public void setInSmartSecurityDetail(String inSmartSecurityDetail) { + this.inSmartSecurityDetail = inSmartSecurityDetail; + } + + public int getInSmartSecurity() { + return inSmartSecurity; + } + + public void setInSmartSecurity(int inSmartSecurity) { + this.inSmartSecurity = inSmartSecurity; + } + + public String getInSecuritySchemeDetail() { + return inSecuritySchemeDetail; + } + + public void setInSecuritySchemeDetail(String inSecuritySchemeDetail) { + this.inSecuritySchemeDetail = inSecuritySchemeDetail; + } + + public int getInSecurityScheme() { + return inSecurityScheme; + } + + public void setInSecurityScheme(int inSecurityScheme) { + this.inSecurityScheme = inSecurityScheme; + } + + public String getOutPeakGuardDetail() { + return outPeakGuardDetail; + } + + public void setOutPeakGuardDetail(String outPeakGuardDetail) { + this.outPeakGuardDetail = outPeakGuardDetail; + } + + public int getOutPeakGuard() { + return outPeakGuard; + } + + public void setOutPeakGuard(int outPeakGuard) { + this.outPeakGuard = outPeakGuard; + } + + public String getOutRiskPreventDetail() { + return outRiskPreventDetail; + } + + public void setOutRiskPreventDetail(String outRiskPreventDetail) { + this.outRiskPreventDetail = outRiskPreventDetail; + } + + public int getOutRiskPrevent() { + return outRiskPrevent; + } + + public void setOutRiskPrevent(int outRiskPrevent) { + this.outRiskPrevent = outRiskPrevent; + } + + public String getOutTrafficDetail() { + return outTrafficDetail; + } + + public void setOutTrafficDetail(String outTrafficDetail) { + this.outTrafficDetail = outTrafficDetail; + } + + public int getOutTraffic() { + return outTraffic; + } + + public void setOutTraffic(int outTraffic) { + this.outTraffic = outTraffic; + } + + public String getOutCaseManageDetail() { + return outCaseManageDetail; + } + + public void setOutCaseManageDetail(String outCaseManageDetail) { + this.outCaseManageDetail = outCaseManageDetail; + } + + public int getOutCaseManage() { + return outCaseManage; + } + + public void setOutCaseManage(int outCaseManage) { + this.outCaseManage = outCaseManage; + } + + public String getRiskDangerManageDetail() { + return riskDangerManageDetail; + } + + public void setRiskDangerManageDetail(String riskDangerManageDetail) { + this.riskDangerManageDetail = riskDangerManageDetail; + } + + public int getRiskDangerManage() { + return riskDangerManage; + } + + public void setRiskDangerManage(int riskDangerManage) { + this.riskDangerManage = riskDangerManage; + } + + public String getRiskConflictManageDetail() { + return riskConflictManageDetail; + } + + public void setRiskConflictManageDetail(String riskConflictManageDetail) { + this.riskConflictManageDetail = riskConflictManageDetail; + } + + public int getRiskConflictManage() { + return riskConflictManage; + } + + public void setRiskConflictManage(int riskConflictManage) { + this.riskConflictManage = riskConflictManage; + } + + public String getRiskProcessDetail() { + return riskProcessDetail; + } + + public void setRiskProcessDetail(String riskProcessDetail) { + this.riskProcessDetail = riskProcessDetail; + } + + public int getRiskProcess() { + return riskProcess; + } + + public void setRiskProcess(int riskProcess) { + this.riskProcess = riskProcess; + } + + public String getLawEducationDetail() { + return lawEducationDetail; + } + + public void setLawEducationDetail(String lawEducationDetail) { + this.lawEducationDetail = lawEducationDetail; + } + + public int getLawEducation() { + return lawEducation; + } + + public void setLawEducation(int lawEducation) { + this.lawEducation = lawEducation; + } + + public String getLawFirstClassDetail() { + return lawFirstClassDetail; + } + + public void setLawFirstClassDetail(String lawFirstClassDetail) { + this.lawFirstClassDetail = lawFirstClassDetail; + } + + public int getLawFirstClass() { + return lawFirstClass; + } + + public void setLawFirstClass(int lawFirstClass) { + this.lawFirstClass = lawFirstClass; + } + + public String getEmcPlanDetail() { + return emcPlanDetail; + } + + public void setEmcPlanDetail(String emcPlanDetail) { + this.emcPlanDetail = emcPlanDetail; + } + + public int getEmcPlan() { + return emcPlan; + } + + public void setEmcPlan(int emcPlan) { + this.emcPlan = emcPlan; + } + + public String getEmcDrillDetail() { + return emcDrillDetail; + } + + public void setEmcDrillDetail(String emcDrillDetail) { + this.emcDrillDetail = emcDrillDetail; + } + + public int getEmcDrill() { + return emcDrill; + } + + public void setEmcDrill(int emcDrill) { + this.emcDrill = emcDrill; + } + + public String getBonus1Detail() { + return bonus1Detail; + } + + public void setBonus1Detail(String bonus1Detail) { + this.bonus1Detail = bonus1Detail; + } + + public int getBonus1() { + return bonus1; + } + + public void setBonus1(int bonus1) { + this.bonus1 = bonus1; + } + + public String getBonus2Detail() { + return bonus2Detail; + } + + public void setBonus2Detail(String bonus2Detail) { + this.bonus2Detail = bonus2Detail; + } + + public int getBonus2() { + return bonus2; + } + + public void setBonus2(int bonus2) { + this.bonus2 = bonus2; + } + + public String getBonus3Detail() { + return bonus3Detail; + } + + public void setBonus3Detail(String bonus3Detail) { + this.bonus3Detail = bonus3Detail; + } + + public int getBonus3() { + return bonus3; + } + + public void setBonus3(int bonus3) { + this.bonus3 = bonus3; + } + + public String getBonus4Detail() { + return bonus4Detail; + } + + public void setBonus4Detail(String bonus4Detail) { + this.bonus4Detail = bonus4Detail; + } + + public int getBonus4() { + return bonus4; + } + + public void setBonus4(int bonus4) { + this.bonus4 = bonus4; + } + + public String getBonus5Detail() { + return bonus5Detail; + } + + public void setBonus5Detail(String bonus5Detail) { + this.bonus5Detail = bonus5Detail; + } + + public int getBonus5() { + return bonus5; + } + + public void setBonus5(int bonus5) { + this.bonus5 = bonus5; + } + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public String getCheckerType() { + return checkerType; + } + + public void setCheckerType(String checkerType) { + this.checkerType = checkerType; + } + + public String getCheckerSignature() { + return checkerSignature; + } + + public void setCheckerSignature(String checkerSignature) { + this.checkerSignature = checkerSignature; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarRatingCompose.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarRatingCompose.java new file mode 100644 index 0000000..d382ce1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarRatingCompose.java @@ -0,0 +1,370 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; + +public class SchoolStarRatingCompose { + + private String station; + private String brigade; + private String detachment; + + private String borough; + + private int totalStar1; + private int totalStar2; + private int totalStar3; + private int totalStar4; + private int totalStar5; + + private int insideBad; + private int insideGood; + private int insideGreat; + + private int outsideBad; + private int outsideGood; + private int outsideGreat; + + private int riskBad; + private int riskGood; + private int riskGreat; + + private int lawBad; + private int lawGood; + private int lawGreat; + + private int emcBad; + private int emcGood; + private int emcGreat; + + private int bonus; + + public SchoolStarRatingCompose(){ + totalStar1 = 0; + totalStar2 = 0; + totalStar3 = 0; + totalStar4 = 0; + totalStar5 = 0; + insideBad = 0; + insideGood = 0; + insideGreat = 0; + outsideBad = 0; + outsideGood = 0; + outsideGreat = 0; + riskBad = 0; + riskGood = 0; + riskGreat = 0; + lawBad = 0; + lawGood = 0; + lawGreat = 0; + emcBad = 0; + emcGood = 0; + emcGreat = 0; + bonus = 0; + } + + public int getTotalStar1() { + return totalStar1; + } + + public void setTotalStar1(int totalStar1) { + this.totalStar1 = totalStar1; + } + + public int getTotalStar2() { + return totalStar2; + } + + public void setTotalStar2(int totalStar2) { + this.totalStar2 = totalStar2; + } + + public int getTotalStar3() { + return totalStar3; + } + + public void setTotalStar3(int totalStar3) { + this.totalStar3 = totalStar3; + } + + public int getTotalStar4() { + return totalStar4; + } + + public void setTotalStar4(int totalStar4) { + this.totalStar4 = totalStar4; + } + + public int getTotalStar5() { + return totalStar5; + } + + public void setTotalStar5(int totalStar5) { + this.totalStar5 = totalStar5; + } + + public int getInsideBad() { + return insideBad; + } + + public void setInsideBad(int insideBad) { + this.insideBad = insideBad; + } + + public int getInsideGood() { + return insideGood; + } + + public void setInsideGood(int insideGood) { + this.insideGood = insideGood; + } + + public int getInsideGreat() { + return insideGreat; + } + + public void setInsideGreat(int insideGreat) { + this.insideGreat = insideGreat; + } + + public int getOutsideBad() { + return outsideBad; + } + + public void setOutsideBad(int outsideBad) { + this.outsideBad = outsideBad; + } + + public int getOutsideGood() { + return outsideGood; + } + + public void setOutsideGood(int outsideGood) { + this.outsideGood = outsideGood; + } + + public int getOutsideGreat() { + return outsideGreat; + } + + public void setOutsideGreat(int outsideGreat) { + this.outsideGreat = outsideGreat; + } + + public int getRiskBad() { + return riskBad; + } + + public void setRiskBad(int riskBad) { + this.riskBad = riskBad; + } + + public int getRiskGood() { + return riskGood; + } + + public void setRiskGood(int riskGood) { + this.riskGood = riskGood; + } + + public int getRiskGreat() { + return riskGreat; + } + + public void setRiskGreat(int riskGreat) { + this.riskGreat = riskGreat; + } + + public int getLawBad() { + return lawBad; + } + + public void setLawBad(int lawBad) { + this.lawBad = lawBad; + } + + public int getLawGood() { + return lawGood; + } + + public void setLawGood(int lawGood) { + this.lawGood = lawGood; + } + + public int getLawGreat() { + return lawGreat; + } + + public void setLawGreat(int lawGreat) { + this.lawGreat = lawGreat; + } + + public int getEmcBad() { + return emcBad; + } + + public void setEmcBad(int emcBad) { + this.emcBad = emcBad; + } + + public int getEmcGood() { + return emcGood; + } + + public void setEmcGood(int emcGood) { + this.emcGood = emcGood; + } + + public int getEmcGreat() { + return emcGreat; + } + + public void setEmcGreat(int emcGreat) { + this.emcGreat = emcGreat; + } + + public int getBonus() { + return bonus; + } + + public void setBonus(int bonus) { + this.bonus = bonus; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + + + public void addTotalStar1() { + this.totalStar1 += 1; + } + + public void addTotalStar2() { + this.totalStar2 += 1; + } + + + public void addTotalStar3() { + this.totalStar3 += 1; + } + + + public void addTotalStar4() { + this.totalStar4 += 1; + } + + + public void addTotalStar5() { + this.totalStar5 += 1; + } + + + public void addInsideBad() { + this.insideBad += 1; + } + + + public void addInsideGood() { + this.insideGood += 1; + } + + + public void addInsideGreat() { + this.insideGreat += 1; + } + + + public void addOutsideBad() { + this.outsideBad += 1; + } + + + public void addOutsideGood() { + this.outsideGood += 1; + } + + + public void addOutsideGreat() { + this.outsideGreat += 1; + } + + + public void addRiskBad() { + this.riskBad += 1; + } + + + public void addRiskGood() { + this.riskGood += 1; + } + + + public void addRiskGreat() { + this.riskGreat += 1; + } + + + public void addLawBad() { + this.lawBad += 1; + } + + + public void addLawGood() { + this.lawGood += 1; + } + + + public void addLawGreat() { + this.lawGreat += 1; + } + + + public void addEmcBad() { + this.emcBad += 1; + } + + + public void addEmcGood() { + this.emcGood += 1; + } + + + public void addEmcGreat() { + this.emcGreat += 1; + } + + + public void addBonus() { + this.bonus += 1; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarRatingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarRatingEntity.java new file mode 100644 index 0000000..5ad3282 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolStarRatingEntity.java @@ -0,0 +1,161 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.firestationport.model.statistics.StationDaySummaryEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SchoolStarRatingEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + @JPos(index = 4,timekey = true) + private Date timestamp; + @JPos(index = 5,threshold = -1,orderkey = true) + private int scoreTotal; + @JPos(index = 6,threshold = -1) + private int scoreInsideManage; + @JPos(index = 7,threshold = -1) + private int scoreOutsideManage; + @JPos(index = 8,threshold = -1) + private int scoreRiskManage; + @JPos(index = 9,threshold = -1) + private int scoreLawEducation; + @JPos(index = 10,threshold = -1) + private int scoreEmcManage; + @JPos(index = 11,threshold = -1) + private int scoreBonus; + @JPos(index = 12, primary = true, filter = true) + private String schoolTime; + + + public String tableName(){ + return "school_star_rating_table"; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public int getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(int scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public int getScoreInsideManage() { + return scoreInsideManage; + } + + public void setScoreInsideManage(int scoreInsideManage) { + this.scoreInsideManage = scoreInsideManage; + } + + public int getScoreOutsideManage() { + return scoreOutsideManage; + } + + public void setScoreOutsideManage(int scoreOutsideManage) { + this.scoreOutsideManage = scoreOutsideManage; + } + + public int getScoreRiskManage() { + return scoreRiskManage; + } + + public void setScoreRiskManage(int scoreRiskManage) { + this.scoreRiskManage = scoreRiskManage; + } + + public int getScoreLawEducation() { + return scoreLawEducation; + } + + public void setScoreLawEducation(int scoreLawEducation) { + this.scoreLawEducation = scoreLawEducation; + } + + public int getScoreEmcManage() { + return scoreEmcManage; + } + + public void setScoreEmcManage(int scoreEmcManage) { + this.scoreEmcManage = scoreEmcManage; + } + + public int getScoreBonus() { + return scoreBonus; + } + + public void setScoreBonus(int scoreBonus) { + this.scoreBonus = scoreBonus; + } + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public static List QueryBonus(DataSource dataSource, String brigadeName, String schoolTime) { + SchoolStarRatingEntity info = new SchoolStarRatingEntity(); + // String sql = "select * from " + info.tableName() + " where brigade='" + brigadeName + "' and scoreBonus > 0 order by scoreBonus"; + String sql = "select * from " + info.tableName() + " where brigade='" + brigadeName +"' and schoolTime='"+ schoolTime +"' and scoreBonus > 0 order by scoreBonus"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SchoolStarRatingEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolTimeLabelEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolTimeLabelEntity.java new file mode 100644 index 0000000..7cc8e70 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/SchoolTimeLabelEntity.java @@ -0,0 +1,56 @@ +package com.jingyi.iotserver.firestationport.model.school; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class SchoolTimeLabelEntity extends SQLDataObject { + + public static final String TYPE_STAR = "star"; + public static final String TYPE_COLOR = "color"; + + @JPos(index=0,primary = true,filter = true) + private String schoolTime; + @JPos(index=1,primary = true,filter = true) + private String brigade; + @JPos(index=2,primary = true,filter = true) + private String type; + @JPos(index=3) + private String comment; + + public String tableName( ){ + return "school_time_table"; + } + + + public String getSchoolTime() { + return schoolTime; + } + + public void setSchoolTime(String schoolTime) { + this.schoolTime = schoolTime; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/StudentVipEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/StudentVipEntity.java new file mode 100644 index 0000000..d875e9e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/StudentVipEntity.java @@ -0,0 +1,165 @@ +package com.jingyi.iotserver.firestationport.model.school; + + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Base64; + +/* +学生性别,学生姓名,家长名称,家长电话,家庭情况,家庭地址,所在班级,班主任, + */ +public class StudentVipEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true) + private String studentId; + @JPos(index = 1,filter = true) + private String name; + @JPos(index = 2) + private String gender; + @JPos(index = 3) + private String parentName; + @JPos(index = 4) + private String parentPhone; + @JPos(index = 5) + private String homeInfo; + @JPos(index = 6) + private String homeAddress; + @JPos(index = 7) + private String classroom; + @JPos(index = 8) + private String teacher; + + @JPos(index = 9,filter = true) + private String brigade; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index = 11,filter = true) + private String detachment; + @JPos(index = 12,filter = true) + private String station; + + + public String tableName() { + return "school_students_table"; + } + + public String getStudentId() { + return studentId; + } + + public void setStudentId(String studentId) { + this.studentId = studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } + + public String getParentPhone() { + return parentPhone; + } + + public void setParentPhone(String parentPhone) { + this.parentPhone = parentPhone; + } + + public String getHomeInfo() { + return homeInfo; + } + + public void setHomeInfo(String homeInfo) { + this.homeInfo = homeInfo; + } + + public String getHomeAddress() { + return homeAddress; + } + + public void setHomeAddress(String homeAddress) { + this.homeAddress = homeAddress; + } + + public String getClassroom() { + return classroom; + } + + public void setClassroom(String classroom) { + this.classroom = classroom; + } + + public String getTeacher() { + return teacher; + } + + public void setTeacher(String teacher) { + this.teacher = teacher; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public void encode(){ + /* + if(gender != null){ + gender = Base64.getEncoder().encodeToString(gender); + Base64.getMimeEncoder(). + } + parentName; + parentPhone; + homeInfo; + homeAddress; + classroom; + teacher; + + */ + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/school/WechatAccountInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/school/WechatAccountInfo.java new file mode 100644 index 0000000..6e91358 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/school/WechatAccountInfo.java @@ -0,0 +1,14 @@ +package com.jingyi.iotserver.firestationport.model.school; + +public class WechatAccountInfo { + private String code; + + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ACBEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ACBEventEntity.java new file mode 100644 index 0000000..cc4bee9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ACBEventEntity.java @@ -0,0 +1,75 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class ACBEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 1, primary = true,filter = true) + private String deviceid; + @JPos(index = 2) + private int devid; + @JPos(index = 3, filter = true) + private String type;//alarm | status + @JPos(index = 4, strlen = 1024) + private String content; + @JPos(index = 5, filter = true) + private String owner; + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevid(int devid) { + this.devid = devid; + } + + public int getDevid() { + return devid; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public String tableName(){ + return "iotserver_sensor_acb_alarm_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ACBStatusEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ACBStatusEntity.java new file mode 100644 index 0000000..6fdc66d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ACBStatusEntity.java @@ -0,0 +1,404 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class ACBStatusEntity extends SQLDataObject { + @JPos(index = 0, primary = true,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 1, primary = true,filter = true) + private String deviceid; + @JPos(index = 2) + private int devid; + @JPos(index = 3, filter = true) + private String type;//alarm | status + @JPos(index = 4, filter = true) + private String owner; + + @JPos(index = 5, filter = true) + private String mac; + + @JPos(index=6,filter = true) + private int addr; + + @JPos(index=7) + private String online; + @JPos(index=8) + private String validity; + @JPos(index=9) + private String oc; + @JPos(index=10) + private String enablenetctrl; + + @JPos(index=11) + private double power; + @JPos(index=12) + private String linetype; + @JPos(index=13) + private int alarm; + + @JPos(index=14) + private double ald; + + @JPos(index=15) + private double aa; + @JPos(index=16) + private double at; + @JPos(index=17) + private double av; + @JPos(index=18) + private double aw; + @JPos(index=19) + private double apf; + + @JPos(index=20) + private double gld; + @JPos(index=21) + private double ga; + @JPos(index=22) + private double gt; + @JPos(index=23) + private double gv; + @JPos(index=24) + private double gw; + @JPos(index=25) + private double gpf; + + @JPos(index=26) + private double ba; + @JPos(index=27) + private double bt; + @JPos(index=28) + private double bv; + @JPos(index=29) + private double bw; + @JPos(index=30) + private double bpf; + + @JPos(index=31) + private double ca; + @JPos(index=32) + private double ct; + @JPos(index=33) + private double cv; + @JPos(index=34) + private double cw; + @JPos(index=35) + private double cpf; + + @JPos(index=36) + private double na; + @JPos(index=37) + private double nt; + + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevid(int devid) { + this.devid = devid; + } + + public int getDevid() { + return devid; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setMac(String mac) { + this.mac = mac; + } + + public String getMac() { + return mac; + } + + public void setAddr(int addr) { + this.addr = addr; + } + + public int getAddr() { + return addr; + } + + public void setOnline(String online) { + this.online = online; + } + + public String getOnline() { + return online; + } + + public void setValidity(String validity) { + this.validity = validity; + } + + public String getValidity() { + return validity; + } + + public void setOc(String oc) { + this.oc = oc; + } + + public String getOc() { + return oc; + } + + public void setEnablenetctrl(String enablenetctrl) { + this.enablenetctrl = enablenetctrl; + } + + public String getEnablenetctrl() { + return enablenetctrl; + } + + public void setPower(double power) { + this.power = power; + } + + public double getPower() { + return power; + } + + public void setLinetype(String linetype) { + this.linetype = linetype; + } + + public String getLinetype() { + return linetype; + } + + public void setAlarm(int alarm) { + this.alarm = alarm; + } + + public int getAlarm() { + return alarm; + } + + public void setAld(double ald) { + this.ald = ald; + } + + public double getAld() { + return ald; + } + + public void setAa(double aa) { + this.aa = aa; + } + + public double getAa() { + return aa; + } + + public void setAt(double at) { + this.at = at; + } + + public double getAt() { + return at; + } + + public void setAv(double av) { + this.av = av; + } + + public double getAv() { + return av; + } + + public void setAw(double aw) { + this.aw = aw; + } + + public double getAw() { + return aw; + } + + public void setApf(double apf) { + this.apf = apf; + } + + public double getApf() { + return apf; + } + + public void setGld(double gld) { + this.gld = gld; + } + + public double getGld() { + return gld; + } + + public void setGa(double ga) { + this.ga = ga; + } + + public double getGa() { + return ga; + } + + public void setGt(double gt) { + this.gt = gt; + } + + public double getGt() { + return gt; + } + + public void setGv(double gv) { + this.gv = gv; + } + + public double getGv() { + return gv; + } + + public void setGw(double gw) { + this.gw = gw; + } + + public double getGw() { + return gw; + } + + public void setGpf(double gpf) { + this.gpf = gpf; + } + + public double getGpf() { + return gpf; + } + + public void setBa(double ba) { + this.ba = ba; + } + + public double getBa() { + return ba; + } + + public void setBt(double bt) { + this.bt = bt; + } + + public double getBt() { + return bt; + } + + public void setBv(double bv) { + this.bv = bv; + } + + public double getBv() { + return bv; + } + + public void setBw(double bw) { + this.bw = bw; + } + + public double getBw() { + return bw; + } + + public void setBpf(double bpf) { + this.bpf = bpf; + } + + public double getBpf() { + return bpf; + } + + public void setCa(double ca) { + this.ca = ca; + } + + public double getCa() { + return ca; + } + + public void setCt(double ct) { + this.ct = ct; + } + + public double getCt() { + return ct; + } + + public void setCv(double cv) { + this.cv = cv; + } + + public double getCv() { + return cv; + } + + public void setCw(double cw) { + this.cw = cw; + } + + public double getCw() { + return cw; + } + + public void setCpf(double cpf) { + this.cpf = cpf; + } + + public double getCpf() { + return cpf; + } + + public void setNa(double na) { + this.na = na; + } + + public double getNa() { + return na; + } + + public void setNt(double nt) { + this.nt = nt; + } + + public double getNt() { + return nt; + } + + public String tableName(){ + return "iotserver_sensor_acb_status_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/AICameraEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/AICameraEventEntity.java new file mode 100644 index 0000000..1b99d79 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/AICameraEventEntity.java @@ -0,0 +1,44 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class AICameraEventEntity extends SQLDataObject { + @JPos(index = 0,timekey = true,orderkey = true) + private Date reporttime; + @JPos(index = 1, filter = true) + private String deviceid; + @JPos(index = 2) + private String deviceip; + @JPos(index = 3) + private String channelid; + @JPos(index = 4) + private String channelip; + @JPos(index = 5) + private int alarmtype; + @JPos(index = 6, primary = true) + private String alarmid; + @JPos(index = 7) + private String alarmtarget; + @JPos(index = 8) + private String alarmlevel; + @JPos(index = 9) + private Date timestamp; + @JPos(index = 10) + private String image; /*big image */ + @JPos(index = 11) + private String thumbnail; /*small image */ + @JPos(index = 12,strlen=1024) + private String data; + @JPos(index = 13, filter = true) + private String owner; + + + public String tableName(){ + return "iotserver_sensor_aicamera_alarm_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/AlerterHostEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/AlerterHostEventEntity.java new file mode 100644 index 0000000..1010aa7 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/AlerterHostEventEntity.java @@ -0,0 +1,115 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class AlerterHostEventEntity extends SQLDataObject{ + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String devicetype; + @JPos(index = 2, filter = true) + private String owner; + @JPos(index = 3, primary = true,timekey = true,orderkey = true) + protected Date timestamp; + + @JPos(index = 4, filter = true) + private String event; //sys-event, mod-event + @JPos(index = 5) + private String systype; + @JPos(index = 6) + private String sysaddr; + @JPos(index = 7) + private String moduletype; + @JPos(index = 8) + private String moduleaddr; + @JPos(index = 9,strlen = 1024) + private String alarm; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setSystype(String systype) { + this.systype = systype; + } + + public String getSystype() { + return systype; + } + + public void setSysaddr(String sysaddr) { + this.sysaddr = sysaddr; + } + + public String getSysaddr() { + return sysaddr; + } + + public void setModuletype(String moduletype) { + this.moduletype = moduletype; + } + + public String getModuletype() { + return moduletype; + } + + public void setModuleaddr(String moduleaddr) { + this.moduleaddr = moduleaddr; + } + + public String getModuleaddr() { + return moduleaddr; + } + + public void setAlarm(String alarm) { + this.alarm = alarm; + } + + public String getAlarm() { + return alarm; + } + + public String tableName( ){ + return "iotserver_sensor_alerter_host_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/CityMgrCommonEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/CityMgrCommonEntity.java new file mode 100644 index 0000000..f9bcc7f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/CityMgrCommonEntity.java @@ -0,0 +1,104 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import org.w3c.dom.Text; + +import java.util.Date; + +public class CityMgrCommonEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String id; + @JPos(index = 1,filter = true) + private String type; + @JPos(index = 2, filter = true) + private String deviceid; + @JPos(index = 3, filter = true) + private String townid; + @JPos(index = 4, filter = true) + private String townname; + @JPos(index = 5,filter = true) + private String source; + @JPos(index = 6, timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 7, strlen = 8192) + private String data; + @JPos(index = 8,filter = true) + private String state; // unprocessed | processed + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public String tableName(){ + return "iotserver_sensor_city_mgr_common_table"; + } + + public String getTownid() { + return townid; + } + + public void setTownid(String townid) { + this.townid = townid; + } + + public String getTownname() { + return townname; + } + + public void setTownname(String townname) { + this.townname = townname; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/CityMgrEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/CityMgrEventEntity.java new file mode 100644 index 0000000..0f2e5ab --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/CityMgrEventEntity.java @@ -0,0 +1,103 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class CityMgrEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String taskid; + @JPos(index = 1,filter = true) + private String taskname; + @JPos(index = 2,filter = true) + private String taskaddress; + @JPos(index = 3) + private double longitude; + @JPos(index = 4) + private double latitude; + @JPos(index = 5, timekey = true,orderkey = true) + private Date pushtime; + @JPos(index = 6 ) + private Date endtime; + @JPos(index = 7,strlen = 4096) + private String taskdescribe; + @JPos(index = 8,filter = true) + private String state; // unprocessed | processed + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setTaskname(String taskname) { + this.taskname = taskname; + } + + public String getTaskname() { + return taskname; + } + + public void setTaskaddress(String taskaddress) { + this.taskaddress = taskaddress; + } + + public String getTaskaddress() { + return taskaddress; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setPushtime(Date pushtime) { + this.pushtime = pushtime; + } + + public Date getPushtime() { + return pushtime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + public Date getEndtime() { + return endtime; + } + + public void setTaskdescribe(String taskdescribe) { + this.taskdescribe = taskdescribe; + } + + public String getTaskdescribe() { + return taskdescribe; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public String tableName(){ + return "iotserver_sensor_city_mgr_task_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/DeShangAnData.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/DeShangAnData.java new file mode 100644 index 0000000..04b76b2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/DeShangAnData.java @@ -0,0 +1,67 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + + +public class DeShangAnData { + /** + * 来电显示 + */ + private String callerId; + /** + * 账号 + */ + private String account; + /** + * 子系统 + */ + private String subsystem; + /** + * 防区号 + */ + private String defenceAreaNumber; + + /** + * 时间 + */ + private String time; + + public String getCallerId() { + return callerId; + } + + public void setCallerId(String callerId) { + this.callerId = callerId; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getSubsystem() { + return subsystem; + } + + public void setSubsystem(String subsystem) { + this.subsystem = subsystem; + } + + public String getDefenceAreaNumber() { + return defenceAreaNumber; + } + + public void setDefenceAreaNumber(String defenceAreaNumber) { + this.defenceAreaNumber = defenceAreaNumber; + } + + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/DoorAutoLockEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/DoorAutoLockEventEntity.java new file mode 100644 index 0000000..027ac83 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/DoorAutoLockEventEntity.java @@ -0,0 +1,64 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class DoorAutoLockEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String owner; + @JPos(index = 2,primary = true,timekey = true,orderkey = true,update = false) + protected Date timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + + @JPos(index = 4,filter = true) + private String state; //lock | unlock + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public String tableName(){ + return "iotserver_door_autolock_sensor_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EarthInductorBuzEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EarthInductorBuzEventEntity.java new file mode 100644 index 0000000..0350c1b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EarthInductorBuzEventEntity.java @@ -0,0 +1,188 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class EarthInductorBuzEventEntity extends SQLDataObject { + @JPos(index = 0, identify = true) + private int eventid; + @JPos(index = 1, primary = true,filter = true) + private String deviceid; + @JPos(index = 2, filter = true) + protected String devicetype; + @JPos(index = 3,filter = true) + private String owner; + @JPos(index = 4,filter = true) + private String buztype; + @JPos(index = 5, primary = true,timekey = true,orderkey = true,update = false) + private Date starttime; + @JPos(index = 6) + private Date endtime; + @JPos(index = 7,filter = true) + private String status; //start / stop + @JPos(index = 8,filter = true) + private String brigade; + @JPos(index = 9,filter = true) + private String borough; + @JPos(index = 10,filter = true) + private String detachment; + + public void setEventid(int eventid) { + this.eventid = eventid; + } + + public int getEventid() { + return eventid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setBuztype(String buztype) { + this.buztype = buztype; + } + + public String getBuztype() { + return buztype; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + public Date getEndtime() { + return endtime; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public String tableName( ){ + return "iotserver_earthinductor_buz_event_table"; + } + + + public boolean Delete(DataSource dataSource){ + String sql = "DELETE FROM "+tableName()+" WHERE eventid="+eventid; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + + public static EarthInductorBuzEventEntity Query(DataSource dataSource, String eventid) { + EarthInductorBuzEventEntity event = new EarthInductorBuzEventEntity(); + String sql = "select * from " + event.tableName() + " where eventid='" + eventid + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, EarthInductorBuzEventEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static EarthInductorBuzEventEntity Query(DataSource dataSource, String deviceid,String status) { + EarthInductorBuzEventEntity event = new EarthInductorBuzEventEntity(); + String sql = "select * from " + event.tableName() + " where deviceid='" + deviceid + "' and status='"+status+"'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, EarthInductorBuzEventEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + + + public boolean Stop(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + status = "stop"; + endtime = new Date(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendKey("status","start"); + cmd.appendValue("status",status); + cmd.appendValue("endtime",endtime); + + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + return true; + }catch (Exception e){ + + } + return false; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EarthInductorEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EarthInductorEventEntity.java new file mode 100644 index 0000000..dcf1dba --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EarthInductorEventEntity.java @@ -0,0 +1,74 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class EarthInductorEventEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + protected String deviceid; + @JPos(index = 1,filter = true) + private String owner; + @JPos(index = 2,timekey = true,primary = true,orderkey = true,update = false) + protected long timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + @JPos(index = 4,filter = true) + private String event;//idle,occupy , lowpower, broken, heartbeat-idle, heartbeat-occupy + @JPos(index = 5) + private Date changetime; + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setChangetime(Date changetime) { + this.changetime = changetime; + } + + public Date getChangetime() { + return changetime; + } + + public String tableName( ){ + return "iotserver_earth_inductor_sensor_event_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EventImageEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EventImageEntity.java new file mode 100644 index 0000000..a0a21c5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/EventImageEntity.java @@ -0,0 +1,51 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class EventImageEntity extends SQLDataObject { + + @JPos(index=0,primary = true,filter = true) + private String imageId; + @JPos(index=1,strlen = 2048000) + private String imageData; + @JPos(index=2, filter = true) + private String eventId; + + + public String tableName( ){ + return "iotserver_event_image_table"; + } + + public EventImageEntity(){ + + } + + public EventImageEntity(String imageid){ + imageId = imageid; + } + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getImageId() { + return imageId; + } + + public void setImageId(String imageId) { + this.imageId = imageId; + } + + public String getImageData() { + return imageData; + } + + public void setImageData(String imageData) { + this.imageData = imageData; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/GasSensorEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/GasSensorEventEntity.java new file mode 100644 index 0000000..22671ed --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/GasSensorEventEntity.java @@ -0,0 +1,371 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import java.util.Date; + +public class GasSensorEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String owner; + @JPos(index = 2,primary = true,timekey = true,orderkey = true,update = false) + protected Date timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + + @JPos(index = 4, filter = true) + private String event;//heartbeat | alarm; + @JPos(index = 5,filter = true) + private String alarmtype; + @JPos(index = 6, filter = true) + private String status; + @JPos(index = 7,threshold = -1) + private int power; + @JPos(index = 8,floatthreshold = -273.0f) + private double temperature; + @JPos(index = 9,threshold = -1) + private double humidity; + @JPos(index = 10,floatthreshold = -1.0f) + private double tvoc; + @JPos(index = 11,floatthreshold = -1.0f) + private double ch2o;//formaldehyde; + @JPos(index = 12,floatthreshold = -1.0f) + private double co; + @JPos(index = 13,floatthreshold = -1.0f) + private double co2; + @JPos(index = 14,floatthreshold = -1.0f) + private double oxygen; + @JPos(index = 15,floatthreshold = -1.0f) + private double ammonia; + @JPos(index = 16,floatthreshold = -1.0f) + private double hepatic;//h2s + @JPos(index = 17,floatthreshold = -1.0f) + private double chlorine; + @JPos(index = 18,floatthreshold = -1.0f) + private double ex; + @JPos(index = 19,floatthreshold = -1.0f) + private double pm2d5; + @JPos(index = 20,floatthreshold = -1.0f) + private double pm10; + @JPos(index = 21,threshold = -1) + private int radiosignal; + @JPos(index = 22,floatthreshold = -1.0f) + private double oxygen3; + @JPos(index = 23,threshold = -1) + private int ch4; + @JPos(index = 24,floatthreshold = -1.0f) + private double oilfume; + @JPos(index = 24,floatthreshold = -1.0f) + private double arg0; + @JPos(index = 25, filter = true) + private String arg0name; + @JPos(index = 26,floatthreshold = -1.0f) + private double arg1; + @JPos(index = 27, filter = true) + private String arg1name; + @JPos(index = 28,floatthreshold = -1.0f) + private double arg2; + @JPos(index = 29, filter = true) + private String arg2name; + @JPos(index = 30,floatthreshold = -1.0f) + private double pm1d0; + + public GasSensorEventEntity(){ + deviceid = ""; + owner = ""; + timestamp = new Date(); + devicetype = ""; + event = ""; + alarmtype = ""; + status = ""; + power = 0; + temperature= 0; + humidity= 0; + tvoc= 0; + ch2o= 0;//formaldehyde; + co= 0; + co2= 0; + oxygen= 0; + ammonia= 0; + hepatic= 0;//h2s + chlorine= 0; + ex= 0; + pm2d5= 0; + pm10= 0; + radiosignal= 0; + oxygen3= 0; + ch4= 0; + oilfume = 0; + arg0= 0; + arg0name = ""; + arg1= 0; + arg1name = ""; + arg2= 0; + arg2name = ""; + pm1d0= 0; + + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setTemperature(double temperature) { + this.temperature = temperature; + } + + public double getTemperature() { + return temperature; + } + + public void setHumidity(double humidity) { + this.humidity = humidity; + } + + public double getHumidity() { + return humidity; + } + + public void setTvoc(double tvoc) { + this.tvoc = tvoc; + } + + public double getTvoc() { + return tvoc; + } + + public void setCh2o(double ch2o) { + this.ch2o = ch2o; + } + + public double getCh2o() { + return ch2o; + } + + public void setCo(double co) { + this.co = co; + } + + public double getCo() { + return co; + } + + public void setCo2(double co2) { + this.co2 = co2; + } + + public double getCo2() { + return co2; + } + + public void setOxygen(double oxygen) { + this.oxygen = oxygen; + } + + public double getOxygen() { + return oxygen; + } + + public void setAmmonia(double ammonia) { + this.ammonia = ammonia; + } + + public double getAmmonia() { + return ammonia; + } + + public void setHepatic(double hepatic) { + this.hepatic = hepatic; + } + + public double getHepatic() { + return hepatic; + } + + public void setChlorine(double chlorine) { + this.chlorine = chlorine; + } + + public double getChlorine() { + return chlorine; + } + + public void setEx(double ex) { + this.ex = ex; + } + + public double getEx() { + return ex; + } + + public void setPm2d5(double pm2d5) { + this.pm2d5 = pm2d5; + } + + public double getPm2d5() { + return pm2d5; + } + + public void setPm10(double pm10) { + this.pm10 = pm10; + } + + public double getPm10() { + return pm10; + } + + public void setRadiosignal(int radiosignal) { + this.radiosignal = radiosignal; + } + + public int getRadiosignal() { + return radiosignal; + } + + public void setOxygen3(double oxygen3) { + this.oxygen3 = oxygen3; + } + + public double getOxygen3() { + return oxygen3; + } + + public void setCh4(int ch4) { + this.ch4 = ch4; + } + + public int getCh4() { + return ch4; + } + + public void setOilfume(double oilfume) { + this.oilfume = oilfume; + } + + public double getOilfume() { + return oilfume; + } + + public void setArg0(double arg0) { + this.arg0 = arg0; + } + + public double getArg0() { + return arg0; + } + + public void setArg0name(String arg0name) { + this.arg0name = arg0name; + } + + public String getArg0name() { + return arg0name; + } + + public void setArg1(double arg1) { + this.arg1 = arg1; + } + + public double getArg1() { + return arg1; + } + + public void setArg1name(String arg1name) { + this.arg1name = arg1name; + } + + public String getArg1name() { + return arg1name; + } + + public void setArg2(double arg2) { + this.arg2 = arg2; + } + + public double getArg2() { + return arg2; + } + + public void setArg2name(String arg2name) { + this.arg2name = arg2name; + } + + public String getArg2name() { + return arg2name; + } + + public double getPm1d0() { + return pm1d0; + } + + public void setPm1d0(double pm1d0) { + this.pm1d0 = pm1d0; + } + + public String tableName(){ + return "iotserver_gas_sensor_event_table"; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/LiquidGageAlarmSettingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/LiquidGageAlarmSettingEntity.java new file mode 100644 index 0000000..17639b8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/LiquidGageAlarmSettingEntity.java @@ -0,0 +1,197 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionTaskEntity; +import com.jingyi.iotserver.utils.SQLCreateTableCmd; +import com.jingyi.iotserver.utils.SQLInsertCmd; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SQLUpdateCmd; + +import javax.sql.DataSource; +import java.util.List; + +public class LiquidGageAlarmSettingEntity { + private String deviceid; + private String devicetype; + private double highout;//unit mH2O kPa + private double lowout;//unit mH2O kPa + private double lowpower;//percent + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setHightout(double highout) { + this.highout = highout; + } + + public double getHightout() { + return highout; + } + + public void setLowout(double lowout) { + this.lowout = lowout; + } + + public double getLowpower() { + return lowpower; + } + + public void setLowpower(double lowpower) { + this.lowpower = lowpower; + } + + public double getLowout() { + return lowout; + } + + public static String tableName(){ + return "iotserver_liquid_gage_alarm_setting_table"; + } + public static void createTable(DataSource dataSource){ + + SQLCreateTableCmd cmd = new SQLCreateTableCmd(); + cmd.start(tableName()); + cmd.addShortString("deviceid"); + cmd.addShortString("devicetype"); + cmd.addDouble("hightout"); + cmd.addDouble("lowout"); + cmd.addDouble("lowpower"); + cmd.end(); + try{ + SQLTools.ExecuteSQL(dataSource, cmd.getSql()); + }catch (Exception e){ + + } + } + + public String InsertSql(){ + SQLInsertCmd cmd = new SQLInsertCmd(); + cmd.start(tableName()); + cmd.appenValue("deviceid",deviceid); + cmd.appenValue("devicetype",devicetype); + cmd.appenValue("highout",highout); + cmd.appenValue("lowout",lowout); + cmd.appenValue("lowpower",lowpower); + + cmd.end(); + return cmd.getSql(); + } + + public boolean Insert(DataSource dataSource){ + try{ + if(!SQLTools.ExecuteSQL(dataSource, InsertSql())){ + createTable(dataSource); + if(!SQLTools.ExecuteSQL(dataSource, InsertSql())) + return false; + } + + }catch (Exception e){ + return false; + } + + return true; + } + + public boolean Delete(DataSource dataSource){ + String sql = "DELETE FROM "+tableName()+" WHERE deviceid='"+deviceid+"' "; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + public static LiquidGageAlarmSettingEntity QuerySetting(DataSource dataSource, String deviceid){ + String sql = "select * from "+tableName()+" where deviceid='"+deviceid+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, LiquidGageAlarmSettingEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + public boolean SetOut(DataSource dataSource){ + if(deviceid==null||deviceid.length()<=0) + return false; + if(QuerySetting(dataSource,deviceid)==null){ + return Insert(dataSource); + }else{ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendValue("devicetype",devicetype); + cmd.appendValue("highout",highout); + cmd.appendValue("lowout",lowout); + cmd.appendValue("lowpower",lowpower); + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + return true; + }catch (Exception e){ + + } + return false; + } + } + + public String queryCondition(){ + String condition = null; + + if(deviceid!=null&&!deviceid.equals("null")&&deviceid.length()>0){ + condition = " deviceid='"+deviceid+"'"; + } + + if(devicetype!=null&&!devicetype.equals("null")&&devicetype.length()>0){ + condition = " devicetype='"+devicetype+"'"; + } + + return condition; + } + + public int queryCount(DataSource dataSource){ + String condition = queryCondition(); + String sql = "select count(*) from "+tableName(); + if(condition!=null){ + sql += " where "+condition; + } + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + return count; + }catch (Exception e){ + + } + return 0; + } + + public List queryPage(DataSource dataSource, int pageindex, int pagesize){ + String condition = queryCondition(); + String sql = "select * from "+tableName(); + if(condition!=null){ + sql += " where "+condition; + } + try{ + List list = SQLTools.queryPage(dataSource, LiquidGageAlarmSettingEntity.class,sql,pageindex,pagesize,"deviceid"); + return list; + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/LiquidGageEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/LiquidGageEventEntity.java new file mode 100644 index 0000000..d53fa3d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/LiquidGageEventEntity.java @@ -0,0 +1,145 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class LiquidGageEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + protected String deviceid; + @JPos(index = 1,filter = true) + private String owner; + @JPos(index = 2, primary = true,timekey = true,orderkey = true, update = false) + protected Date timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + @JPos(index = 4, filter = true) + private String event;//heartbeat | alarm; + @JPos(index = 5,filter = true) + private String alarmtype; //out1high | out1low | low power | outrange | out2high | out2low + @JPos(index = 6,floatthreshold = -1.0f) + private double gage; + @JPos(index = 7) + private String unit;//mH2O cmH2O mmH2O mHg cmHg mmHg inchHg + @JPos(index = 8,floatthreshold = -1.0f) + private double vantage;//v + @JPos(index = 9,threshold = -1) + private int power; //percent % + @JPos(index = 10,threshold = -1) + private int radiosignal; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setVantage(double vantage) { + this.vantage = vantage; + } + + public double getVantage() { + return vantage; + } + + public void setGage(double gage) { + this.gage = gage; + } + + public double getGage() { + return gage; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setRadiosignal(int radiosignal) { + this.radiosignal = radiosignal; + } + + public int getRadiosignal() { + return radiosignal; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getUnit() { + return unit; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public String tableName(){ + return "iotserver_liquid_gage_sensor_event_table"; + } + + public double getmH2O(){ + double mH2O = gage; + if(unit==null||unit.equals("mH2O")){ + + }else if(unit.equals("cmH2O")){ + mH2O = gage/100; + }else if(unit.equals("mmH2O")){ + mH2O = gage/1000; + }else if(unit.equals("mHg")){ + mH2O = gage*13.6; + }else if(unit.equals("cmHg")){ + mH2O = gage/100*13.6; + }else if(unit.equals("mmHg")){ + mH2O = gage/1000*13.6; + }else if(unit.equals("inchHg")){ + mH2O = gage*2.54/100*13.6; + } + + return mH2O; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/MuckTruckEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/MuckTruckEventEntity.java new file mode 100644 index 0000000..180346d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/MuckTruckEventEntity.java @@ -0,0 +1,153 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class MuckTruckEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + protected String deviceid; + @JPos(index = 1,filter = true) + private String owner; + @JPos(index = 2, primary = true,timekey = true,orderkey = true, update = false) + protected Date timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + @JPos(index = 4, filter = true) + private String event;//heartbeat | alarm; + @JPos(index = 5) + private String eventname; + @JPos(index = 6) + private String platenumber; + @JPos(index = 7) + private String companyname; + @JPos(index = 8) + private String bidarea; + @JPos(index = 9) + private Date geoindata; + @JPos(index = 10) + private Date geoinfencedata; + @JPos(index = 11) + private String fencetype; + @JPos(index = 12) + private Date geooutfencedata; + @JPos(index = 13,filter = true) + protected String status; //read | unread + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventname(String eventname) { + this.eventname = eventname; + } + + public String getEventname() { + return eventname; + } + + public void setPlatenumber(String platenumber) { + this.platenumber = platenumber; + } + + public String getPlatenumber() { + return platenumber; + } + + public void setCompanyname(String companyname) { + this.companyname = companyname; + } + + public String getCompanyname() { + return companyname; + } + + public void setBidarea(String bidarea) { + this.bidarea = bidarea; + } + + public String getBidarea() { + return bidarea; + } + + public void setGeoindata(Date geoindata) { + this.geoindata = geoindata; + } + + public Date getGeoindata() { + return geoindata; + } + + public void setGeoinfencedata(Date geoinfencedata) { + this.geoinfencedata = geoinfencedata; + } + + public Date getGeoinfencedata() { + return geoinfencedata; + } + + public void setFencetype(String fencetype) { + this.fencetype = fencetype; + } + + public String getFencetype() { + return fencetype; + } + + public void setGeooutfencedata(Date geooutfencedata) { + this.geooutfencedata = geooutfencedata; + } + + public Date getGeooutfencedata() { + return geooutfencedata; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public String tableName( ){ + return "iotserver_sensor_mucktruck_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/PipePressureEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/PipePressureEventEntity.java new file mode 100644 index 0000000..e6523e4 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/PipePressureEventEntity.java @@ -0,0 +1,152 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class PipePressureEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + protected String deviceid; + @JPos(index = 1,filter = true) + private String owner; + @JPos(index = 2, primary = true,timekey = true,orderkey = true, update = false) + protected Date timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + @JPos(index = 4,filter = true) + private String event;//heartbeat | alarm; + @JPos(index = 5,filter = true) + private String alarmtype; //out1high | out1low | lowpower | outrange | out2high | out2low + @JPos(index = 6,floatthreshold = -1.0f) + private double pressure; + @JPos(index = 7) + private String unit;//Pa hPa kPa MPa bar mbar PSI Torr ATM mmHg + @JPos(index = 8,floatthreshold = -1.0f) + private double vantage;//v + @JPos(index = 9,threshold = -1) + private int power; //percent % + @JPos(index = 10,threshold = -1) + private int radiosignal; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setVantage(double vantage) { + this.vantage = vantage; + } + + public double getVantage() { + return vantage; + } + + public void setPressure(double pressure) { + this.pressure = pressure; + } + + public double getPressure() { + return pressure; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getUnit() { + return unit; + } + + public void setPower(int power) { + this.power = power; + } + + + public int getPower() { + return power; + } + + public void setRadiosignal(int radiosignal) { + this.radiosignal = radiosignal; + } + + public int getRadiosignal() { + return radiosignal; + } + + public String tableName(){ + return "iotserver_pipe_pressure_sensor_event_table"; + } + + public double getkPa(){ + double kPa = pressure; + if(unit==null||unit.equals("kPa")){ + + }else if(unit.equals("Pa")){ + kPa = pressure/1000; + }else if(unit.equals("MPa")||unit.equals("mPa")){ + kPa = pressure*1000; + }else if(unit.equals("mbar")){ + kPa = pressure/1000*101.3; + }else if(unit.equals("bar")){ + kPa = pressure*101.3; + }else if(unit.equals("mmHg")){ + kPa = pressure/7600*101300/1000; + }else if(unit.equals("Torr")){ + kPa = pressure*133.32/1000; + }else if(unit.equals("ATM")){ + kPa = pressure*101.3; + }else if(unit.equals("PSI")){ + kPa = pressure*6.895; + }else if(unit.equals("hPa")){ + kPa = pressure*0.1; + } + + return kPa; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/PushButtonEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/PushButtonEventEntity.java new file mode 100644 index 0000000..316b268 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/PushButtonEventEntity.java @@ -0,0 +1,97 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class PushButtonEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String owner; + @JPos(index = 2,primary = true,timekey = true,orderkey = true,update = false) + protected Date timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + + @JPos(index = 4,filter = true) + private String alarmstate; + + @JPos(index = 5,filter = true) + private String readstate; // unread | isread + + @JPos(index = 6,filter = true) + private String operator; + + @JPos(index = 7,timekey = true,orderkey = true) + protected Date readtime; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setAlarmstate(String alarmstate) { + this.alarmstate = alarmstate; + } + + public String getAlarmstate() { + return alarmstate; + } + + public void setReadstate(String readstate) { + this.readstate = readstate; + } + + public String getReadstate() { + return readstate; + } + + public String tableName(){ + return "iotserver_pushbutton_sensor_event_table"; + } + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public void setReadtime(Date readtime) { + this.readtime = readtime; + } + + public Date getReadtime() { + return readtime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/STVAlarmEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/STVAlarmEventEntity.java new file mode 100644 index 0000000..2b91091 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/STVAlarmEventEntity.java @@ -0,0 +1,316 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class STVAlarmEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String devicetype; + @JPos(index = 2, filter = true) + private String owner; + @JPos(index = 3, primary = true,timekey = true,orderkey = true) + protected Date timestamp; + + @JPos(index = 4, filter = true) + private String id; // alarm id + @JPos(index = 5) + private String source;// source address--vbox id + @JPos(index = 6) + private int type; // 1:system; 2:device; 128:device-ex + + @JPos(index = 7) + private int systemtype; + @JPos(index = 8) + private int systemaddress; + @JPos(index = 9) + private int lineaddress; + @JPos(index = 10) + private int deviceaddress; + @JPos(index = 11) + private String description; + @JPos(index = 12) + private int mode; + @JPos(index = 13) + private int alarm; + @JPos(index = 14) + private int breakdown; + @JPos(index = 15) + private int block; + @JPos(index = 16) + private int supervise; + @JPos(index = 17) + private int status; + @JPos(index = 18) + private int response; + @JPos(index = 19) + private int delay; + @JPos(index = 20) + private int masterpowerbreak; + @JPos(index = 21) + private int standbypowerbreak; + @JPos(index = 22) + private int busbreak; + @JPos(index = 23) + private int auto; + @JPos(index = 24) + private int configchanged; + @JPos(index = 25) + private int reset; + @JPos(index = 26) + private int devtype; + @JPos(index = 27) + private String alarmstate; + @JPos(index = 28) + private String reporttime; + @JPos(index = 29) + private String acktime; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setSource(String source) { + this.source = source; + } + + public String getSource() { + return source; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public void setSystemtype(int systemtype) { + this.systemtype = systemtype; + } + + public int getSystemtype() { + return systemtype; + } + + public void setSystemaddress(int systemaddress) { + this.systemaddress = systemaddress; + } + + public int getSystemaddress() { + return systemaddress; + } + + public void setLineaddress(int lineaddress) { + this.lineaddress = lineaddress; + } + + public int getLineaddress() { + return lineaddress; + } + + public void setDeviceaddress(int deviceaddress) { + this.deviceaddress = deviceaddress; + } + + public int getDeviceaddress() { + return deviceaddress; + } + + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setMode(int mode) { + this.mode = mode; + } + + public int getMode() { + return mode; + } + + public void setAlarm(int alarm) { + this.alarm = alarm; + } + + public int getAlarm() { + return alarm; + } + + public void setBreakdown(int breakdown) { + this.breakdown = breakdown; + } + + public int getBreakdown() { + return breakdown; + } + + public void setBlock(int block) { + this.block = block; + } + + public int getBlock() { + return block; + } + + public void setSupervise(int supervise) { + this.supervise = supervise; + } + + public int getSupervise() { + return supervise; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getStatus() { + return status; + } + + public void setResponse(int response) { + this.response = response; + } + + public int getResponse() { + return response; + } + + public void setDelay(int delay) { + this.delay = delay; + } + + public int getDelay() { + return delay; + } + + public void setMasterpowerbreak(int masterpowerbreak) { + this.masterpowerbreak = masterpowerbreak; + } + + public int getMasterpowerbreak() { + return masterpowerbreak; + } + + public void setStandbypowerbreak(int standbypowerbreak) { + this.standbypowerbreak = standbypowerbreak; + } + + public int getStandbypowerbreak() { + return standbypowerbreak; + } + + public void setBusbreak(int busbreak) { + this.busbreak = busbreak; + } + + public int getBusbreak() { + return busbreak; + } + + public void setAuto(int auto) { + this.auto = auto; + } + + public int getAuto() { + return auto; + } + + public void setConfigchanged(int configchanged) { + this.configchanged = configchanged; + } + + public int getConfigchanged() { + return configchanged; + } + + public void setReset(int reset) { + this.reset = reset; + } + + public int getReset() { + return reset; + } + + public void setAlarmstate(String alarmstate) { + this.alarmstate = alarmstate; + } + + public String getAlarmstate() { + return alarmstate; + } + + public void setReporttime(String reporttime) { + this.reporttime = reporttime; + } + + public String getReporttime() { + return reporttime; + } + + public void setAcktime(String acktime) { + this.acktime = acktime; + } + + public String getAcktime() { + return acktime; + } + + public void setDevtype(int devtype) { + this.devtype = devtype; + } + + public int getDevtype() { + return devtype; + } + + public String tableName( ){ + return "iotserver_sensor_alarm_host_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorAlarmBuzInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorAlarmBuzInfoEntity.java new file mode 100644 index 0000000..835d284 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorAlarmBuzInfoEntity.java @@ -0,0 +1,185 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionTaskEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SensorAlarmBuzInfoEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private int alarmid; + @JPos(index = 1, filter = true) + private String owner; + @JPos(index = 2, primary = true,filter = true) + private String deviceid; + @JPos(index = 3,filter = true) + private String devicetype; + + @JPos(index = 4, filter = true) + private String status; //start | stop + + @JPos(index = 5, filter = true) + private String alarmtype; + @JPos(index = 6) + private String alarminfo; + @JPos(index = 7) + private String cause; + @JPos(index = 8) + private String process; + + @JPos(index = 9, timekey = true,orderkey = true,update = false) + private Date starttime; + @JPos(index = 10) + private Date stoptime; + @JPos(index = 11) + private Date processtime; + + public void setAlarmid(int alarmid) { + this.alarmid = alarmid; + } + + public int getAlarmid() { + return alarmid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setAlarminfo(String alarminfo) { + this.alarminfo = alarminfo; + } + + public String getAlarminfo() { + return alarminfo; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setStoptime(Date stoptime) { + this.stoptime = stoptime; + } + + public Date getStoptime() { + return stoptime; + } + + public Date getProcesstime() { + return processtime; + } + + public void setProcesstime(Date processtime) { + this.processtime = processtime; + } + + public void setCause(String cause) { + this.cause = cause; + } + + public String getCause() { + return cause; + } + + public void setProcess(String process) { + this.process = process; + } + + public String getProcess() { + return process; + } + + public String tableName(){ + return "iotserver_gas_sensor_event_table"; + } + + public static SensorAlarmBuzInfoEntity QueryActiveAlarm(DataSource dataSource, String deviceid){ + SensorAlarmBuzInfoEntity info = new SensorAlarmBuzInfoEntity(); + String sql = "select * from "+info.tableName()+" where status='start' and deviceid='"+deviceid+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, SensorAlarmBuzInfoEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + + + public boolean Delete(DataSource dataSource){ + String sql = "DELETE FROM "+tableName()+" WHERE timestamp='"+SQLTools.formatDate(starttime)+"' AND deviceid='"+deviceid+"'"; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + public boolean Stop(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendKey("alarmid",alarmid); + status = "stop"; + stoptime = new Date(); + cmd.appendValue("status",status); + cmd.appendValue("stoptime",stoptime); + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + return true; + }catch (Exception e){ + + } + return false; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorDeviceEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorDeviceEntity.java new file mode 100644 index 0000000..b0af325 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorDeviceEntity.java @@ -0,0 +1,308 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SensorDeviceEntity extends SQLDataObject{ + @JPos(index=0,identify = true,orderkey = true) + private int id; + @JPos(index=1,filter = true) + private String devicetype; + @JPos(index=2,primary = true,filter = true) + private String deviceid; + @JPos(index=3,filter = true) + private String owner; + @JPos(index=4,filter = true) + private String houseowner; + @JPos(index=5,filter = true) + private String status;//unknown,normal, alarm,broken + //烟感报警,服务端数据存储的变更流程 + // unknown ,idle,occupy, + @JPos(index=6,threshold = -1) + private int power; //0~100 <10 low power + @JPos(index=7) + private Date activetime; + @JPos(index=8,floatthreshold = -1.0f) + private double longitude; + @JPos(index=9,floatthreshold = -1.0f) + private double latitude; + @JPos(index=10) + private String address; + @JPos(index=11,filter = true) + private String producer; + @JPos(index=12,filter = true) + private String model; + @JPos(index=13,filter = true) + private String enableuse;//use ,close + @JPos(index=14,filter = true) + private String brigade; + @JPos(index=15,filter = true) + private String borough; + @JPos(index=16,filter = true) + private String detachment; + @JPos(index=17) + private String alarm;//open,close + @JPos(index=18,filter = true) + private String qrcode; + + @JPos(index=19,filter = true) + private String buildingName; + @JPos(index=20,filter = true) + private String floorName; + @JPos(index=21,filter = true) + private String roomName; + @JPos(index=22,filter = true) + private String deviceName; + @JPos(index=23,filter = true) + private String lineState; + @JPos(index=24,filter = true) + private String iotSystemId; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setHouseowner(String houseowner) { + this.houseowner = houseowner; + } + + public String getHouseowner() { + return houseowner; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setActivetime(Date activetime) { + this.activetime = activetime; + } + + public Date getActivetime() { + return activetime; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setProducer(String producer) { + this.producer = producer; + } + + public String getProducer() { + return producer; + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setEnableuse(String enableuse) { + this.enableuse = enableuse; + } + + public String getEnableuse() { + return enableuse; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setAlarm(String alarm) { + this.alarm = alarm; + } + + public String getAlarm(){ + return alarm; + } + + public String tableName(){ + return "iotserver_sensor_info_table"; + } + + + public String getBuildingName() { + return buildingName; + } + + public void setBuildingName(String buildingName) { + this.buildingName = buildingName; + } + + public String getFloorName() { + return floorName; + } + + public void setFloorName(String floorName) { + this.floorName = floorName; + } + + public String getRoomName() { + return roomName; + } + + public void setRoomName(String roomName) { + this.roomName = roomName; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public static SensorDeviceEntity Query(DataSource dataSource, String devid) { + SensorDeviceEntity sensor = new SensorDeviceEntity(); + String sql = "select * from " + sensor.tableName() + " where deviceid='" + devid + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SensorDeviceEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static SensorDeviceEntity QueryQrcode(DataSource dataSource, String qrccode) { + SensorDeviceEntity sensor = new SensorDeviceEntity(); + String sql = "select * from " + sensor.tableName() + " where qrcode='" + qrccode + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SensorDeviceEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static List QueryByOwner(DataSource dataSource,String owner) { + SensorDeviceEntity sensor = new SensorDeviceEntity(); + String sql = "select * from " +sensor.tableName() + " where owner='" + owner + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SensorDeviceEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public String getQrcode() { + return qrcode; + } + + public void setQrcode(String qrcode) { + this.qrcode = qrcode; + } + + public String getLineState() { + return lineState; + } + + public void setLineState(String lineState) { + this.lineState = lineState; + } + + public String getIotSystemId() { + return iotSystemId; + } + + public void setIotSystemId(String iotSystemId) { + this.iotSystemId = iotSystemId; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorLinkStateEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorLinkStateEntity.java new file mode 100644 index 0000000..fd19d5f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorLinkStateEntity.java @@ -0,0 +1,166 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; + +import java.util.List; + +public class SensorLinkStateEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String deviceid; + @JPos(index=1,filter = true) + private String devicetype; + @JPos(index=2,filter = true) + private String state;//online | offline + @JPos(index = 3,timekey = true,orderkey = true) + protected long timestamp; + @JPos(index=4,filter = true) + private String brigade; + @JPos(index=5,filter = true) + private String borough; + @JPos(index=6,filter = true) + private String detachment; + @JPos(index=7,filter = true) + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName( ){ + return "iotserver_sensor_link_state_table"; + } + + static public List queryActiveSensorBefore(DataSource dataSource, String type, long before ){ + SensorLinkStateEntity sensor = new SensorLinkStateEntity(); + sensor.setDevicetype(type); + sensor.setState("online"); + String condition = sensor.queryCondition(); + String sql = "select * from "+sensor.tableName(); + if (condition == null) { + condition = " timestamp<=" + (System.currentTimeMillis()-before) ; + } else + condition += " and timestamp<=" + (System.currentTimeMillis()-before) ; + if(condition!=null){ + sql += " where "+condition; + } + + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, SensorLinkStateEntity.class); + return list; + }catch (Exception e){ + + } + return null; + } + + static public int queryActiveSensorCountBefore(DataSource dataSource, String type, long before ){ + SensorLinkStateEntity sensor = new SensorLinkStateEntity(); + sensor.setDevicetype(type); + sensor.setState("online"); + String condition = sensor.queryCondition(); + String sql = "select count(*) from "+sensor.tableName(); + if (condition == null) { + condition = " timestamp<=" + (System.currentTimeMillis()-before) ; + } else + condition += " and timestamp<=" + (System.currentTimeMillis()-before) ; + if(condition!=null){ + sql += " where "+condition; + } + + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + return count; + + }catch (Exception e){ + + } + return 0; + } + + static public List queryActiveSensorPageBefore(DataSource dataSource, String type, long before ,int pageindex,int pagesize){ + SensorLinkStateEntity sensor = new SensorLinkStateEntity(); + sensor.setDevicetype(type); + sensor.setState("online"); + String condition = sensor.queryCondition(); + String sql = "select * from "+sensor.tableName(); + if (condition == null) { + condition = " timestamp<=" + (System.currentTimeMillis()-before) ; + } else + condition += " and timestamp<=" + (System.currentTimeMillis()-before) ; + if(condition!=null){ + sql += " where "+condition; + } + + try{ + List list = SQLTools.queryPage(dataSource, SensorLinkStateEntity.class,sql,pageindex,pagesize,"deviceid"); + return list; + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorSubDeviceEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorSubDeviceEntity.java new file mode 100644 index 0000000..ca75c75 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorSubDeviceEntity.java @@ -0,0 +1,131 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class SensorSubDeviceEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index=1,filter = true) + private String devicetype; + + @JPos(index = 2, filter = true) + private String subtype; + + @JPos(index = 3, primary = true,filter = true) + private String position; + + @JPos(index=4) + private String description; + + @JPos(index=5) + private String address; + + @JPos(index=6,filter = true) + private String station; + + @JPos(index=7) + private String mapid; + + @JPos(index=8) + private double posx; + + @JPos(index=9) + private double posy; + + @JPos(index=10) + private double posz; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setSubtype(String subtype) { + this.subtype = subtype; + } + + public String getSubtype() { + return subtype; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getPosition() { + return position; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setMapid(String mapid) { + this.mapid = mapid; + } + + public String getMapid() { + return mapid; + } + + public void setPosx(double posx) { + this.posx = posx; + } + + public double getPosx() { + return posx; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setPosy(double posy) { + this.posy = posy; + } + + public double getPosy() { + return posy; + } + + public void setPosz(double posz) { + this.posz = posz; + } + + public double getPosz() { + return posz; + } + + public String tableName(){ + return "iotserver_sensor_subdev_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorTypeResult.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorTypeResult.java new file mode 100644 index 0000000..d680a28 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SensorTypeResult.java @@ -0,0 +1,13 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +public class SensorTypeResult { + private String type; + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SkynetIPCEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SkynetIPCEntity.java new file mode 100644 index 0000000..eac7d02 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SkynetIPCEntity.java @@ -0,0 +1,258 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.List; + +public class SkynetIPCEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String pointCode; + @JPos(index = 1,filter = true) + private String name; + @JPos(index = 2,filter = true) + private String brigade; + @JPos(index = 3,filter = true) + private String detachment; + @JPos(index = 4,filter = true) + private String borough; + @JPos(index=5,filter = true) + private String station; + @JPos(index=6,filter = true) + private String projectName; + @JPos(index=7) + private int highPoint; + @JPos(index=8,filter = true) + private String deviceType; + @JPos(index=9) + private int aiFace; + @JPos(index=10) + private int aiVehicle; + @JPos(index=11) + private String comment; + @JPos(index=12) + private String videoChannel; + @JPos(index=13,floatthreshold = -1.0f) + private double longitude; + @JPos(index=14,floatthreshold = -1.0f) + private double latitude; + @JPos(index = 15,filter = true) + private String cameraIndexCode; + @JPos(index = 16) + private String platformType; + @JPos(index = 17) + private String zoneIndex; + + + public String tableName(){ + return "skynet_ipc_info_table"; + } + public String getPointCode() { + return pointCode; + } + + public void setPointCode(String pointCode) { + this.pointCode = pointCode; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public int getHighPoint() { + return highPoint; + } + + public void setHighPoint(int highPoint) { + this.highPoint = highPoint; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public int getAiFace() { + return aiFace; + } + + public void setAiFace(int aiFace) { + this.aiFace = aiFace; + } + + public int getAiVehicle() { + return aiVehicle; + } + + public void setAiVehicle(int aiVehicle) { + this.aiVehicle = aiVehicle; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getVideoChannel() { + return videoChannel; + } + + public void setVideoChannel(String videoChannel) { + this.videoChannel = videoChannel; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getPlatformType() { + return platformType; + } + + public void setPlatformType(String platformType) { + this.platformType = platformType; + } + + public String getZoneIndex() { + return zoneIndex; + } + + public void setZoneIndex(String zoneIndex) { + this.zoneIndex = zoneIndex; + } + + public static SkynetIPCEntity Query(DataSource dataSource, String devid) { + SkynetIPCEntity sensor = new SkynetIPCEntity(); + String sql = "select * from " + sensor.tableName() + " where pointCode='" + devid + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SkynetIPCEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + + public static SkynetIPCEntity QueryWithCameraCode(DataSource dataSource, String cameraCode) { + SkynetIPCEntity sensor = new SkynetIPCEntity(); + String sql = "select * from " + sensor.tableName() + " where cameraIndexCode='" + cameraCode + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SkynetIPCEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static SkynetIPCEntity QueryWithCameraName(DataSource dataSource, String cameraName) { + SkynetIPCEntity sensor = new SkynetIPCEntity(); + String sql = "select * from " + sensor.tableName() + " where name='" + cameraName + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SkynetIPCEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static List searchPosition(DataSource dataSource, double lat, double lon, double dRange) { + double latTop = lat + dRange; + double latBottom = lat - dRange; + double lonRight = lon + dRange; + double lonLeft = lon - dRange; + SkynetIPCEntity info = new SkynetIPCEntity(); + String sql = "select * from " + info.tableName() + " where longitude>="+lonLeft+" and longitude<="+lonRight+" and latitude>="+latBottom+" and latitude<="+latTop; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SkynetIPCEntity.class); + if (list != null && list.size() > 0) { + return list; + } + } catch (Exception e) { + + } + return null; + } + + + public String getCameraIndexCode() { + return cameraIndexCode; + } + + public void setCameraIndexCode(String cameraIndexCode) { + this.cameraIndexCode = cameraIndexCode; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SmokingBuzEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SmokingBuzEventEntity.java new file mode 100644 index 0000000..8813679 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SmokingBuzEventEntity.java @@ -0,0 +1,235 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SmokingBuzEventEntity extends SQLDataObject { + @JPos(index = 0,identify = true) + private int eventid; + @JPos(index = 1, primary = true,filter = true) + private String deviceid; + @JPos(index = 2,filter = true) + protected String devicetype; + @JPos(index = 3,filter = true) + private String owner; + @JPos(index = 4,filter = true) + private String buztype; + @JPos(index = 5, primary = true,timekey = true,orderkey = true,update = false) + private Date starttime; + @JPos(index = 6) + private Date endtime; + @JPos(index = 7,filter = true) + private String status; //start / stop + + @JPos(index = 8) + private Date ownerrcvtime; + @JPos(index = 9) + private Date ownerprocesstime; + @JPos(index = 10) + private Date ownerstoptime; + @JPos(index = 11,filter = true) + private String validity;//valid invalid + @JPos(index = 12) + private String cause; + @JPos(index = 13,filter = true) + private String brigade; + @JPos(index = 14,filter = true) + private String borough; + @JPos(index = 15,filter = true) + private String detachment; + + + public void setEventid(int eventid) { + this.eventid = eventid; + } + + public int getEventid() { + return eventid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setBuztype(String buztype) { + this.buztype = buztype; + } + + public String getBuztype() { + return buztype; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + public Date getEndtime() { + return endtime; + } + + public void setOwnerrcvtime(Date ownerrcvtime) { + this.ownerrcvtime = ownerrcvtime; + } + + public Date getOwnerrcvtime() { + return ownerrcvtime; + } + + public void setOwnerprocesstime(Date ownerprocesstime) { + this.ownerprocesstime = ownerprocesstime; + } + + public Date getOwnerprocesstime() { + return ownerprocesstime; + } + + public void setOwnerstoptime(Date ownerstoptime) { + this.ownerstoptime = ownerstoptime; + } + + public Date getOwnerstoptime() { + return ownerstoptime; + } + + public void setValidity(String validity) { + this.validity = validity; + } + + public String getValidity() { + return validity; + } + + public void setCause(String cause) { + this.cause = cause; + } + + public String getCause() { + return cause; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public String tableName( ){ + return "iotserver_smoking_sensor_buz_event_table"; + } + + + public boolean Delete(DataSource dataSource){ + String sql = "DELETE FROM "+tableName()+" WHERE eventid="+eventid; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + public static SmokingBuzEventEntity Query(DataSource dataSource, int eventid) { + SmokingBuzEventEntity event = new SmokingBuzEventEntity(); + String sql = "select * from " + event.tableName() + " where eventid=" + eventid ; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SmokingBuzEventEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + + public static SmokingBuzEventEntity Query(DataSource dataSource, String devid,String status) { + SmokingBuzEventEntity event = new SmokingBuzEventEntity(); + String sql = "select * from " + event.tableName() + " where deviceid='" + devid + "' and status='"+status+"'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, SmokingBuzEventEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public boolean Stop(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendKey("status","start"); + cmd.appendValue("status","stop"); + cmd.appendValue("endtime",new Date()); + status = "stop"; + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + return true; + }catch (Exception e){ + + } + return false; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SmokingEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SmokingEventEntity.java new file mode 100644 index 0000000..0ba6bdc --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/SmokingEventEntity.java @@ -0,0 +1,66 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SmokingEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + protected String deviceid; + @JPos(index = 1,filter = true) + private String owner; + @JPos(index = 2,timekey = true,primary = true,orderkey = true,update = false) + protected long timestamp; + @JPos(index = 3,filter = true) + protected String devicetype; + @JPos(index = 4,filter = true) + private String event;//alarm , lowpower, broken, heartbeat + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public String tableName( ){ + return "iotserver_smoking_sensor_event_table"; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/UAVTaskEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/UAVTaskEntity.java new file mode 100644 index 0000000..3b749b5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/UAVTaskEntity.java @@ -0,0 +1,200 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + + +/* +{"code":0, +"message":"OK", +"data": + {"list":[ + { + "index":"0c415617163b223c71f63327890224fe229f39a62a72259bb3b8c6cb2769bb9a", + "host": + { + "device_sn":"1ZNBK7L00C00PF", + "device_model": + {"key":"0-60-0", + "domain":"0", + "type":"60", + "sub_type":"0", + "name":"M300 RTK", + "class":"drone", + "develop_code":"pm430" + }, + "device_online_status":true, + "is_device_pending_offline":false, + "device_offline_position":null, + "device_project_callsign":"M300 RTK", + "is_organization_device":true, + "device_organization_callsign":"M300 RTK", + "device_control_user_id":"", + "device_control_user_project_callsign":"", + "device_control_user_organization_callsign":"", + "device_state": + { + "--0": + {"gimbal_pitch":0, + "gimbal_roll":0, + "gimbal_yaw":115.8, + "payload_index":"--0", + "version":1, + "zoom_factor":0.828076 + }, + "50-65535-0": + {"gimbal_pitch":0, + "gimbal_roll":0, + "gimbal_yaw":-84.8, + "payload_index":"50-65535-0", + "version":1, + "zoom_factor":0.828076 + }, + "H20-0": {"firmware_version":"04.00.02.05"}, + "attitude_head":-101.30000000000001, + "attitude_pitch":-1.4000000000000001, + "attitude_roll":-3.9000000000000004, + "battery": + {"batteries": + [ + {"capacity_percent":79, + "firmware_version":"01.02.05.44", + "index":0, + "loop_times":27, + "sn":"1Z6PKBWFA500FZ", + "sub_type":0, + "temperature":33.1, + "type":0, + "voltage":48360 + }, + {"capacity_percent":79, + "firmware_version":"01.02.05.44", + "index":1, + "loop_times":27, + "sn":"1Z6PKBWFA5002Q", + "sub_type":0, + "temperature":31.4, + "type":0, + "voltage":48384 + } + ], + "capacity_percent":78, + "landing_power":7, + "remain_flight_time":2265, + "return_home_power":15 + }, + "control_source":"A", + "distance_limit_status": {"distance_limit":5000, "state":1}, + "elevation":109.30000000000001, + "firmware_version":"04.00.0111", + "gear":1, + "height":136.41298179626466, + "height_limit":120, + "home_distance":531.69091796875, + "home_latitude":31.108486188395766, + "home_longitude":121.6356106946701, + "horizontal_speed":0, + "latitude":31.106687513603536, + "longitude":121.64078105117886, + "low_battery_warning_threshold":25, + "mode_code":3, + "payloads":[], + "position_state": + {"gps_number":19, + "is_fixed":0, + "quality":5, + "rtk_number":42}, + "serious_low_battery_warning_threshold":16, + "storage":{"total":0,"used":0}, + "total_flight_distance":0, + "total_flight_time":0, + "track_id":"", + "vertical_speed":0, + "wind_direction":6, + "wind_speed":39 + }, + "device_index":"" + }, + "parents":[ + { + "device_sn":"1ZMBJA7003010J", + "device_model":{"key":"2-56-0","domain":"2","type":"56","sub_type":"0","name":"DJI RC","class":"rc","develop_code":"rm500"}, + "device_online_status":true, + "is_device_pending_offline":false, + "device_offline_position":null, + "device_project_callsign":"DJI RC", + "is_organization_device":false, + "device_organization_callsign":"", + "device_control_user_id":"905420920893353984", + "device_control_user_project_callsign":"17601320378", + "device_control_user_organization_callsign":"17601320378", + "device_state": + { + "capacity_percent":27, + "firmware_version":"06.01.0100", + "latitude":31.108551826483826, + "live_capacity": + { + "available_video_number":1, + "coexist_video_number_max":1, + "device_list": + [ + { + "available_video_number":1, + "camera_list": + [ + { + "available_video_number":1, + "camera_index":"39-0-7", + "coexist_video_number_max":1, + "video_list": + [ + { + "video_index":"normal-0", + "video_type":"normal" + } + ] + } + ], + "coexist_video_number_max":1, + "sn":"1ZNBK7L00C00PF" + } + ] + }, + "live_status": + { + "live_time":0, + "live_trendline":0, + "video_id":"", + "video_quality":65535 + }, + "longitude":121.63549762729829, + "transmission_signal_quality":60, + "wireless_link": + { + "4g_freq_band":5.8, + "4g_gnd_quality":65535, + "4g_link_state":0, + "4g_quality":65535, + "4g_uav_quality":65535, + "dongle_number":0, + "link_workmode":1, + "sdr_freq_band":5.8, + "sdr_link_state":0, + "sdr_quality":65535 + }, + "wireless_link_state":{"download_quality":60,"frequency_band":1,"upward_quality":60} + }, + "device_index":"A" + } + ] + } + ]--list + }--data + } --root + + */ + +public class UAVTaskEntity { + + private String device_sn; + private boolean device_online_status; + private String device_project_callsign; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WateMeterHourCountEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WateMeterHourCountEntity.java new file mode 100644 index 0000000..9e5eb8b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WateMeterHourCountEntity.java @@ -0,0 +1,136 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class WateMeterHourCountEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String devicetype; + @JPos(index = 2, filter = true) + private String owner; + @JPos(index = 3, primary = true) + private int year; + @JPos(index = 4, primary = true) + private int month; + @JPos(index = 5, primary = true) + private int day; + @JPos(index = 6, primary = true,orderkey = true) + private int hour; + + @JPos(index = 7) + private float hourcount; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setYear(int year) { + this.year = year; + } + + public int getYear() { + return year; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getMonth() { + return month; + } + + public void setDay(int day) { + this.day = day; + } + + public int getDay() { + return day; + } + + public void setHour(int hour) { + this.hour = hour; + } + + public int getHour() { + return hour; + } + + public void setHourcount(float hourcount) { + this.hourcount = hourcount; + } + + public float getHourcount() { + return hourcount; + } + + public String tableName( ){ + return "iotserver_sensor_water_meter_hour_count_table"; + } + + public List queryCounts(DataSource dataSource){ + String con = null; + + if(deviceid!=null){ + if(con==null) + con = " where deviceid='"+deviceid+"'"; + else + con += " and deviceid='"+deviceid+"'"; + } + + if(devicetype!=null){ + if(con==null) + con = " where devicetype='"+devicetype+"'"; + else + con += " and devicetype='"+devicetype+"'"; + } + + if(owner!=null){ + if(con==null) + con = " where owner='"+owner+"'"; + else + con += " and owner='"+owner+"'"; + } + + if(con==null) + con = " where year="+year + "and month="+month+ " and day="+day; + else + con += " and year="+year + " and month="+month+ " and day="+day; + String sql = "select * from " +tableName() + con; + + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, WateMeterHourCountEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterCheckDataEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterCheckDataEntity.java new file mode 100644 index 0000000..ec58c88 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterCheckDataEntity.java @@ -0,0 +1,225 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class WaterCheckDataEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String recordId; + @JPos(index = 1, filter = true) + private String deviceid; + @JPos(index = 2, filter = true) + private String buNo; + @JPos(index = 3, filter = true) + private String owner; + @JPos(index = 4, timekey = true,orderkey = true) + private Date checkTimestamp; + @JPos(index = 5, filter = true) + private String checkDevice; + @JPos(index = 6) + private String orgTimestamp; + @JPos(index = 7) + private double orgtoc; + @JPos(index = 8) + private double orgcod; + @JPos(index = 9) + private double orgtds; + @JPos(index = 10) + private double orgntu; + @JPos(index = 11) + private String cleanTimestamp; + @JPos(index = 12) + private double toc; + @JPos(index = 13) + private double cod; + @JPos(index = 14) + private double tds; + @JPos(index = 15) + private double ntu; + @JPos(index = 16) + private String checkstatus; + @JPos(index = 17) + private String timestamp; + @JPos(index = 18) + private double temp; + + public WaterCheckDataEntity(){ + recordId = ""; + deviceid = ""; + buNo = ""; + owner = ""; + checkTimestamp = new Date() ; + checkDevice = ""; + orgTimestamp = ""; + orgtoc = 0; + orgcod = 0; + orgtds = 0; + orgntu = 0; + cleanTimestamp = ""; + toc = 0; + cod = 0; + tds = 0; + ntu = 0; + checkstatus = ""; + timestamp = ""; + temp = 0; + } + + public String tableName( ){ + return "iotserver_watercheck_event_table"; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getBuNo() { + return buNo; + } + + public void setBuNo(String buNo) { + this.buNo = buNo; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Date getCheckTimestamp() { + return checkTimestamp; + } + + public void setCheckTimestamp(Date checkTimestamp) { + this.checkTimestamp = checkTimestamp; + } + + public String getOrgTimestamp() { + return orgTimestamp; + } + + public void setOrgTimestamp(String orgTimestamp) { + this.orgTimestamp = orgTimestamp; + } + + public double getOrgtoc() { + return orgtoc; + } + + public void setOrgtoc(double orgtoc) { + this.orgtoc = orgtoc; + } + + public double getOrgcod() { + return orgcod; + } + + public void setOrgcod(double orgcod) { + this.orgcod = orgcod; + } + + public double getOrgtds() { + return orgtds; + } + + public void setOrgtds(double orgtds) { + this.orgtds = orgtds; + } + + public double getToc() { + return toc; + } + + public void setToc(double toc) { + this.toc = toc; + } + + public double getCod() { + return cod; + } + + public void setCod(double cod) { + this.cod = cod; + } + + public double getTds() { + return tds; + } + + public void setTds(double tds) { + this.tds = tds; + } + + public String getCheckstatus() { + return checkstatus; + } + + public void setCheckstatus(String checkstatus) { + this.checkstatus = checkstatus; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public double getTemp() { + return temp; + } + + public void setTemp(double temp) { + this.temp = temp; + } + + public double getOrgntu() { + return orgntu; + } + + public void setOrgntu(double orgntu) { + this.orgntu = orgntu; + } + + public double getNtu() { + return ntu; + } + + public void setNtu(double ntu) { + this.ntu = ntu; + } + + public String getCleanTimestamp() { + return cleanTimestamp; + } + + public void setCleanTimestamp(String cleanTimestamp) { + this.cleanTimestamp = cleanTimestamp; + } + + public String getCheckDevice() { + return checkDevice; + } + + public void setCheckDevice(String checkDevice) { + this.checkDevice = checkDevice; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterCheckReportEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterCheckReportEntity.java new file mode 100644 index 0000000..5577a0e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterCheckReportEntity.java @@ -0,0 +1,319 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class WaterCheckReportEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String recordId; + @JPos(index = 1) + private String model; + @JPos(index = 2, filter = true) + private String ble; + @JPos(index = 3, timekey = true,orderkey = true) + private Date flyTimestamp; + @JPos(index = 4) + private int flyScore; + @JPos(index = 5) + private int flytoc; + @JPos(index = 6) + private int flyntu; + @JPos(index = 7) + private int flycod; + @JPos(index = 8) + private int flytds; + @JPos(index = 9) + private int flyntc; + @JPos(index = 10) + private double longitude; + @JPos(index = 11) + private double latitude; + @JPos(index = 12, filter = true) + private String targetDeviceid; + @JPos(index = 13) + private String compRecordId; + @JPos(index = 14) + private String buNo; + @JPos(index = 15, filter = true) + private String owner; + @JPos(index = 16, filter = true) + private String detachment; + @JPos(index = 17, filter = true) + private String borough; + @JPos(index = 18, filter = true) + private String brigade; + @JPos(index = 19) + private String orgTimestamp; + @JPos(index = 20) + private double orgtoc; + @JPos(index = 21) + private double orgcod; + @JPos(index = 22) + private double orgtds; + @JPos(index = 23) + private double orgntu; + @JPos(index = 24) + private String cleanTimestamp; + @JPos(index = 25) + private double toc; + @JPos(index = 26) + private double cod; + @JPos(index = 27) + private double tds; + @JPos(index = 28) + private double ntu; + @JPos(index = 29) + private double temp; + + + public String tableName() { + return "water_check_fly_data_table"; + } + public WaterCheckReportEntity(){ + + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getBle() { + return ble; + } + + public void setBle(String ble) { + this.ble = ble; + } + + public Date getFlyTimestamp() { + return flyTimestamp; + } + + public void setFlyTimestamp(Date flyTimestamp) { + this.flyTimestamp = flyTimestamp; + } + + public int getFlyScore() { + return flyScore; + } + + public void setFlyScore(int flyScore) { + this.flyScore = flyScore; + } + + public int getFlytoc() { + return flytoc; + } + + public void setFlytoc(int flytoc) { + this.flytoc = flytoc; + } + + public int getFlyntu() { + return flyntu; + } + + public void setFlyntu(int flyntu) { + this.flyntu = flyntu; + } + + public int getFlycod() { + return flycod; + } + + public void setFlycod(int flycod) { + this.flycod = flycod; + } + + public int getFlytds() { + return flytds; + } + + public void setFlytds(int flytds) { + this.flytds = flytds; + } + + public int getFlyntc() { + return flyntc; + } + + public void setFlyntc(int flyntc) { + this.flyntc = flyntc; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getTargetDeviceid() { + return targetDeviceid; + } + + public void setTargetDeviceid(String targetDeviceid) { + this.targetDeviceid = targetDeviceid; + } + + public String getCompRecordId() { + return compRecordId; + } + + public void setCompRecordId(String compRecordId) { + this.compRecordId = compRecordId; + } + + public String getBuNo() { + return buNo; + } + + public void setBuNo(String buNo) { + this.buNo = buNo; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getOrgTimestamp() { + return orgTimestamp; + } + + public void setOrgTimestamp(String orgTimestamp) { + this.orgTimestamp = orgTimestamp; + } + + public double getOrgtoc() { + return orgtoc; + } + + public void setOrgtoc(double orgtoc) { + this.orgtoc = orgtoc; + } + + public double getOrgcod() { + return orgcod; + } + + public void setOrgcod(double orgcod) { + this.orgcod = orgcod; + } + + public double getOrgtds() { + return orgtds; + } + + public void setOrgtds(double orgtds) { + this.orgtds = orgtds; + } + + public double getOrgntu() { + return orgntu; + } + + public void setOrgntu(double orgntu) { + this.orgntu = orgntu; + } + + public String getCleanTimestamp() { + return cleanTimestamp; + } + + public void setCleanTimestamp(String cleanTimestamp) { + this.cleanTimestamp = cleanTimestamp; + } + + public double getToc() { + return toc; + } + + public void setToc(double toc) { + this.toc = toc; + } + + public double getCod() { + return cod; + } + + public void setCod(double cod) { + this.cod = cod; + } + + public double getTds() { + return tds; + } + + public void setTds(double tds) { + this.tds = tds; + } + + public double getNtu() { + return ntu; + } + + public void setNtu(double ntu) { + this.ntu = ntu; + } + + public double getTemp() { + return temp; + } + + public void setTemp(double temp) { + this.temp = temp; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterDayCountEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterDayCountEntity.java new file mode 100644 index 0000000..cc166a9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterDayCountEntity.java @@ -0,0 +1,126 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class WaterMeterDayCountEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String devicetype; + @JPos(index = 2, filter = true) + private String owner; + @JPos(index = 3, primary = true) + protected int year; + + @JPos(index = 4, primary = true) + private int month; + @JPos(index = 5, primary = true,orderkey = true) + private int day; + @JPos(index = 6) + private float daycount; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setYear(int year) { + this.year = year; + } + + public int getYear() { + return year; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getMonth() { + return month; + } + + public void setDay(int day) { + this.day = day; + } + + public int getDay() { + return day; + } + + public void setDaycount(float daycount) { + this.daycount = daycount; + } + + public float getDaycount() { + return daycount; + } + + public String tableName( ){ + return "iotserver_sensor_water_meter_month_count_table"; + } + + public List queryCounts(DataSource dataSource){ + String con = null; + + if(deviceid!=null){ + if(con==null) + con = " where deviceid='"+deviceid+"'"; + else + con += " and deviceid='"+deviceid+"'"; + } + + if(devicetype!=null){ + if(con==null) + con = " where devicetype='"+devicetype+"'"; + else + con += " and devicetype='"+devicetype+"'"; + } + + if(owner!=null){ + if(con==null) + con = " where owner='"+owner+"'"; + else + con += " and owner='"+owner+"'"; + } + + if(con==null) + con = " where year="+year + " and month="+month; + else + con += " and year="+year + " and month="+month; + String sql = "select * from " +tableName() + con; + + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, WaterMeterDayCountEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterEventEntity.java new file mode 100644 index 0000000..a9a69bc --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterEventEntity.java @@ -0,0 +1,144 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class WaterMeterEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String devicetype; + @JPos(index = 2, filter = true) + private String owner; + @JPos(index = 3, primary = true,timekey = true,orderkey = true) + protected Date timestamp; + + @JPos(index = 4) + private int cause; + @JPos(index = 5) + private int batval; + @JPos(index = 6) + private int signal; + @JPos(index = 7) + private int state; + @JPos(index = 8) + private float total; + @JPos(index = 9) + private float counttotal; + @JPos(index = 10) + private float monthcount; + @JPos(index = 11) + private float daycount; + @JPos(index = 12) + private float hourcount; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setCause(int cause) { + this.cause = cause; + } + + public int getCause() { + return cause; + } + + public void setBatval(int batval) { + this.batval = batval; + } + + public int getBatval() { + return batval; + } + + public void setSignal(int signal) { + this.signal = signal; + } + + public int getSignal() { + return signal; + } + + public void setState(int state) { + this.state = state; + } + + public int getState() { + return state; + } + + public void setTotal(float total) { + this.total = total; + } + + public float getTotal() { + return total; + } + + public void setCounttotal(float counttotal) { + this.counttotal = counttotal; + } + + public float getCounttotal() { + return counttotal; + } + + public void setMonthcount(float monthcount) { + this.monthcount = monthcount; + } + + public float getMonthcount() { + return monthcount; + } + + public void setHourcount(float hourcount) { + this.hourcount = hourcount; + } + + public float getHourcount() { + return hourcount; + } + + public void setDaycount(float daycount) { + this.daycount = daycount; + } + + public float getDaycount() { + return daycount; + } + + public String tableName( ){ + return "iotserver_sensor_water_meter_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterMonthCountEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterMonthCountEntity.java new file mode 100644 index 0000000..2bce69c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/WaterMeterMonthCountEntity.java @@ -0,0 +1,115 @@ +package com.jingyi.iotserver.firestationport.model.sensor; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class WaterMeterMonthCountEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String devicetype; + @JPos(index = 2, filter = true) + private String owner; + @JPos(index = 3, primary = true) + private int year; + @JPos(index = 4, primary = true,orderkey = true) + private int month; + @JPos(index = 5) + private float monthcount; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setYear(int year) { + this.year = year; + } + + public int getYear() { + return year; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getMonth() { + return month; + } + + public void setMonthcount(float monthcount) { + this.monthcount = monthcount; + } + + public float getMonthcount() { + return monthcount; + } + + public String tableName( ){ + return "iotserver_sensor_water_meter_month_count_table"; + } + + public List queryCounts(DataSource dataSource){ + String con = null; + + if(deviceid!=null){ + if(con==null) + con = " where deviceid='"+deviceid+"'"; + else + con += " and deviceid='"+deviceid+"'"; + } + + if(devicetype!=null){ + if(con==null) + con = " where devicetype='"+devicetype+"'"; + else + con += " and devicetype='"+devicetype+"'"; + } + + if(owner!=null){ + if(con==null) + con = " where owner='"+owner+"'"; + else + con += " and owner='"+owner+"'"; + } + + if(con==null) + con = " where year="+year; + else + con += " and year="+year; + String sql = "select * from " +tableName() + con; + + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, WaterMeterMonthCountEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCEventSettingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCEventSettingEntity.java new file mode 100644 index 0000000..17961ab --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCEventSettingEntity.java @@ -0,0 +1,65 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class AIIPCEventSettingEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true,filter = true) + private String event;// match | mismatch | no-helmet | no-chaf-hat | smoke | calling | no-clothes | fire| recognize-match| recognize-mismatch + + @JPos(index = 3) + private String setting;// open | close + + @JPos(index = 4) + private String descript; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setSetting(String setting) { + this.setting = setting; + } + + public String getSetting() { + return setting; + } + + public void setDescript(String descript) { + this.descript = descript; + } + + public String getDescript() { + return descript; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_event_setting_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCInvadeEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCInvadeEventEntity.java new file mode 100644 index 0000000..9e6565a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCInvadeEventEntity.java @@ -0,0 +1,74 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class AIIPCInvadeEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1) + private String picture; + @JPos(index = 2,primary = true,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 3,filter = true) + private String owner; + @JPos(index = 4) + private String type; + @JPos(index = 5) + private int confidence; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setPicture(String picture) { + this.picture = picture; + } + + public String getPicture() { + return picture; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setConfidence(int confidence) { + this.confidence = confidence; + } + + public int getConfidence() { + return confidence; + } + + @Override + public String tableName() { + return "iotserver_sensor_aiipc_invade_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCMatchCarPlateEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCMatchCarPlateEventEntity.java new file mode 100644 index 0000000..e777b65 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCMatchCarPlateEventEntity.java @@ -0,0 +1,166 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SQLUpdateCmd; + +import javax.sql.DataSource; +import java.util.Date; + +public class AIIPCMatchCarPlateEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true) + private long timestamp; + + @JPos(index = 3,timekey = true,orderkey = true) + private Date msgtime; + + @JPos(index = 4,filter = true) + private String event;// recognize-match| recognize-mismatch + + @JPos(index = 5,filter = true, primary = true) + private String eventid; + + @JPos(index = 6,filter = true) + private String image; + + @JPos(index = 7,filter = true) + private int imagestatus; // =0 not upload, =1 uploaded, =2 missed + + @JPos(index = 8,filter = true) + private String carplate; + + @JPos(index=9,filter = true) + private String brigade; + @JPos(index=10,filter = true) + private String borough; + @JPos(index=11,filter = true) + private String detachment; + @JPos(index=12,filter = true) + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImagestatus(int imagestatus) { + this.imagestatus = imagestatus; + } + + public int getImagestatus() { + return imagestatus; + } + + public void setCarplate(String carplate) { + this.carplate = carplate; + } + + public String getCarplate() { + return carplate; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_carplate_event_table"; + } + + public void updateImageStatus(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendKey("channel",channel); + cmd.appendKey("timestamp",timestamp); + cmd.appendKey("eventid",eventid); + cmd.appendValue("imagestatus",imagestatus); + + SQLTools.ExecuteQueryCount(dataSource,cmd.getSql()); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCMatchFaceEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCMatchFaceEventEntity.java new file mode 100644 index 0000000..1e7dd50 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCMatchFaceEventEntity.java @@ -0,0 +1,178 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SQLUpdateCmd; + +import javax.sql.DataSource; +import java.util.Date; + +public class AIIPCMatchFaceEventEntity extends SQLDataObject { + + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true) + private long timestamp; + + @JPos(index = 3,timekey = true,orderkey = true) + private Date msgtime; + + @JPos(index = 4,filter = true) + private String event;//match | mismatch | no-helmet | no-chaf-hat | smoke | calling | no-clothes + + @JPos(index = 5,filter = true, primary = true) + private String eventid; + + @JPos(index = 6,filter = true) + private String image; + + @JPos(index = 7,filter = true) + private int imagestatus; // =0 not upload, =1 uploaded, =2 missed + + @JPos(index = 8,filter = true) + private String staffid; + + @JPos(index = 9,filter = true) + private String staffname; + + @JPos(index=10,filter = true) + private String brigade; + @JPos(index=11,filter = true) + private String borough; + @JPos(index=12,filter = true) + private String detachment; + @JPos(index=13,filter = true) + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImagestatus(int imagestatus) { + this.imagestatus = imagestatus; + } + + public int getImagestatus() { + return imagestatus; + } + + public void setStaffid(String staffid) { + this.staffid = staffid; + } + + public String getStaffid() { + return staffid; + } + + public void setStaffname(String staffname) { + this.staffname = staffname; + } + + public String getStaffname() { + return staffname; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_face_event_table"; + } + + public void updateImageStatus(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendKey("channel",channel); + cmd.appendKey("timestamp",timestamp); + cmd.appendKey("eventid",eventid); + cmd.appendValue("imagestatus",imagestatus); + + SQLTools.ExecuteQueryCount(dataSource,cmd.getSql()); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCPictureMatchSettingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCPictureMatchSettingEntity.java new file mode 100644 index 0000000..f102873 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCPictureMatchSettingEntity.java @@ -0,0 +1,109 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class AIIPCPictureMatchSettingEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true,filter = true) + private String image; + + @JPos(index = 3) + private String imageurl; + + @JPos(index = 4,filter = true) + private String subject; //person | + + @JPos(index = 5,filter = true) + private String reference; + + @JPos(index = 6) + private String descript; + + @JPos(index = 7) + private String option; + + @JPos(index = 8) + private long timestamp; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImageurl(String imageurl) { + this.imageurl = imageurl; + } + + public String getImageurl() { + return imageurl; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getSubject() { + return subject; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public String getReference() { + return reference; + } + + public void setDescript(String descript) { + this.descript = descript; + } + + public String getDescript() { + return descript; + } + + public void setOption(String option) { + this.option = option; + } + + public String getOption() { + return option; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_pic_setting_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCSceneEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCSceneEventEntity.java new file mode 100644 index 0000000..61a3386 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCSceneEventEntity.java @@ -0,0 +1,154 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SQLUpdateCmd; + +import javax.sql.DataSource; +import java.util.Date; + +public class AIIPCSceneEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true) + private long timestamp; + + @JPos(index = 3,timekey = true,orderkey = true) + private Date msgtime; + + @JPos(index = 4,filter = true) + private String event;//fire + + @JPos(index = 5,filter = true, primary = true) + private String eventid; + + @JPos(index = 6,filter = true) + private String image; + @JPos(index = 7,filter = true) + private int imagestatus; // =0 not upload, =1 uploaded, =2 missed + + @JPos(index=8,filter = true) + private String brigade; + @JPos(index=9,filter = true) + private String borough; + @JPos(index=10,filter = true) + private String detachment; + @JPos(index=11,filter = true) + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImagestatus(int imagestatus) { + this.imagestatus = imagestatus; + } + + public int getImagestatus() { + return imagestatus; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_scene_event_table"; + } + + public void updateImageStatus(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"deviceid",deviceid); + cmd.appendKey("channel",channel); + cmd.appendKey("timestamp",timestamp); + cmd.appendKey("eventid",eventid); + cmd.appendValue("imagestatus",imagestatus); + + SQLTools.ExecuteQueryCount(dataSource,cmd.getSql()); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCSettingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCSettingEntity.java new file mode 100644 index 0000000..b2a4b16 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCSettingEntity.java @@ -0,0 +1,65 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class AIIPCSettingEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1) + private int heartbeat; + + @JPos(index = 2) + private String serveraddr; + + @JPos(index = 3) + private int port; + + @JPos(index = 4) + private String imageuploadaddr; + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public void setHeartbeat(int heartbeat) { + this.heartbeat = heartbeat; + } + + public int getHeartbeat() { + return heartbeat; + } + + public void setServeraddr(String serveraddr) { + this.serveraddr = serveraddr; + } + + public String getServeraddr() { + return serveraddr; + } + + public void setPort(int port) { + this.port = port; + } + + public int getPort() { + return port; + } + + public void setImageuploadaddr(String imageuploadaddr) { + this.imageuploadaddr = imageuploadaddr; + } + + public String getImageuploadaddr() { + return imageuploadaddr; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_setting_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCStatusEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCStatusEntity.java new file mode 100644 index 0000000..5514151 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCStatusEntity.java @@ -0,0 +1,108 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class AIIPCStatusEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true) + private long timestamp; + + @JPos(index = 3,timekey = true,orderkey = true) + private Date msgtime; + + @JPos(index = 4) + private int personcount; + + @JPos(index=5,filter = true) + private String brigade; + @JPos(index=6,filter = true) + private String borough; + @JPos(index=7,filter = true) + private String detachment; + @JPos(index=8,filter = true) + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setPersoncount(int personcount) { + this.personcount = personcount; + } + + public int getPersoncount() { + return personcount; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_status_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCTextMatchSettingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCTextMatchSettingEntity.java new file mode 100644 index 0000000..3bc7a0f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AIIPCTextMatchSettingEntity.java @@ -0,0 +1,54 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class AIIPCTextMatchSettingEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + + @JPos(index = 1, primary = true,filter = true) + private String channel; + + @JPos(index = 2, primary = true) + private String text; + + @JPos(index = 3) + private String option; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setText(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public void setOption(String option) { + this.option = option; + } + + public String getOption() { + return option; + } + + public String tableName(){ + return "iotserver_sensor_aiipc_text_setting_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AiSearchAlarmEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AiSearchAlarmEntity.java new file mode 100644 index 0000000..8280fc3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/AiSearchAlarmEntity.java @@ -0,0 +1,81 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.firestationport.model.multiPlatform.AlarmFileInfo; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.util.Date; +import java.util.List; + +@Data +public class AiSearchAlarmEntity { + + public static final String TYPE_FACE = "face"; + public static final String TYPE_VEHICLE = "vehicle"; + + private String targetType; + private String targetValue; + private String targetName; + private String city; + private String district; + private String town; + private String street; + private Date timestamp; + private String level; + private String state; + private String alarmType; + private String alarmName; + private String deviceId; + private String alarmData; + private String address; + private Double longitude; + private Double latitude; + private String storageType; + private String bucket; + private String path; + private String url; + private String platKey; + private String alarmId; + + + public static boolean reportToMultiPlat(AiSearchAlarmEntity aiSearchAlarm){ + boolean reportState = true; + + HttpURLConnection connLogin; + try { + String payload = JSON.toJSONString(aiSearchAlarm); + + String agentUrlLong = "https://www.hndyjqrh.cn:8083/multialarm/ai/alarm/report" ; + System.out.println("process reportToMultiPlat: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("platKey", "LS0001"); + connLogin.setRequestProperty("platToken", "LS0001"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(payload); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("reportToMultiPlat: fail = " + responseCode); + }else{ + System.out.println("reportToMultiPlat: ok = " + responseCode); + } + }catch (Exception e){ + System.out.println("reportToMultiPlat: fail = " + e.getMessage()); + }finally { + + } + + return reportState; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/BRVisonEvent.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/BRVisonEvent.java new file mode 100644 index 0000000..ab931a3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/BRVisonEvent.java @@ -0,0 +1,16 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import lombok.Data; + +@Data +public class BRVisonEvent { + private String mechanismName; + private String branchesId; + private String rtspIP; + private String alarmId; + private String eventName; + private String eventType; + private String time; + private String img1; + private String img2; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmPersonSummary.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmPersonSummary.java new file mode 100644 index 0000000..2dba032 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmPersonSummary.java @@ -0,0 +1,87 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class FaceAlarmPersonSummary extends SQLDataObject { + + @JPos(index=0, primary = true, filter = true) + private String personId; + @JPos(index=1,primary = true, filter = true) + private String year; + @JPos(index=2,primary = true, filter = true) + private String month; + @JPos(index=3,primary = true, filter = true) + private String day; + @JPos(index=4) + private int alarmCount; + @JPos(index=5,timekey = true, orderkey = true) + private Date lastTimestamp; + @JPos(index=6,strlen = 2048) + private String lastPicUrl; + + + public String tableName( ){ + return "skynet_alarm_person_summary_table"; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getYear() { + return year; + } + + public void setYear(String year) { + this.year = year; + } + + public String getMonth() { + return month; + } + + public void setMonth(String month) { + this.month = month; + } + + public String getDay() { + return day; + } + + public void setDay(String day) { + this.day = day; + } + + public Date getLastTimestamp() { + return lastTimestamp; + } + + public void setLastTimestamp(Date lastTimestamp) { + this.lastTimestamp = lastTimestamp; + } + + public int getAlarmCount() { + return alarmCount; + } + + public void setAlarmCount(int alarmCount) { + this.alarmCount = alarmCount; + } + + public String getLastPicUrl() { + return lastPicUrl; + } + + public void setLastPicUrl(String lastPicUrl) { + this.lastPicUrl = lastPicUrl; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmRecordSum.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmRecordSum.java new file mode 100644 index 0000000..1f45a5b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmRecordSum.java @@ -0,0 +1,34 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import java.util.HashMap; +import java.util.List; + +public class FaceAlarmRecordSum { + private List groupInfo; + private List< HikFaceAlarmRecordSetInfo> personInfo; + private Object data; + + public List< HikFaceAlarmGroupSetInfo> getGroupInfo() { + return groupInfo; + } + + public void setGroupInfo(List< HikFaceAlarmGroupSetInfo> groupInfo) { + this.groupInfo = groupInfo; + } + + public List< HikFaceAlarmRecordSetInfo> getPersonInfo() { + return personInfo; + } + + public void setPersonInfo(List< HikFaceAlarmRecordSetInfo> personInfo) { + this.personInfo = personInfo; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmStationSummary.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmStationSummary.java new file mode 100644 index 0000000..e9ec8dd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/FaceAlarmStationSummary.java @@ -0,0 +1,115 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class FaceAlarmStationSummary extends SQLDataObject { + + @JPos(index=0, primary = true, filter = true) + private String station; + @JPos(index=1,primary = true, filter = true) + private String year; + @JPos(index=2,primary = true, filter = true) + private String month; + @JPos(index=3,primary = true, filter = true) + private String day; + @JPos(index=4) + private int alarmCount; + @JPos(index=5,timekey = true, orderkey = true) + private Date lastTimestamp; + @JPos(index=6,strlen = 2048) + private String lastPicUrl; + + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String detachment; + @JPos(index = 9,filter = true) + private String borough; + + public String tableName( ){ + return "skynet_alarm_station_summary_table"; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getYear() { + return year; + } + + public void setYear(String year) { + this.year = year; + } + + public String getMonth() { + return month; + } + + public void setMonth(String month) { + this.month = month; + } + + public String getDay() { + return day; + } + + public void setDay(String day) { + this.day = day; + } + + public Date getLastTimestamp() { + return lastTimestamp; + } + + public void setLastTimestamp(Date lastTimestamp) { + this.lastTimestamp = lastTimestamp; + } + + public int getAlarmCount() { + return alarmCount; + } + + public void setAlarmCount(int alarmCount) { + this.alarmCount = alarmCount; + } + + public String getLastPicUrl() { + return lastPicUrl; + } + + public void setLastPicUrl(String lastPicUrl) { + this.lastPicUrl = lastPicUrl; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/H5SDeviceSummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/H5SDeviceSummaryEntity.java new file mode 100644 index 0000000..ddfe0e1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/H5SDeviceSummaryEntity.java @@ -0,0 +1,264 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +public class H5SDeviceSummaryEntity { + private Integer nCameraTotal; + + private Integer nCameraOnline; + + private Integer nHikDevTotal; + + private Integer nHikDevOnline; + + private Integer nDhDevTotal; + + private Integer nDhDevOnline; + + private Integer nHikIscDevTotal; + + private Integer nHikIscDevOnline; + + private Integer nTdDevTotal; + + private Integer nTdDevOnline; + + private Integer nGbDevTotal; + + private Integer nGbDevOnline; + + private Integer nUnvDevTotal; + + private Integer nUnvDevOnline; + + private Integer nDssDevTotal; + + private Integer nDssDevOnline; + + private Integer nIvsDevTotal; + + private Integer nIvsDevOnline; + + private Integer nCloudTotal; + + private Integer nCloudOnline; + + private Integer nRTSPRTMPTotal; + + private Integer nRTSPRTMPOnline; + + private Integer nONVIFTotal; + + private Integer nONVIFOnline; + + private Integer nRTMPPushTotal; + + private Integer nRTMPPushOnline; + + public Integer getnCameraTotal() { + return nCameraTotal; + } + + public void setnCameraTotal(Integer nCameraTotal) { + this.nCameraTotal = nCameraTotal; + } + + public Integer getnCameraOnline() { + return nCameraOnline; + } + + public void setnCameraOnline(Integer nCameraOnline) { + this.nCameraOnline = nCameraOnline; + } + + public Integer getnHikDevTotal() { + return nHikDevTotal; + } + + public void setnHikDevTotal(Integer nHikDevTotal) { + this.nHikDevTotal = nHikDevTotal; + } + + public Integer getnHikDevOnline() { + return nHikDevOnline; + } + + public void setnHikDevOnline(Integer nHikDevOnline) { + this.nHikDevOnline = nHikDevOnline; + } + + public Integer getnDhDevTotal() { + return nDhDevTotal; + } + + public void setnDhDevTotal(Integer nDhDevTotal) { + this.nDhDevTotal = nDhDevTotal; + } + + public Integer getnDhDevOnline() { + return nDhDevOnline; + } + + public void setnDhDevOnline(Integer nDhDevOnline) { + this.nDhDevOnline = nDhDevOnline; + } + + public Integer getnHikIscDevTotal() { + return nHikIscDevTotal; + } + + public void setnHikIscDevTotal(Integer nHikIscDevTotal) { + this.nHikIscDevTotal = nHikIscDevTotal; + } + + public Integer getnHikIscDevOnline() { + return nHikIscDevOnline; + } + + public void setnHikIscDevOnline(Integer nHikIscDevOnline) { + this.nHikIscDevOnline = nHikIscDevOnline; + } + + public Integer getnTdDevTotal() { + return nTdDevTotal; + } + + public void setnTdDevTotal(Integer nTdDevTotal) { + this.nTdDevTotal = nTdDevTotal; + } + + public Integer getnTdDevOnline() { + return nTdDevOnline; + } + + public void setnTdDevOnline(Integer nTdDevOnline) { + this.nTdDevOnline = nTdDevOnline; + } + + public Integer getnGbDevTotal() { + return nGbDevTotal; + } + + public void setnGbDevTotal(Integer nGbDevTotal) { + this.nGbDevTotal = nGbDevTotal; + } + + public Integer getnGbDevOnline() { + return nGbDevOnline; + } + + public void setnGbDevOnline(Integer nGbDevOnline) { + this.nGbDevOnline = nGbDevOnline; + } + + public Integer getnUnvDevTotal() { + return nUnvDevTotal; + } + + public void setnUnvDevTotal(Integer nUnvDevTotal) { + this.nUnvDevTotal = nUnvDevTotal; + } + + public Integer getnUnvDevOnline() { + return nUnvDevOnline; + } + + public void setnUnvDevOnline(Integer nUnvDevOnline) { + this.nUnvDevOnline = nUnvDevOnline; + } + + public Integer getnDssDevTotal() { + return nDssDevTotal; + } + + public void setnDssDevTotal(Integer nDssDevTotal) { + this.nDssDevTotal = nDssDevTotal; + } + + public Integer getnDssDevOnline() { + return nDssDevOnline; + } + + public void setnDssDevOnline(Integer nDssDevOnline) { + this.nDssDevOnline = nDssDevOnline; + } + + public Integer getnIvsDevTotal() { + return nIvsDevTotal; + } + + public void setnIvsDevTotal(Integer nIvsDevTotal) { + this.nIvsDevTotal = nIvsDevTotal; + } + + public Integer getnIvsDevOnline() { + return nIvsDevOnline; + } + + public void setnIvsDevOnline(Integer nIvsDevOnline) { + this.nIvsDevOnline = nIvsDevOnline; + } + + public Integer getnCloudTotal() { + return nCloudTotal; + } + + public void setnCloudTotal(Integer nCloudTotal) { + this.nCloudTotal = nCloudTotal; + } + + public Integer getnCloudOnline() { + return nCloudOnline; + } + + public void setnCloudOnline(Integer nCloudOnline) { + this.nCloudOnline = nCloudOnline; + } + + public Integer getnRTSPRTMPTotal() { + return nRTSPRTMPTotal; + } + + public void setnRTSPRTMPTotal(Integer nRTSPRTMPTotal) { + this.nRTSPRTMPTotal = nRTSPRTMPTotal; + } + + public Integer getnRTSPRTMPOnline() { + return nRTSPRTMPOnline; + } + + public void setnRTSPRTMPOnline(Integer nRTSPRTMPOnline) { + this.nRTSPRTMPOnline = nRTSPRTMPOnline; + } + + public Integer getnONVIFTotal() { + return nONVIFTotal; + } + + public void setnONVIFTotal(Integer nONVIFTotal) { + this.nONVIFTotal = nONVIFTotal; + } + + public Integer getnONVIFOnline() { + return nONVIFOnline; + } + + public void setnONVIFOnline(Integer nONVIFOnline) { + this.nONVIFOnline = nONVIFOnline; + } + + public Integer getnRTMPPushTotal() { + return nRTMPPushTotal; + } + + public void setnRTMPPushTotal(Integer nRTMPPushTotal) { + this.nRTMPPushTotal = nRTMPPushTotal; + } + + public Integer getnRTMPPushOnline() { + return nRTMPPushOnline; + } + + public void setnRTMPPushOnline(Integer nRTMPPushOnline) { + this.nRTMPPushOnline = nRTMPPushOnline; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmGroupSetInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmGroupSetInfo.java new file mode 100644 index 0000000..eafa190 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmGroupSetInfo.java @@ -0,0 +1,46 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import java.util.ArrayList; +import java.util.List; + +public class HikFaceAlarmGroupSetInfo { + private String groupName; + private int count; + private List person; + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public List getPerson() { + return person; + } + + public void setPerson(List person) { + this.person = person; + } + + public int addPersonInfo(HikFaceAlarmRecordSetInfo personInfo){ + if(personInfo == null){ + return count; + } + if(person == null){ + person = new ArrayList<>(); + } + person.add(personInfo); + count = person.size(); + return count; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmRecordEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmRecordEntity.java new file mode 100644 index 0000000..47db107 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmRecordEntity.java @@ -0,0 +1,372 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +/* + "name": "测试布控", + "taskId": "temp_301230caa5534d0d9de6f9c020936019", + "alarmId": "8e49e4268d7a4b91aef8f0cd39c8e64d", + "alarmTime": "2017-06-15T00:00:00.000+08:00", + "cameraName": "人脸抓拍机", + "cameraIndexCode": "1100003210301421", + "latitude": "120.216123284763", + "longitude": "30.21168569675452", + "snappedPicUrl": "http://ip:port/pic?=d1=i972z01c9s08a-690105m2ep=t9i6d*=*6pdi=*1s0i1=98b2ifd92*dedb03682-81b3997-1423*0-f0i2c7d0e13", + "bkgPicUrl": "http://ip:port/pic?=d1=i972z01c9s08a-690105m2ep=t9i6d*=*6pdi=*1s0i1=98b2ifd92*dedb03682-81b3997-1423*0-f0i2c7d0e17", + "bkgPicUrlBak": "http://ip:port/pic?=d9=i974z01c9s08a-690105m2ep=t9i7d*=*6pdi=*1s0i1=98b2ifd92*dedb03682-81b3997-1423*0-f0i4c7d3e18", + "refrencePicUrl": "http://ip:port/pic?=d9=i974z01c9s08a-690105m2ep=t9i7d*=*6pdi=*1s0i1=98b2ifd92*dedb03682-81b3997-1423*0-f0i4c7d3e12", + "similarity": "0.1", + "personLibId": "ff80808162dbbeef0162e104de5c0005", + "personLibName": "在逃犯库", + "personId": "0094_9_48ef0f5c6f6140839df4ea7bf84b8708", + "personName": "张三", + "certificateType": 111, + "certificateTypeName": "居民身份证", + "certificateNumber": "330602201106010356", + "registerGender": "male", + "registerGenderName": "男", + + */ +public class HikFaceAlarmRecordEntity extends SQLDataObject { + + public final static String STATE_Unread = "unread"; + public final static String STATE_Read = "read"; + + @JPos(index=0,primary = true,filter = true) + private String alarmId; + @JPos(index=1) + private String name; + @JPos(index=2) + private String taskId; + @JPos(index=3) + private String alarmTime; + @JPos(index=4,filter = true) + private String cameraName; + @JPos(index=5,filter = true) + private String cameraIndexCode; + @JPos(index=6) + private double latitude; + @JPos(index=7) + private double longitude; + @JPos(index=8, strlen = 2048) + private String snappedPicUrl; + @JPos(index=9, strlen = 2048) + private String bkgPicUrl; + @JPos(index=10, strlen = 2048) + private String bkgPicUrlBak; + @JPos(index=11, strlen = 2048) + private String refrencePicUrl; + @JPos(index=12) + private String similarity; + @JPos(index=13,filter = true) + private String personLibId; + @JPos(index=14,filter = true) + private String personLibName; + @JPos(index=15,filter = true) + private String personId; + @JPos(index=16,filter = true) + private String personName; + @JPos(index=17) + private int certificateType; + @JPos(index=18,filter = true) + private String certificateTypeName; + @JPos(index=19,filter = true) + private String certificateNumber; + @JPos(index=20) + private String registerGender; + @JPos(index=21,filter = true) + private String registerGenderName; + @JPos(index = 22,filter = true) + private String station; + @JPos(index = 23,filter = true) + private String brigade; + @JPos(index = 24,filter = true) + private String detachment; + @JPos(index = 25,filter = true) + private String borough; + @JPos(index=26, timekey = true, orderkey = true) + private Date timestamp; + @JPos(index=27,filter = true) + private String readState; + @JPos(index=28,filter = true) + private String pointCode; + @JPos(index=29,filter = true,strlen = 1024) + private String schools; + @JPos(index=30,filter = true) + private String groupType; + + public String tableName( ){ + return "hik_face_alarm_table"; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getAlarmId() { + return alarmId; + } + + public void setAlarmId(String alarmId) { + this.alarmId = alarmId; + } + + public String getAlarmTime() { + return alarmTime; + } + + public void setAlarmTime(String alarmTime) { + this.alarmTime = alarmTime; + } + + public String getCameraName() { + return cameraName; + } + + public void setCameraName(String cameraName) { + this.cameraName = cameraName; + } + + public String getCameraIndexCode() { + return cameraIndexCode; + } + + public void setCameraIndexCode(String cameraIndexCode) { + this.cameraIndexCode = cameraIndexCode; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getSnappedPicUrl() { + return snappedPicUrl; + } + + public void setSnappedPicUrl(String snappedPicUrl) { + this.snappedPicUrl = snappedPicUrl; + } + + public String getBkgPicUrl() { + return bkgPicUrl; + } + + public void setBkgPicUrl(String bkgPicUrl) { + this.bkgPicUrl = bkgPicUrl; + } + + public String getBkgPicUrlBak() { + return bkgPicUrlBak; + } + + public void setBkgPicUrlBak(String bkgPicUrlBak) { + this.bkgPicUrlBak = bkgPicUrlBak; + } + + public String getRefrencePicUrl() { + return refrencePicUrl; + } + + public void setRefrencePicUrl(String refrencePicUrl) { + this.refrencePicUrl = refrencePicUrl; + } + + public String getSimilarity() { + return similarity; + } + + public void setSimilarity(String similarity) { + this.similarity = similarity; + } + + public String getPersonLibId() { + return personLibId; + } + + public void setPersonLibId(String personLibId) { + this.personLibId = personLibId; + } + + public String getPersonLibName() { + return personLibName; + } + + public void setPersonLibName(String personLibName) { + this.personLibName = personLibName; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public int getCertificateType() { + return certificateType; + } + + public void setCertificateType(int certificateType) { + this.certificateType = certificateType; + } + + public String getCertificateTypeName() { + return certificateTypeName; + } + + public void setCertificateTypeName(String certificateTypeName) { + this.certificateTypeName = certificateTypeName; + } + + public String getCertificateNumber() { + return certificateNumber; + } + + public void setCertificateNumber(String certificateNumber) { + this.certificateNumber = certificateNumber; + } + + public String getRegisterGender() { + return registerGender; + } + + public void setRegisterGender(String registerGender) { + this.registerGender = registerGender; + } + + public String getRegisterGenderName() { + return registerGenderName; + } + + public void setRegisterGenderName(String registerGenderName) { + this.registerGenderName = registerGenderName; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getReadState() { + return readState; + } + + public void setReadState(String readState) { + this.readState = readState; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getPointCode() { + return pointCode; + } + + public void setPointCode(String pointCode) { + this.pointCode = pointCode; + } + + public String getSchools() { + return schools; + } + + public void setSchools(String schools) { + this.schools = schools; + } + + public String getGroupType() { + return groupType; + } + + public void setGroupType(String groupType) { + this.groupType = groupType; + } + + @Override + public boolean equals(Object obj){ + if(obj == null){ + return false; + } + if(!(obj instanceof HikFaceAlarmRecordEntity)){ + return false; + } + + HikFaceAlarmRecordEntity leftObj = (HikFaceAlarmRecordEntity)obj; + if(leftObj.getPersonId() == null || leftObj.getCameraIndexCode() == null || this.getPersonId() == null || this.getCameraIndexCode() == null){ + return false; + } + if(leftObj.getPersonId().equalsIgnoreCase(this.getPersonId()) && leftObj.getCameraIndexCode().equalsIgnoreCase(this.getCameraIndexCode())){ + return true; + } + return false; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmRecordSetInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmRecordSetInfo.java new file mode 100644 index 0000000..0e54878 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/HikFaceAlarmRecordSetInfo.java @@ -0,0 +1,50 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +public class HikFaceAlarmRecordSetInfo { + private String personId; + private String groupType; + private int count; + private String personName; + + public HikFaceAlarmRecordSetInfo(){ + personId = ""; + groupType = ""; + count = 0; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getGroupType() { + return groupType; + } + + public void setGroupType(String groupType) { + this.groupType = groupType; + } + + public void addCount(){ + count += 1; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/PictureAgentUrl.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/PictureAgentUrl.java new file mode 100644 index 0000000..6cfa5e4 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/PictureAgentUrl.java @@ -0,0 +1,14 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +public class PictureAgentUrl { + private String pictureUrl; + + + public String getPictureUrl() { + return pictureUrl; + } + + public void setPictureUrl(String pictureUrl) { + this.pictureUrl = pictureUrl; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/SophgoMetaData.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/SophgoMetaData.java new file mode 100644 index 0000000..b05f744 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/SophgoMetaData.java @@ -0,0 +1,70 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class SophgoMetaData extends SQLDataObject { + @JPos(index=0,primary = true,filter = true,buildindex = true) + private String warnId; + @JPos(index=1,strlen = 8192) + private String extraImage; + @JPos(index=2,strlen = 8192) + private String feature; + @JPos(index=3,strlen = 8192) + private String fullImage; + @JPos(index=4,strlen = 248192) + private String image; + @JPos(index=5) + private int metaType; + + public String tableName( ){ + return "ai_sophgo_meta_table"; + } + public String getWarnId() { + return warnId; + } + + public void setWarnId(String warnId) { + this.warnId = warnId; + } + + public String getExtraImage() { + return extraImage; + } + + public void setExtraImage(String extraImage) { + this.extraImage = extraImage; + } + + public String getFeature() { + return feature; + } + + public void setFeature(String feature) { + this.feature = feature; + } + + public String getFullImage() { + return fullImage; + } + + public void setFullImage(String fullImage) { + this.fullImage = fullImage; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public int getMetaType() { + return metaType; + } + + public void setMetaType(int metaType) { + this.metaType = metaType; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/SophgoWarn.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/SophgoWarn.java new file mode 100644 index 0000000..8543cbb --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/aiipc/SophgoWarn.java @@ -0,0 +1,63 @@ +package com.jingyi.iotserver.firestationport.model.sensor.aiipc; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class SophgoWarn extends SQLDataObject { + public final static String STATE_Unread = "unread"; + public final static String STATE_Read = "read"; + + @JPos(index=0,primary = true,filter = true) + private String warnId; + @JPos(index=1,filter = true) + private String deviceId; + @JPos(index=2) + private String warnDesc; + @JPos(index=3) + private String warnInfo; + @JPos(index=4) + private String warnName; + @JPos(index=5) + private int warnType; + @JPos(index=6) + private String channelName; + @JPos(index=7) + private int channelNo; + @JPos(index=8) + private long timestamp; + @JPos(index=9,timekey = true,orderkey = true, buildindex = true) + private Date receiveTime; + + @JPos(index=10,filter = true) + private String personId; + @JPos(index=11,filter = true) + private String personName; + + @JPos(index = 12,filter = true) + private String station; + @JPos(index = 13,filter = true) + private String brigade; + @JPos(index = 14,filter = true) + private String detachment; + @JPos(index = 15,filter = true) + private String borough; + + @JPos(index=16) + private double latitude; + @JPos(index=17) + private double longitude; + + @JPos(index=18,filter = true) + private String readState; + @JPos(index=19,strlen = 1024) + private String imageUrl; + + public String tableName( ){ + return "ai_sophgo_warn_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/CommunityInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/CommunityInfo.java new file mode 100644 index 0000000..bf2d7c5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/CommunityInfo.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.firestationport.model.sensor.echarge; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +@Data +public class CommunityInfo extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String communityId; + @JPos(index = 1,filter = true) + private String communityName; + @JPos(index = 2,filter = true) + private String policeStation; + @JPos(index = 3,filter = true) + private String policeZone; + @JPos(index = 4,filter = true) + private String address; + @JPos(index = 5,filter = true) + private String contact; + @JPos(index = 6,filter = true) + private String phone; + @JPos(index = 7) + private double longitude; + @JPos(index = 8) + private double latitude; + @JPos(index = 9, strlen = 4096) + private String boundary; + @JPos(index = 10,filter = true) + private String station; + @JPos(index = 11,filter = true) + private String detachment; + @JPos(index = 12,filter = true) + private String borough; + @JPos(index = 13,filter = true) + private String brigade; + + public String tableName( ){ + return "residential_community_info_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeAlarmEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeAlarmEntity.java new file mode 100644 index 0000000..24a01f8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeAlarmEntity.java @@ -0,0 +1,68 @@ +package com.jingyi.iotserver.firestationport.model.sensor.echarge; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class EChargeAlarmEntity extends SQLDataObject { + public static final String ALARM_CHARGE_IN = "charge.in"; + public static final String ALARM_CHARGE_OUT = "charge.out"; + + public static final String ALARM_STATE_NEW = "new"; + public static final String ALARM_STATE_READ = "readed"; + public static final String ALARM_STATE_CLOSED = "closed"; + + @JPos(index = 0, primary = true,filter = true) + private String alarmId; + @JPos(index = 1, filter = true) + private String sensorId; + @JPos(index=2) + private String alarm; + @JPos(index=3,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 4,filter = true) + private String brigade; + @JPos(index = 5,filter = true) + private String detachment; + @JPos(index = 6,filter = true) + private String borough; + @JPos(index=7,filter = true) + private String station; + @JPos(index = 8) + private double longitude; + @JPos(index = 9) + private double latitude; + @JPos(index = 10) + private double attitude; + @JPos(index = 11,filter = true) + private String roomId; + @JPos(index = 12,filter = true) + private String roomName; + @JPos(index = 13,filter = true) + private String buildingId; + @JPos(index = 14,filter = true) + private String buildingName; + @JPos(index = 15,filter = true) + private String communityId; + @JPos(index = 16,filter = true) + private String communityName; + @JPos(index = 17,filter = true) + private String roomUserName; + @JPos(index = 18,filter = true) + private String roomUserPhone; + @JPos(index = 19) + private String roomInfo; + @JPos(index=20) + private String state; + @JPos(index=21) + private Date readTime; + @JPos(index=22) + private Date closeTime; + + public String tableName(){ + return "house_charge_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeBuildingEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeBuildingEntity.java new file mode 100644 index 0000000..991cf9e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeBuildingEntity.java @@ -0,0 +1,49 @@ +package com.jingyi.iotserver.firestationport.model.sensor.echarge; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +@Data +public class EChargeBuildingEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true) + private String buildingId; + @JPos(index = 1,filter = true) + private String buildingName; + @JPos(index = 2,filter = true) + private String communityId; + @JPos(index = 3,filter = true) + private String communityName; + @JPos(index = 4,filter = true) + private String address; + @JPos(index = 5,filter = true) + private String contact; + @JPos(index = 6,filter = true) + private String phone; + @JPos(index = 7) + private double longitude; + @JPos(index = 8) + private double latitude; + @JPos(index = 9, strlen = 4096) + private String boundary; + @JPos(index = 10) + private double high; + @JPos(index = 11) + private int floorCount; + @JPos(index = 12,filter = true) + private String buildingType; + @JPos(index = 13) + private String buildingInfo; + @JPos(index = 14,filter = true) + private String station; + @JPos(index = 15,filter = true) + private String detachment; + @JPos(index = 16,filter = true) + private String borough; + @JPos(index = 17,filter = true) + private String brigade; + + public String tableName(){ + return "community_building_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeRoomEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeRoomEntity.java new file mode 100644 index 0000000..3406118 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/echarge/EChargeRoomEntity.java @@ -0,0 +1,81 @@ +package com.jingyi.iotserver.firestationport.model.sensor.echarge; + +import com.jingyi.iotserver.firestationport.model.sensor.SkynetIPCEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import lombok.Data; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +@Data +public class EChargeRoomEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true) + private String roomId; + @JPos(index = 1,filter = true) + private String roomName; + @JPos(index = 2,filter = true) + private String buildingId; + @JPos(index = 3,filter = true) + private String buildingName; + @JPos(index = 4,filter = true) + private String communityId; + @JPos(index = 5,filter = true) + private String communityName; + @JPos(index = 6,filter = true) + private String address; + @JPos(index = 7,filter = true) + private String userName; + @JPos(index = 8,filter = true) + private String userPhone; + @JPos(index = 9) + private double longitude; + @JPos(index = 10) + private double latitude; + @JPos(index = 11) + private double attitude; + @JPos(index = 12, strlen = 4096) + private String boundary; + @JPos(index = 13) + private String floorIndex; + @JPos(index = 14) + private String roomType; + @JPos(index = 15) + private String roomInfo; + @JPos(index = 16,filter = true) + private String station; + @JPos(index = 17,filter = true) + private String detachment; + @JPos(index = 18,filter = true) + private String borough; + @JPos(index = 19,filter = true) + private String brigade; + @JPos(index = 20, filter = true) + private String chargeSensorId; + @JPos(index = 21, filter = true) + private String chargeStatus; + @JPos(index = 22) + private Date chargeStatusTime; + @JPos(index = 23) + private int chargeInCount; + + public String tableName(){ + return "community_room_table"; + } + + public static EChargeRoomEntity QueryWithChargeSensorId(DataSource dataSource, String sensorId) { + EChargeRoomEntity sensorRoom = new EChargeRoomEntity(); + String sql = "select * from " + sensorRoom.tableName() + " where chargeSensorId='" + sensorId + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, EChargeRoomEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/ProcessAlarmEventOpRecord.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/ProcessAlarmEventOpRecord.java new file mode 100644 index 0000000..38e8267 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/ProcessAlarmEventOpRecord.java @@ -0,0 +1,153 @@ +package com.jingyi.iotserver.firestationport.model.sensor.event; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class ProcessAlarmEventOpRecord extends SQLDataObject { + @JPos(index = 0,identify = true,filter = true) + private String recordId; + @JPos(index = 1,primary = true,filter = true) + private String eventId; + @JPos(index = 2,primary = true,filter = true) + private String operation;// updatestatus + @JPos(index = 3,primary = true, filter = true) + private String operator; + @JPos(index = 4,filter = true) + private String operatortype; + @JPos(index = 5,filter = true) + private String operatordevice; + @JPos(index = 6,filter = true) + private String operatordevicetype; + @JPos(index = 7,filter = true) + private String previousState; + @JPos(index = 8,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 9,filter = true) + private String receiver; + @JPos(index = 10) + private double longitude; + @JPos(index = 11) + private double latitude; + @JPos(index = 12,strlen = 4096) + private String comment; + @JPos(index = 13) + private String newState; + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getEventId() { + return eventId; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getOperation() { + return operation; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setOperatortype(String operatortype) { + this.operatortype = operatortype; + } + + public String getOperatortype() { + return operatortype; + } + + public void setOperatordevice(String operatordevice) { + this.operatordevice = operatordevice; + } + + public String getOperatordevice() { + return operatordevice; + } + + public void setOperatordevicetype(String operatordevicetype) { + this.operatordevicetype = operatordevicetype; + } + + public String getOperatordevicetype() { + return operatordevicetype; + } + + public void setPreviousState(String previousState) { + this.previousState = previousState; + } + + public String getPreviousState() { + return previousState; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public String tableName( ){ + return "iotserver_process_alarm_event_op_table"; + } + + public String getNewState() { + return newState; + } + + public void setNewState(String newState) { + this.newState = newState; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorAlarmEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorAlarmEventEntity.java new file mode 100644 index 0000000..d257f33 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorAlarmEventEntity.java @@ -0,0 +1,84 @@ +package com.jingyi.iotserver.firestationport.model.sensor.event; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class SensorAlarmEventEntity extends SQLDataObject { + + public final static String STATE_NEW = "new"; + + public final static String STATE_DISPATCHED = "dispatched"; + public final static String STATE_PROCESSING = "processing"; + public final static String STATE_PROCESSED = "processed"; + public final static String STATE_CLOSE = "close"; + + public final static String STATE_Read = "read"; + + public final static String Alarm_Type_AI_Entrance = "ai.entrance"; + public final static String Alarm_Type_SOS_PushBotton = "sos.pushbutton"; + public final static String Alarm_Type_SOS_MDEV = "sos.mdev"; + public final static String Alarm_Type_SOS_Voice = "sos.voice"; + + @JPos(index=0,primary = true,filter = true) + private String eventId; + @JPos(index=1,primary = true,filter = true) + private String deviceId; + @JPos(index=2,filter = true) + private String devicetype; + @JPos(index=3,filter = true,diffconf = true) + private String state; + @JPos(index=4,timekey = true,orderkey = true, update = false) + protected Date timestamp; + @JPos(index=5,primary = true,filter = true) + private String brigade; + @JPos(index=6,primary = true,filter = true) + private String borough; + @JPos(index=7,primary = true,filter = true) + private String detachment; + @JPos(index=8,primary = true,filter = true) + private String station; + @JPos(index=9,filter = true) + private String alarmSource; + @JPos(index=10,filter = true) + private String alarmType; + @JPos(index=11,filter = true) + private String alarmCode; + @JPos(index=12,strlen = 2048000) + private String eventData; + @JPos(index=13) + private String address; + @JPos(index=14,floatthreshold = -1.0f, update = false) + private double longitude; + @JPos(index=15,floatthreshold = -1.0f, update = false) + private double latitude; + @JPos(index=16) + private String subAddress; + @JPos(index=17,filter = true) + private String readState; + @JPos(index=18) + private Date stateTime; + @JPos(index=19,filter = true) + private String alarmTarget; + + private String user1Name; + private String user1Phone; + private String user2Name; + private String user2Phone; + private String user3Name; + private String user3Phone; + + private String city; + private String district; + private String town; + + private String needTranslate; + + public String tableName( ){ + return "iotserver_sensor_alarm_event_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorAlarmSummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorAlarmSummaryEntity.java new file mode 100644 index 0000000..fa19613 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorAlarmSummaryEntity.java @@ -0,0 +1,49 @@ +package com.jingyi.iotserver.firestationport.model.sensor.event; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class SensorAlarmSummaryEntity extends SQLDataObject { + public static final String Mode_Day = "day"; + public static final String Mode_Week = "week"; + public static final String Mode_Month = "month"; + public static final String Mode_Year = "year"; + @JPos(index = 0,primary = true,filter = true) + private String recordId; + + @JPos(index = 1,filter = true) + private String brigade; + + @JPos(index = 2,filter = true) + private String year; + @JPos(index = 3,filter = true) + private String month; + @JPos(index = 4,filter = true) + private String week; + @JPos(index = 5,filter = true) + private String day; + @JPos(index = 6,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 7) + private int alarmTotal; + @JPos(index = 8) + private int pushCount; + @JPos(index = 9) + private int aiCount; + @JPos(index = 10) + private int skynetCount; + @JPos(index = 11) + private int mdevCount; + + private String mode; + + public String tableName( ){ + return "iotserver_sensor_alarm_summary_table"; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorEventEntity.java new file mode 100644 index 0000000..f6f4b2a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorEventEntity.java @@ -0,0 +1,170 @@ +package com.jingyi.iotserver.firestationport.model.sensor.event; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SQLUpdateCmd; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SensorEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String eventid; + + @JPos(index = 1, timekey = true,orderkey = true) + private Date timestamp; + + @JPos(index = 2, filter = true) + private String deviceid; + + @JPos(index = 3, filter = true) + private String devicetype; + + @JPos(index = 4, filter = true) + private String deviceaddress; + + @JPos(index = 5, filter = true) + private String event; + + @JPos(index = 6, filter = true) + private String state; //created | assigned | processed | closed + + @JPos(index = 7,strlen = 1024) + private String description; + + @JPos(index=8,filter = true) + private String brigade; + @JPos(index=9,filter = true) + private String borough; + @JPos(index=10,filter = true) + private String detachment; + @JPos(index=11,filter = true) + private String station; + + private List operatelog; + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceaddress(String deviceaddress) { + this.deviceaddress = deviceaddress; + } + + public String getDeviceaddress() { + return deviceaddress; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setOperatelog(List operatelog) { + this.operatelog = operatelog; + } + + public List getOperatelog() { + return operatelog; + } + + public String tableName(){ + return "iotserver_sensor_event_table"; + } + + public boolean UpdateState(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"eventid",eventid); + cmd.appendValue("state",state); + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + return true; + }catch (Exception e){ + + } + return false; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorEventProcessEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorEventProcessEntity.java new file mode 100644 index 0000000..6d51bf3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/event/SensorEventProcessEntity.java @@ -0,0 +1,100 @@ +package com.jingyi.iotserver.firestationport.model.sensor.event; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class SensorEventProcessEntity extends SQLDataObject { + @JPos(index = 0, filter = true) + private String eventid; + + @JPos(index = 1, timekey = true,orderkey = true) + private Date timestamp; + + @JPos(index = 2) + private String operator; + + @JPos(index = 3) + private String title; + + @JPos(index = 4, filter = true) + private String process; // created | assigned | processed | closed | addres + + @JPos(index = 5) + private String resourcelocate; + + @JPos(index = 6) + private String result; + + @JPos(index = 7,strlen = 1024) + private String description; + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setProcess(String process) { + this.process = process; + } + + public String getProcess() { + return process; + } + + public void setResourcelocate(String resourcelocate) { + this.resourcelocate = resourcelocate; + } + + public String getResourcelocate() { + return resourcelocate; + } + + public void setResult(String result) { + this.result = result; + } + + public String getResult() { + return result; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String tableName(){ + return "iotserver_sensor_event_process_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/gas/DataDescriptionEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/gas/DataDescriptionEntity.java new file mode 100644 index 0000000..ba831ce --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/gas/DataDescriptionEntity.java @@ -0,0 +1,71 @@ +package com.jingyi.iotserver.firestationport.model.sensor.gas; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class DataDescriptionEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String name; + @JPos(index = 1, primary = true,filter = true) + private String type; + @JPos(index = 2) + private String description; + @JPos(index = 3) + private String unit; + @JPos(index = 4) + private String alarm; + @JPos(index = 5) + private String comment; + + public String tableName() { + return "data_description_table"; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getAlarm() { + return alarm; + } + + public void setAlarm(String alarm) { + this.alarm = alarm; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/gas/GasJy14Data.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/gas/GasJy14Data.java new file mode 100644 index 0000000..b1de854 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/gas/GasJy14Data.java @@ -0,0 +1,133 @@ +package com.jingyi.iotserver.firestationport.model.sensor.gas; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class GasJy14Data { + private String deviceid; + private String owner; + + private Date timestamp; + + private String devicetype; + + private int power; + + private double temperature; + + private double humidity; + + private double tvoc; + + private double ch2o; + private double co2; + private double pm2d5; + private double pm10; + + private double pm1d0; + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public int getPower() { + return power; + } + + public void setPower(int power) { + this.power = power; + } + + public double getTemperature() { + return temperature; + } + + public void setTemperature(double temperature) { + this.temperature = temperature; + } + + public double getHumidity() { + return humidity; + } + + public void setHumidity(double humidity) { + this.humidity = humidity; + } + + public double getTvoc() { + return tvoc; + } + + public void setTvoc(double tvoc) { + this.tvoc = tvoc; + } + + public double getCh2o() { + return ch2o; + } + + public void setCh2o(double ch2o) { + this.ch2o = ch2o; + } + + public double getCo2() { + return co2; + } + + public void setCo2(double co2) { + this.co2 = co2; + } + + public double getPm2d5() { + return pm2d5; + } + + public void setPm2d5(double pm2d5) { + this.pm2d5 = pm2d5; + } + + public double getPm10() { + return pm10; + } + + public void setPm10(double pm10) { + this.pm10 = pm10; + } + + public double getPm1d0() { + return pm1d0; + } + + public void setPm1d0(double pm1d0) { + this.pm1d0 = pm1d0; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/pushalarm/PushAlarmPointEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/pushalarm/PushAlarmPointEntity.java new file mode 100644 index 0000000..0d884fc --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/pushalarm/PushAlarmPointEntity.java @@ -0,0 +1,501 @@ +package com.jingyi.iotserver.firestationport.model.sensor.pushalarm; + +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class PushAlarmPointEntity extends SQLDataObject { + + public static final String STATE_ON = "on"; + public static final String STATE_OFF = "off"; + + public static final String Translate_On = "on"; + public static final String Translate_OFF = "off"; + + public static final String Device_TYPE_DeShangAn = "de_shang_an"; + public static final String Device_TYPE_PBA = "PBA"; + + @JPos(index = 0,primary = true, filter = true) + private String pointId; + @JPos(index = 1,filter = true) + private String account; + @JPos(index = 2,filter = true) + private String pointCode; + @JPos(index = 3) + private String pointName; + @JPos(index = 4) + private String pointAddress; + @JPos(index = 5) + private String sensorType; + @JPos(index = 6) + private int sensorCount; + @JPos(index = 7) + private String subCode; + @JPos(index = 8,filter = true) + private String status; + @JPos(index = 9) + private String alarmType; + @JPos(index = 10) + private Date setupTime; + @JPos(index = 11) + private String ip; + @JPos(index = 12, filter = true) + private String dwbs; + @JPos(index = 13, filter = true) + private String dwmc; + @JPos(index = 14) + private String dwdz; + @JPos(index = 15) + private String sfnb; + @JPos(index = 16) + private String userName; + @JPos(index = 17) + private String userPhone; + @JPos(index = 18) + private double latitude; + @JPos(index = 19) + private double longitude; + @JPos(index = 20) + private String hylxdm; + @JPos(index = 21) + private String hylx; + @JPos(index = 22) + private String zdjbdm; + @JPos(index = 23) + private String zdjb; + @JPos(index = 24) + private String fenceData; + @JPos(index = 25,filter = true) + private String needTranslate; + @JPos(index = 26) + private String user2Name; + @JPos(index = 27) + private String user2Phone; + @JPos(index = 28) + private String user3Name; + @JPos(index = 29) + private String user3Phone; + @JPos(index = 30) + private String linkISC; + @JPos(index = 31) + private String linkICC; + @JPos(index = 32) + private String linkAgora; + + @JPos(index=33,filter = true) + private String deviceType; + @JPos(index=34,filter = true) + private String deviceId; + + @JPos(index=35,filter = true) + private String station; + @JPos(index=36,filter = true) + private String brigade; + @JPos(index=37,filter = true) + private String borough; + @JPos(index=38,filter = true) + private String detachment; + @JPos(index=39,filter = true) + private String city; + @JPos(index=40,filter = true) + private String district; + @JPos(index=41,filter = true) + private String town; + @JPos(index=42,filter = true) + private String street; + + + public String tableName() { + return "push_alarm_point_table"; + } + + public String getDwbs() { + return dwbs; + } + + public void setDwbs(String dwbs) { + this.dwbs = dwbs; + } + + public String getDwmc() { + return dwmc; + } + + public void setDwmc(String dwmc) { + this.dwmc = dwmc; + } + + public String getDwdz() { + return dwdz; + } + + public void setDwdz(String dwdz) { + this.dwdz = dwdz; + } + + public String getSfnb() { + return sfnb; + } + + public void setSfnb(String sfnb) { + this.sfnb = sfnb; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserPhone() { + return userPhone; + } + + public void setUserPhone(String userPhone) { + this.userPhone = userPhone; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getFenceData() { + return fenceData; + } + + public void setFenceData(String fenceData) { + this.fenceData = fenceData; + } + + public String getHylxdm() { + return hylxdm; + } + + public void setHylxdm(String hylxdm) { + this.hylxdm = hylxdm; + } + + public String getHylx() { + return hylx; + } + + public void setHylx(String hylx) { + this.hylx = hylx; + } + + public String getZdjbdm() { + return zdjbdm; + } + + public void setZdjbdm(String zdjbdm) { + this.zdjbdm = zdjbdm; + } + + public String getZdjb() { + return zdjb; + } + + public void setZdjb(String zdjb) { + this.zdjb = zdjb; + } + + public String getNeedTranslate() { + return needTranslate; + } + + public void setNeedTranslate(String needTranslate) { + this.needTranslate = needTranslate; + } + + public String getPointId() { + return pointId; + } + + public void setPointId(String pointId) { + this.pointId = pointId; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getPointCode() { + return pointCode; + } + + public void setPointCode(String pointCode) { + this.pointCode = pointCode; + } + + public String getPointName() { + return pointName; + } + + public void setPointName(String pointName) { + this.pointName = pointName; + } + + public String getPointAddress() { + return pointAddress; + } + + public void setPointAddress(String pointAddress) { + this.pointAddress = pointAddress; + } + + public String getSensorType() { + return sensorType; + } + + public void setSensorType(String sensorType) { + this.sensorType = sensorType; + } + + public int getSensorCount() { + return sensorCount; + } + + public void setSensorCount(int sensorCount) { + this.sensorCount = sensorCount; + } + + public String getSubCode() { + return subCode; + } + + public void setSubCode(String subCode) { + this.subCode = subCode; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public Date getSetupTime() { + return setupTime; + } + + public void setSetupTime(Date setupTime) { + this.setupTime = setupTime; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getUser2Name() { + return user2Name; + } + + public void setUser2Name(String user2Name) { + this.user2Name = user2Name; + } + + public String getUser2Phone() { + return user2Phone; + } + + public void setUser2Phone(String user2Phone) { + this.user2Phone = user2Phone; + } + + public String getUser3Name() { + return user3Name; + } + + public void setUser3Name(String user3Name) { + this.user3Name = user3Name; + } + + public String getUser3Phone() { + return user3Phone; + } + + public void setUser3Phone(String user3Phone) { + this.user3Phone = user3Phone; + } + + public String getLinkISC() { + return linkISC; + } + + public void setLinkISC(String linkISC) { + this.linkISC = linkISC; + } + + public String getLinkICC() { + return linkICC; + } + + public void setLinkICC(String linkICC) { + this.linkICC = linkICC; + } + + public String getLinkAgora() { + return linkAgora; + } + + public void setLinkAgora(String linkAgora) { + this.linkAgora = linkAgora; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } + + public String getTown() { + return town; + } + + public void setTown(String town) { + this.town = town; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public static PushAlarmPointEntity QueryStationName(DataSource dataSource, String postName){ + PushAlarmPointEntity as = new PushAlarmPointEntity(); + String sql = "select * from "+as.tableName()+" where dwmc='"+postName+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,PushAlarmPointEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + public static PushAlarmPointEntity Query(DataSource dataSource, String devid) { + PushAlarmPointEntity sensor = new PushAlarmPointEntity(); + String sql = "select * from " + sensor.tableName() + " where deviceId='" + devid + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, PushAlarmPointEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static PushAlarmPointEntity QueryIt(DataSource dataSource, String pointId) { + PushAlarmPointEntity sensor = new PushAlarmPointEntity(); + String sql = "select * from " + sensor.tableName() + " where pointId='" + pointId + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, PushAlarmPointEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidAntDetectorEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidAntDetectorEntity.java new file mode 100644 index 0000000..438e639 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidAntDetectorEntity.java @@ -0,0 +1,51 @@ +package com.jingyi.iotserver.firestationport.model.sensor.rfid; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class RfidAntDetectorEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String rfidreader; + @JPos(index=1,primary = true,filter = true) + private int antid; + @JPos(index=2,filter = true) + private String community; + @JPos(index=3,filter = true) + private String detecttype; //income | goout | forbid + + public void setRfidreader(String rfidreader) { + this.rfidreader = rfidreader; + } + + public String getRfidreader() { + return rfidreader; + } + + public void setAntid(int antid) { + this.antid = antid; + } + + public int getAntid() { + return antid; + } + + public void setCommunity(String community) { + this.community = community; + } + + public String getCommunity() { + return community; + } + + public void setDetecttype(String detecttype) { + this.detecttype = detecttype; + } + + public String getDetecttype() { + return detecttype; + } + + public String tableName(){ + return "iotserver_rfid_ant_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidBuzEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidBuzEventEntity.java new file mode 100644 index 0000000..062403a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidBuzEventEntity.java @@ -0,0 +1,103 @@ +package com.jingyi.iotserver.firestationport.model.sensor.rfid; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class RfidBuzEventEntity extends SQLDataObject { + @JPos(index=0,filter = true) + private String rfid; + @JPos(index=1,filter = true) + private String plate; + @JPos(index=2,filter = true) + private String owner; + @JPos(index=3,filter = true) + private String event; // income | goout | forbid + @JPos(index=4,filter = true) + private String community; + @JPos(index=5,filter = true) + private String rfidreader; + @JPos(index=6,filter = true) + private int antid; + @JPos(index=7,filter = true) + private Date timestamp; + @JPos(index=8,filter = true) + private String station; + + public void setRfid(String rfid) { + this.rfid = rfid; + } + + public String getRfid() { + return rfid; + } + + public void setPlate(String plate) { + this.plate = plate; + } + + public String getPlate() { + return plate; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public void setRfidreader(String rfidreader) { + this.rfidreader = rfidreader; + } + + public String getRfidreader() { + return rfidreader; + } + + public int getAntid() { + return antid; + } + + public void setAntid(int antid) { + this.antid = antid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "iotserver_rfid_buz_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidEventEntity.java new file mode 100644 index 0000000..f141d31 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidEventEntity.java @@ -0,0 +1,96 @@ +package com.jingyi.iotserver.firestationport.model.sensor.rfid; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class RfidEventEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String deviceid; + @JPos(index = 1, filter = true) + private String owner; + @JPos(index = 2,timekey = true,orderkey = true) + protected Date firsttimestamp; + + @JPos(index = 3,filter = true) + private String rfidreader; + + @JPos(index = 4,filter = true) + private int antid; + @JPos(index = 5,filter = true) + private String status; + @JPos(index = 6,filter = true) + private String alarm; + + @JPos(index = 7,filter = true) + private String community; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public Date getFirsttimestamp() { + return firsttimestamp; + } + + public void setFirsttimestamp(Date firsttimestamp) { + this.firsttimestamp = firsttimestamp; + } + + public void setRfidreader(String rfidreader) { + this.rfidreader = rfidreader; + } + + public String getRfidreader() { + return rfidreader; + } + + public void setAntid(int antid) { + this.antid = antid; + } + + public int getAntid() { + return antid; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setAlarm(String alarm) { + this.alarm = alarm; + } + + public String getAlarm() { + return alarm; + } + + public void setCommunity(String community) { + this.community = community; + } + + public String getCommunity() { + return community; + } + + public String tableName(){ + return "iotserver_rfid_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidStateEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidStateEntity.java new file mode 100644 index 0000000..b08e067 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/rfid/RfidStateEntity.java @@ -0,0 +1,154 @@ +package com.jingyi.iotserver.firestationport.model.sensor.rfid; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class RfidStateEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String rfid; + @JPos(index=1,filter = true) + private String plate; + @JPos(index=2,filter = true) + private String owner; + + @JPos(index=3,filter = true) + private String phone; + @JPos(index=4,filter = true) + private String address; + @JPos(index=5,filter = true) + private String model; + @JPos(index=6,filter = true) + private int battery; + @JPos(index=7,filter = true) + private String state; // income | goout | forbid + @JPos(index=8,filter = true) + private String community; + @JPos(index=9,filter = true) + private String readerid; + @JPos(index=10,filter = true) + private int antid; + @JPos(index=11,filter = true) + private String status; + @JPos(index=12,filter = true) + private String alarm; + @JPos(index=13) + private Date firsttimestamp; + + public void setRfid(String rfid) { + this.rfid = rfid; + } + + public String getRfid() { + return rfid; + } + + public void setPlate(String plate) { + this.plate = plate; + } + + public String getPlate() { + return plate; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setBattery(int battery) { + this.battery = battery; + } + + public int getBattery() { + return battery; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setCommunity(String community) { + this.community = community; + } + + public String getCommunity() { + return community; + } + + public void setReaderid(String readerid) { + this.readerid = readerid; + } + + public String getReaderid() { + return readerid; + } + + public void setAntid(int antid) { + this.antid = antid; + } + + public int getAntid() { + return antid; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setAlarm(String alarm) { + this.alarm = alarm; + } + + public String getAlarm() { + return alarm; + } + + public void setFirsttimestamp(Date firsttimestamp) { + this.firsttimestamp = firsttimestamp; + } + + public Date getFirsttimestamp() { + return firsttimestamp; + } + + public String tableName(){ + return "iotserver_rfid_state_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/voice/AiVoiceDeviceInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/voice/AiVoiceDeviceInfo.java new file mode 100644 index 0000000..458f9f1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/voice/AiVoiceDeviceInfo.java @@ -0,0 +1,30 @@ +package com.jingyi.iotserver.firestationport.model.sensor.voice; + +import lombok.Data; + +@Data +public class AiVoiceDeviceInfo { + private int id; + private String DeviceType; + private String Name; + private String SerialNum; + private String Ip; + private int SoftwareVerNum; + private String SoftwareVer; + private String HardwareVer; + private String SipNum; + private String LicenseId; + private String Lng; + private String Lat; + private String Remark; + private String Linkman; + private String PhoneNum; + private String SetupLocation; + private int WithCamera; + private String OnlineTime; + private String AppState; + private String SipState; + private String WsState; + private String ProjectCode; + private String AvatarUrl; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/voice/AiVoiceReport.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/voice/AiVoiceReport.java new file mode 100644 index 0000000..f703a5f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/voice/AiVoiceReport.java @@ -0,0 +1,32 @@ +package com.jingyi.iotserver.firestationport.model.sensor.voice; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import lombok.Data; + +@Data +public class AiVoiceReport { + + public static final String ReportIndicate_Create = "created"; + public static final String ReportIndicate_Finished = "finished"; + + private String reportIndicate; + private String taskCode; + private String confSipCode; + private String deviceId; + private String deviceName; + private String deviceLicenseId; + private String deviceSipNum; + private AiVoiceDeviceInfo DeviceInfo; + + public void parseFormString(String srcData){ + JSONObject jsData = JSON.parseObject(srcData); + reportIndicate = jsData.getString("ReportIndicate"); + taskCode = jsData.getString("TaskCode"); + confSipCode = jsData.getString("ConfSipCode"); + deviceId = jsData.getString("DeviceId"); + deviceName = jsData.getString("DeviceName"); + deviceLicenseId = jsData.getString("DeviceLicenseId"); + deviceSipNum = jsData.getString("DeviceSipNum"); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/MaintainStaffBindEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/MaintainStaffBindEntity.java new file mode 100644 index 0000000..92c1b70 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/MaintainStaffBindEntity.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class MaintainStaffBindEntity extends SQLDataObject { + @JPos(index=0,filter = true,primary = true, strlen = 512) + private String bindId; + @JPos(index=1,filter = true) + private String staffId; + @JPos(index=2,filter = true) + private String station; + @JPos(index=3,timekey = true,orderkey = true) + private Date bindTime; + @JPos(index=4) + private String comment; + @JPos(index = 5,filter = true) + private String brigade; + @JPos(index = 6,filter = true) + private String detachment; + @JPos(index = 7,filter = true) + private String borough; + + public String tableName(){ + return "water_maintain_staff_bind_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/MaintainStaffEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/MaintainStaffEntity.java new file mode 100644 index 0000000..330764b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/MaintainStaffEntity.java @@ -0,0 +1,47 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class MaintainStaffEntity extends SQLDataObject { + @JPos(index=0,filter = true,primary = true) + private String staffId; + @JPos(index=1,filter = true) + private String staffName; + @JPos(index=2,filter = true) + private String phone; + @JPos(index=3,filter = true) + private String idCode; + @JPos(index=4) + private String gender; + @JPos(index=5,filter = true) + private String healthCertId; + @JPos(index=6,timekey = true) + private Date healthCertExpire; + @JPos(index=7,filter = true) + private String healthStatus; + @JPos(index=8,filter = true) + private String birthday; + @JPos(index=9,filter = true) + private String responseStation; + @JPos(index=10,filter = true) + private String staffTitle; + @JPos(index=11,filter = true) + private String station; + @JPos(index = 12,filter = true) + private String brigade; + @JPos(index = 13,filter = true) + private String detachment; + @JPos(index = 14,filter = true) + private String borough; + + private String companyName; + + public String tableName(){ + return "water_maintain_staff_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFilterEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFilterEntity.java new file mode 100644 index 0000000..914aa79 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFilterEntity.java @@ -0,0 +1,49 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class WaterFilterEntity extends SQLDataObject { + @JPos(index=0,filter = true,primary = true) + private String filterId; + @JPos(index=1,filter = true) + private String waterDeviceId; + @JPos(index=2) + private String filterNumber; + @JPos(index=3,filter = true) + private String model; + @JPos(index=4,timekey = true,orderkey = true) + private Date onTime; + @JPos(index=5) + private Date offTime; + @JPos(index=6,filter = true) + private String status; + + private long lifeHour; + + public String tableName(){ + return "water_filter_device_table"; + } + + public void setOffTime(Date offTime1){ + offTime = offTime1; + + if(offTime == null){ + lifeHour = -1; + return; + } + + Date nowTime = new Date(); + if(offTime.before(nowTime)){ + lifeHour = 0; + return; + } + + lifeHour = (offTime.getTime() - nowTime.getTime())/3600000; + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowDayEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowDayEntity.java new file mode 100644 index 0000000..c689e19 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowDayEntity.java @@ -0,0 +1,56 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class WaterFlowDayEntity extends SQLDataObject { + @JPos(index=0,filter = true, primary = true) + private String recordId; + @JPos(index=1,filter = true) + private String waterDeviceId; + @JPos(index=2,filter = true) + private String year; + @JPos(index=3,filter = true) + private String month; + @JPos(index=4,filter = true) + private String day; + @JPos(index=5,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index=6) + private long flow; + @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String detachment; + @JPos(index = 9,filter = true) + private String borough; + @JPos(index=10,filter = true) + private String station; + + public String tableName(){ + return "water_flow_device_day_table"; + } + + public WaterFlowDayEntity(){ + + } + + public WaterFlowDayEntity(WaterFlowInfoEntity flowInfoEntity, String nYear, String nMonth, String nDay){ + waterDeviceId = flowInfoEntity.getWaterDeviceId(); + year = nYear; + month = nMonth; + day = nDay; + timestamp = flowInfoEntity.getTimestamp(); + flow = flowInfoEntity.getFlow(); + brigade = flowInfoEntity.getBrigade(); + detachment = flowInfoEntity.getDetachment(); + borough = flowInfoEntity.getBorough(); + station = flowInfoEntity.getStation(); + + recordId = waterDeviceId + "_" + year+ "_" + month+ "_" + day; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowHourEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowHourEntity.java new file mode 100644 index 0000000..587b7de --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowHourEntity.java @@ -0,0 +1,61 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; +import java.util.UUID; + +@Data +public class WaterFlowHourEntity extends SQLDataObject { + @JPos(index=0,filter = true, primary = true) + private String recordId; + @JPos(index=1,filter = true) + private String waterDeviceId; + @JPos(index=2,filter = true) + private String year; + @JPos(index=3,filter = true) + private String month; + @JPos(index=4,filter = true) + private String day; + @JPos(index=5,filter = true) + private String hour; + @JPos(index=6,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index=7) + private long flow; + @JPos(index = 8,filter = true) + private String brigade; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index=11,filter = true) + private String station; + + public String tableName(){ + return "water_flow_device_hour_table"; + } + + public WaterFlowHourEntity(){ + + } + + public WaterFlowHourEntity(WaterFlowInfoEntity flowInfoEntity, String nYear, String nMonth, String nDay, String nHour){ + waterDeviceId = flowInfoEntity.getWaterDeviceId(); + year = nYear; + month = nMonth; + day = nDay; + hour = nHour; + timestamp = flowInfoEntity.getTimestamp(); + flow = flowInfoEntity.getFlow(); + brigade = flowInfoEntity.getBrigade(); + detachment = flowInfoEntity.getDetachment(); + borough = flowInfoEntity.getBorough(); + station = flowInfoEntity.getStation(); + + recordId = waterDeviceId + "_" + year+ "_" + month+ "_" + day+ "_" + hour; + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowInfoEntity.java new file mode 100644 index 0000000..a99ed94 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowInfoEntity.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class WaterFlowInfoEntity extends SQLDataObject { + @JPos(index = 0, primary = true,filter = true) + private String recordId; + @JPos(index = 1, filter = true) + private String waterDeviceId; + @JPos(index=2) + private long flow; + @JPos(index=3,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 4,filter = true) + private String brigade; + @JPos(index = 5,filter = true) + private String detachment; + @JPos(index = 6,filter = true) + private String borough; + @JPos(index=7,filter = true) + private String station; + + public String tableName(){ + return "water_flow_event_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowMonthEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowMonthEntity.java new file mode 100644 index 0000000..55bb2d5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowMonthEntity.java @@ -0,0 +1,53 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class WaterFlowMonthEntity extends SQLDataObject { + @JPos(index=0,filter = true, primary = true) + private String recordId; + @JPos(index=1,filter = true) + private String waterDeviceId; + @JPos(index=2,filter = true) + private String year; + @JPos(index=3,filter = true) + private String month; + @JPos(index=4,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index=5) + private long flow; + @JPos(index = 6,filter = true) + private String brigade; + @JPos(index = 7,filter = true) + private String detachment; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index=9,filter = true) + private String station; + + public String tableName(){ + return "water_flow_device_month_table"; + } + + public WaterFlowMonthEntity(){ + + } + + public WaterFlowMonthEntity(WaterFlowInfoEntity flowInfoEntity, String nYear, String nMonth){ + waterDeviceId = flowInfoEntity.getWaterDeviceId(); + year = nYear; + month = nMonth; + timestamp = flowInfoEntity.getTimestamp(); + flow = flowInfoEntity.getFlow(); + brigade = flowInfoEntity.getBrigade(); + detachment = flowInfoEntity.getDetachment(); + borough = flowInfoEntity.getBorough(); + station = flowInfoEntity.getStation(); + + recordId = waterDeviceId + "_" + year+ "_" + month; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowSum.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowSum.java new file mode 100644 index 0000000..6b9ae87 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/water/WaterFlowSum.java @@ -0,0 +1,19 @@ +package com.jingyi.iotserver.firestationport.model.sensor.water; + +import com.jingyi.iotserver.utils.JPos; +import lombok.Data; + +import java.util.Date; + +@Data +public class WaterFlowSum { + + private String brigade; + private String detachment; + private String borough; + private String station; + + private long flowCurDay; + private long flowCurMonth; + private long flowCurYear; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/HikvisionIPCEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/HikvisionIPCEntity.java new file mode 100644 index 0000000..682978a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/HikvisionIPCEntity.java @@ -0,0 +1,452 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + + +/* +{ +"altitude\":null, +"cameraIndexCode\":\"6b01d387b3ad4474a36fcb47e983d9d8\", +"cameraName\":\"湘江新区管理委员会6栋入口\", +"cameraType\":0, +"cameraTypeName\":\"枪机\", +"capabilitySet\":\"event_vss,io,vss,record,event_rule,remote_vss,maintenance,event_device,status\", +"capabilitySetName\":\"视频事件能力,IO能力,视频能力,录像能力,行为分析事件能力,视频设备远程获取能力,设备维护能力,设备事件能力,状态能力\", +"intelligentSet\":null, +"intelligentSetName\":null, +"channelNo\":\"1\", +"channelType\":\"analog\", +"channelTypeName\":\"模拟通道\", +"createTime\":\"2023-06-02T11:58:30.252+08:00\", +"encodeDevIndexCode\":\"5ca763da71184886a0f4d4b14d633719\", +"encodeDevResourceType\":null, +"encodeDevResourceTypeName\":null, +"gbIndexCode\":\"43010000581314000483\", +"installLocation\":null, +"keyBoardCode\":null, +"latitude\":null, +"longitude\":null, +"pixel\":null, +"ptz\":null, +"ptzName\":null, +"ptzController\":null, +"ptzControllerName\":null, +"recordLocation\":null, +"recordLocationName\":null, +"regionIndexCode\":\"d2cbd5b7-54f7-475e-8ecb-6402cf7eb2f5\", +"status\":null, +"statusName\":null, +"transType\":1, +"transTypeName\":\"TCP\", +"treatyType\":null, +"treatyTypeName\":null, +"viewshed\":null, +"updateTime\":\"2023-06-02T11:59:48.294+08:00\" +} + + */ + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class HikvisionIPCEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String cameraIndexCode; + @JPos(index = 1,filter = true) + private String cameraName; + @JPos(index = 2,filter = true) + private int cameraType; + @JPos(index = 3,filter = true) + private String cameraTypeName; + + @JPos(index = 4,filter = true) + private String station; + @JPos(index = 5,filter = true) + private String brigade; + @JPos(index = 6,filter = true) + private String detachment; + @JPos(index = 7,filter = true) + private String borough; + + @JPos(index = 8,filter = true) + private String channelNo; + @JPos(index = 9,filter = true) + private String channelType; + @JPos(index = 10,filter = true) + private String channelTypeName; + @JPos(index = 11) + private String createTime; + @JPos(index = 12) + private String encodeDevIndexCode; + @JPos(index = 13) + private String encodeDevResourceType; + @JPos(index = 14) + private String encodeDevResourceTypeName; + @JPos(index = 15,filter = true) + private String gbIndexCode; + @JPos(index = 16) + private String installLocation; + @JPos(index = 17) + private String keyBoardCode; + @JPos(index = 18) + private String latitude; + @JPos(index = 19) + private String longitude; + @JPos(index = 20) + private String altitude; + @JPos(index = 21) + private String pixel; + @JPos(index = 22) + private String ptz; + @JPos(index = 23) + private String ptzName; + @JPos(index = 24) + private String ptzController; + @JPos(index = 25) + private String ptzControllerName; + @JPos(index = 26) + private String recordLocation; + @JPos(index = 27) + private String recordLocationName; + @JPos(index = 28,filter = true) + private String regionIndexCode; + @JPos(index = 29) + private String status; + @JPos(index = 30) + private String statusName; + @JPos(index = 31) + private int transType; + @JPos(index = 32,filter = true) + private String transTypeName; + @JPos(index = 33) + private String treatyType; + @JPos(index = 34) + private String treatyTypeName; + @JPos(index = 35) + private String viewshed; + @JPos(index = 36) + private String updateTime; + @JPos(index = 37) + private String platformType; + @JPos(index = 38) + private String zoneIndex; + + public String tableName(){ + return "hikvision_ipc_table"; + } + + public HikvisionIPCEntity(String cameraIndexCode1){ + cameraIndexCode = cameraIndexCode1; + } + public HikvisionIPCEntity( ){ + } + public String getAltitude() { + return altitude; + } + + public void setAltitude(String altitude) { + this.altitude = altitude; + } + + public String getCameraIndexCode() { + return cameraIndexCode; + } + + public void setCameraIndexCode(String cameraIndexCode) { + this.cameraIndexCode = cameraIndexCode; + } + + public String getCameraName() { + return cameraName; + } + + public void setCameraName(String cameraName) { + this.cameraName = cameraName; + } + + public int getCameraType() { + return cameraType; + } + + public void setCameraType(int cameraType) { + this.cameraType = cameraType; + } + + public String getCameraTypeName() { + return cameraTypeName; + } + + public void setCameraTypeName(String cameraTypeName) { + this.cameraTypeName = cameraTypeName; + } + + public String getChannelNo() { + return channelNo; + } + + public void setChannelNo(String channelNo) { + this.channelNo = channelNo; + } + + public String getChannelType() { + return channelType; + } + + public void setChannelType(String channelType) { + this.channelType = channelType; + } + + public String getChannelTypeName() { + return channelTypeName; + } + + public void setChannelTypeName(String channelTypeName) { + this.channelTypeName = channelTypeName; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getEncodeDevIndexCode() { + return encodeDevIndexCode; + } + + public void setEncodeDevIndexCode(String encodeDevIndexCode) { + this.encodeDevIndexCode = encodeDevIndexCode; + } + + public String getEncodeDevResourceType() { + return encodeDevResourceType; + } + + public void setEncodeDevResourceType(String encodeDevResourceType) { + this.encodeDevResourceType = encodeDevResourceType; + } + + public String getEncodeDevResourceTypeName() { + return encodeDevResourceTypeName; + } + + public void setEncodeDevResourceTypeName(String encodeDevResourceTypeName) { + this.encodeDevResourceTypeName = encodeDevResourceTypeName; + } + + public String getGbIndexCode() { + return gbIndexCode; + } + + public void setGbIndexCode(String gbIndexCode) { + this.gbIndexCode = gbIndexCode; + } + + public String getInstallLocation() { + return installLocation; + } + + public void setInstallLocation(String installLocation) { + this.installLocation = installLocation; + } + + public String getKeyBoardCode() { + return keyBoardCode; + } + + public void setKeyBoardCode(String keyBoardCode) { + this.keyBoardCode = keyBoardCode; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getPixel() { + return pixel; + } + + public void setPixel(String pixel) { + this.pixel = pixel; + } + + public String getPtz() { + return ptz; + } + + public void setPtz(String ptz) { + this.ptz = ptz; + } + + public String getPtzName() { + return ptzName; + } + + public void setPtzName(String ptzName) { + this.ptzName = ptzName; + } + + public String getPtzController() { + return ptzController; + } + + public void setPtzController(String ptzController) { + this.ptzController = ptzController; + } + + public String getPtzControllerName() { + return ptzControllerName; + } + + public void setPtzControllerName(String ptzControllerName) { + this.ptzControllerName = ptzControllerName; + } + + public String getRecordLocation() { + return recordLocation; + } + + public void setRecordLocation(String recordLocation) { + this.recordLocation = recordLocation; + } + + public String getRecordLocationName() { + return recordLocationName; + } + + public void setRecordLocationName(String recordLocationName) { + this.recordLocationName = recordLocationName; + } + + public String getRegionIndexCode() { + return regionIndexCode; + } + + public void setRegionIndexCode(String regionIndexCode) { + this.regionIndexCode = regionIndexCode; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + + public int getTransType() { + return transType; + } + + public void setTransType(int transType) { + this.transType = transType; + } + + public String getTransTypeName() { + return transTypeName; + } + + public void setTransTypeName(String transTypeName) { + this.transTypeName = transTypeName; + } + + public String getTreatyType() { + return treatyType; + } + + public void setTreatyType(String treatyType) { + this.treatyType = treatyType; + } + + public String getTreatyTypeName() { + return treatyTypeName; + } + + public void setTreatyTypeName(String treatyTypeName) { + this.treatyTypeName = treatyTypeName; + } + + public String getViewshed() { + return viewshed; + } + + public void setViewshed(String viewshed) { + this.viewshed = viewshed; + } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getPlatformType() { + return platformType; + } + + public void setPlatformType(String platformType) { + this.platformType = platformType; + } + + public String getZoneIndex() { + return zoneIndex; + } + + public void setZoneIndex(String zoneIndex) { + this.zoneIndex = zoneIndex; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmBody.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmBody.java new file mode 100644 index 0000000..663a561 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmBody.java @@ -0,0 +1,159 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +import java.util.List; + +public class YsAlarmBody { + private int crypt; + private String alarmTime; + private int channel; + private int channelType; + private String relationId; + private String customInfo; + private long requestTime; + private String devSerial; + private String alarmType; + private String customType; + private String alarmId; + private String checksum; + private String channelName; + private String location; + private String describe; + private List pictureList; + private int status; + + public int getCrypt() { + return crypt; + } + + public void setCrypt(int crypt) { + this.crypt = crypt; + } + + public String getAlarmTime() { + return alarmTime; + } + + public void setAlarmTime(String alarmTime) { + this.alarmTime = alarmTime; + } + + public int getChannel() { + return channel; + } + + public void setChannel(int channel) { + this.channel = channel; + } + + public int getChannelType() { + return channelType; + } + + public void setChannelType(int channelType) { + this.channelType = channelType; + } + + public String getRelationId() { + return relationId; + } + + public void setRelationId(String relationId) { + this.relationId = relationId; + } + + public String getCustomInfo() { + return customInfo; + } + + public void setCustomInfo(String customInfo) { + this.customInfo = customInfo; + } + + public long getRequestTime() { + return requestTime; + } + + public void setRequestTime(long requestTime) { + this.requestTime = requestTime; + } + + public String getDevSerial() { + return devSerial; + } + + public void setDevSerial(String devSerial) { + this.devSerial = devSerial; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public String getCustomType() { + return customType; + } + + public void setCustomType(String customType) { + this.customType = customType; + } + + public String getAlarmId() { + return alarmId; + } + + public void setAlarmId(String alarmId) { + this.alarmId = alarmId; + } + + public String getChecksum() { + return checksum; + } + + public void setChecksum(String checksum) { + this.checksum = checksum; + } + + public String getChannelName() { + return channelName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getDescribe() { + return describe; + } + + public void setDescribe(String describe) { + this.describe = describe; + } + + public List getPictureList() { + return pictureList; + } + + public void setPictureList(List pictureList) { + this.pictureList = pictureList; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmCutoutEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmCutoutEntity.java new file mode 100644 index 0000000..097e95a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmCutoutEntity.java @@ -0,0 +1,186 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.io.UnsupportedEncodingException; +import java.util.Calendar; +import java.util.Date; + +public class YsAlarmCutoutEntity extends SQLDataObject { + + @JPos(index = 0,primary = true,filter = true) + private String deviceId; + @JPos(index = 1,primary = true,filter = true) + private String cutoutId; + @JPos(index=2,filter = true) + private String roomInfo; + @JPos(index = 3) + private String messageId; + + @JPos(index = 4,timekey = true, orderkey = true) + private Date receiveTime; + + @JPos(index = 5,filter = true) + private String channelName; + @JPos(index = 6) + private String pictureId; + @JPos(index = 7,strlen = 2048) + private String pictureUrl; + + @JPos(index = 8,filter = true) + private String brigade; + @JPos(index = 9,filter = true) + private String detachment; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index=11,filter = true) + private String station; + @JPos(index = 12,strlen = 512) + private String localUrl; + + public String tableName(){ + return "ys_alarm_cutout_table"; + } + + public YsAlarmCutoutEntity(){ + + } + + public YsAlarmCutoutEntity(YsAlarmEntity ysHeader, YsIPCEntity ysIPC){ + messageId = ysHeader.getMessageId(); + deviceId = ysHeader.getDeviceId(); + roomInfo = ysIPC.getRoomInfo(); + messageId = ysHeader.getMessageId(); + receiveTime = ysHeader.getReceiveTime(); + channelName = ysHeader.getChannelName(); + pictureId = ysHeader.getPictureId(); + pictureUrl = ysHeader.getPictureUrl(); + brigade = ysHeader.getBrigade(); + detachment = ysHeader.getDetachment(); + borough = ysHeader.getBorough(); + station = ysHeader.getStation(); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(receiveTime); + + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + int day = calendar.get(Calendar.DATE); + + int hour = calendar.get(Calendar.HOUR_OF_DAY); + int minute = calendar.get(Calendar.MINUTE)/10; + + cutoutId = deviceId + "_" + year + month + day + hour + minute; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + + public Date getReceiveTime() { + return receiveTime; + } + + public void setReceiveTime(Date receiveTime) { + this.receiveTime = receiveTime; + } + + + + public String getChannelName() { + return channelName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public String getPictureId() { + return pictureId; + } + + public void setPictureId(String pictureId) { + this.pictureId = pictureId; + } + + public String getPictureUrl() { + return pictureUrl; + } + + public void setPictureUrl(String pictureUrl) { + this.pictureUrl = pictureUrl; + } + + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getCutoutId() { + return cutoutId; + } + + public void setCutoutId(String cutoutId) { + this.cutoutId = cutoutId; + } + + public String getRoomInfo() { + return roomInfo; + } + + public void setRoomInfo(String roomInfo) { + this.roomInfo = roomInfo; + } + + public String getLocalUrl() { + return localUrl; + } + + public void setLocalUrl(String localUrl) { + this.localUrl = localUrl; + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmEntity.java new file mode 100644 index 0000000..ceb403e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsAlarmEntity.java @@ -0,0 +1,254 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.io.UnsupportedEncodingException; +import java.util.Base64; +import java.util.Date; + +public class YsAlarmEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String messageId; + @JPos(index = 1,filter = true) + private String alarmId; + @JPos(index = 2,filter = true) + private String messageType; + @JPos(index = 3,filter = true) + private String deviceId; + @JPos(index = 4) + private int channelNo; + @JPos(index = 5,timekey = true, orderkey = true) + private Date receiveTime; + @JPos(index = 6) + private String alarmTime; + @JPos(index = 7,filter = true) + private String alarmType; + @JPos(index = 8,filter = true) + private String channelName; + @JPos(index = 9) + private String pictureId; + @JPos(index = 10,strlen = 2048) + private String pictureUrl; + @JPos(index = 11) + private String readState; + @JPos(index = 12) + private Date readTime; + + @JPos(index = 13,filter = true) + private String brigade; + @JPos(index = 14,filter = true) + private String detachment; + @JPos(index = 15,filter = true) + private String borough; + @JPos(index=16,filter = true) + private String station; + @JPos(index=17,filter = true) + private String address; + @JPos(index=18,floatthreshold = -1.0f) + private double longitude; + @JPos(index=19,floatthreshold = -1.0f) + private double latitude; + + @JPos(index = 20,strlen = 512) + private String localUrl; + + public String tableName(){ + return "ys_alarm_table"; + } + + public YsAlarmEntity(){ + + } + + public YsAlarmEntity(YsHeader ysHeader, YsAlarmBody body){ + messageId = ysHeader.getMessageId(); + alarmId = body.getAlarmId(); + messageType = ysHeader.getType(); + deviceId = ysHeader.getDeviceId(); + channelNo = ysHeader.getChannelNo(); + receiveTime = new Date(); + alarmTime = body.getAlarmTime(); + alarmType = body.getAlarmType(); + channelName = body.getChannelName(); + if(body.getPictureList() != null && body.getPictureList().size() > 0){ + YsPicture pic = body.getPictureList().get(0); + pictureId = pic.getId(); + try { + pictureUrl =org.apache.commons.codec.binary.Base64.encodeBase64String(pic.getUrl().getBytes("UTF8")) ; + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAlarmId() { + return alarmId; + } + + public void setAlarmId(String alarmId) { + this.alarmId = alarmId; + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public int getChannelNo() { + return channelNo; + } + + public void setChannelNo(int channelNo) { + this.channelNo = channelNo; + } + + public Date getReceiveTime() { + return receiveTime; + } + + public void setReceiveTime(Date receiveTime) { + this.receiveTime = receiveTime; + } + + public String getAlarmTime() { + return alarmTime; + } + + public void setAlarmTime(String alarmTime) { + this.alarmTime = alarmTime; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public String getChannelName() { + return channelName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public String getPictureId() { + return pictureId; + } + + public void setPictureId(String pictureId) { + this.pictureId = pictureId; + } + + public String getPictureUrl() { + return pictureUrl; + } + + public void setPictureUrl(String pictureUrl) { + this.pictureUrl = pictureUrl; + } + + public String getReadState() { + return readState; + } + + public void setReadState(String readState) { + this.readState = readState; + } + + public Date getReadTime() { + return readTime; + } + + public void setReadTime(Date readTime) { + this.readTime = readTime; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public String getLocalUrl() { + return localUrl; + } + + public void setLocalUrl(String localUrl) { + this.localUrl = localUrl; + } +} + diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsHeader.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsHeader.java new file mode 100644 index 0000000..da1177e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsHeader.java @@ -0,0 +1,60 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +import com.jingyi.iotserver.utils.SpringContextUtil; + +import java.util.Date; + +/* + "channelNo": 1, + "deviceId": "D98462102", + "messageId": "5e57f239793f2b007fecb0de", + "messageTime": 1582821945396, + "type": "ys.open.isapi" + */ +public class YsHeader { + private int channelNo; + private String deviceId; + private String messageId; + private long messageTime; + private String type; + + public int getChannelNo() { + return channelNo; + } + + public void setChannelNo(int channelNo) { + this.channelNo = channelNo; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public long getMessageTime() { + return messageTime; + } + + public void setMessageTime(long messageTime) { + this.messageTime = messageTime; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsIPCEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsIPCEntity.java new file mode 100644 index 0000000..56f9b27 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsIPCEntity.java @@ -0,0 +1,173 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class YsIPCEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true) + private String deviceId; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + @JPos(index=4,filter = true) + private String station; + @JPos(index=5) + private String address; + @JPos(index=6) + private String userName; + @JPos(index=7) + private String userPhone; + @JPos(index=8) + private String decorationName; + @JPos(index=9) + private String decorationPhone; + @JPos(index=10, timekey = true) + private Date startTime; + @JPos(index=11,filter = true) + private String roomInfo; + @JPos(index=12,floatthreshold = -1.0f) + private double longitude; + @JPos(index=13,floatthreshold = -1.0f) + private double latitude; + @JPos(index = 14,strlen = 2048) + private String pictureUrl; + @JPos(index=15, timekey = true) + private Date pictureTime; + + public String tableName(){ + return "ys_ipc_device_table"; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserPhone() { + return userPhone; + } + + public void setUserPhone(String userPhone) { + this.userPhone = userPhone; + } + + public String getDecorationName() { + return decorationName; + } + + public void setDecorationName(String decorationName) { + this.decorationName = decorationName; + } + + public String getDecorationPhone() { + return decorationPhone; + } + + public void setDecorationPhone(String decorationPhone) { + this.decorationPhone = decorationPhone; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public String getRoomInfo() { + return roomInfo; + } + + public void setRoomInfo(String roomInfo) { + this.roomInfo = roomInfo; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public String getPictureUrl() { + return pictureUrl; + } + + public void setPictureUrl(String pictureUrl) { + this.pictureUrl = pictureUrl; + } + + public Date getPictureTime() { + return pictureTime; + } + + public void setPictureTime(Date pictureTime) { + this.pictureTime = pictureTime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsPicture.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsPicture.java new file mode 100644 index 0000000..966f08e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsPicture.java @@ -0,0 +1,23 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +public class YsPicture { + private String id; + private String url; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsTokenEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsTokenEntity.java new file mode 100644 index 0000000..9bfb911 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/sensor/ys/YsTokenEntity.java @@ -0,0 +1,62 @@ +package com.jingyi.iotserver.firestationport.model.sensor.ys; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class YsTokenEntity extends SQLDataObject { + + @JPos(index = 0,primary = true, filter = true) + private String appKey; + @JPos(index = 1, strlen = 512) + private String appSecret; + @JPos(index = 2, strlen = 512) + private String accessToken; + @JPos(index = 3) + private long expireTime; + @JPos(index = 4, strlen = 512) + private String appState; + + public String tableName(){ + return "ys_token_table"; + } + + public String getAppKey() { + return appKey; + } + + public void setAppKey(String appKey) { + this.appKey = appKey; + } + + public String getAppSecret() { + return appSecret; + } + + public void setAppSecret(String appSecret) { + this.appSecret = appSecret; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public long getExpireTime() { + return expireTime; + } + + public void setExpireTime(long expireTime) { + this.expireTime = expireTime; + } + + public String getAppState() { + return appState; + } + + public void setAppState(String appState) { + this.appState = appState; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/CommonDefine.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/CommonDefine.java new file mode 100644 index 0000000..ab2e8b9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/CommonDefine.java @@ -0,0 +1,7 @@ +package com.jingyi.iotserver.firestationport.model.station; + +public class CommonDefine { + public static final String STATION_INDUSTRY_EDU = "education"; + public static final String STATION_INDUSTRY_BANK = "bank"; + public static final String STATION_INDUSTRY_HOSPITAL = "hospital"; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireMediaInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireMediaInfoEntity.java new file mode 100644 index 0000000..9aa0559 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireMediaInfoEntity.java @@ -0,0 +1,162 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; +import java.util.Date; + +public class FireMediaInfoEntity extends SQLDataObject{ + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,strlen=1024) + private String path;//路径 + @JPos(index = 2,strlen=4096) + private String url;//网络地址 + @JPos(index = 3,filter = true) + private String bucket;//项目名 + @JPos(index = 4,filter = true) + private String filename;//文件名 + @JPos(index = 5,filter = true) + private String filetype;//文件类型 jpg,mp4,pcm + @JPos(index = 6,primary = true,timekey = true,update = false,orderkey = true) + private Date createtime;//创建时间 + @JPos(index = 7) + private Date uploadtime;//上传时间ms + @JPos(index = 8,filter = true) + private String username;//设备用户名 + @JPos(index = 9) + private String address;//创建时地址 + @JPos(index = 10) + private double longitude; + @JPos(index = 11) + private double latitude; + @JPos(index = 12,filter = true) + private String title; + @JPos(index = 13,filter = true) + private String label; + @JPos(index = 14) + private String comment; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setPath(String path) { + this.path = path; + } + + public String getPath() { + return path; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUrl() { + return url; + } + + public void setBucket(String bucket) { + this.bucket = bucket; + } + + public String getBucket() { + return bucket; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getFilename() { + return filename; + } + + public void setFiletype(String filetype) { + this.filetype = filetype; + } + + public String getFiletype() { + return filetype; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setUploadtime(Date uploadtime) { + this.uploadtime = uploadtime; + } + + public Date getUploadtime() { + return uploadtime; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public String tableName(){ + return "firectrl_station_media_info_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationAlarmEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationAlarmEntity.java new file mode 100644 index 0000000..47f2011 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationAlarmEntity.java @@ -0,0 +1,185 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationAlarmEntity extends SQLDataObject{ + @JPos(index=0,primary = true,filter = true) + private String station; + @JPos(index=1,filter = true) + private String brigade; + @JPos(index=2,filter = true) + private String borough; + @JPos(index=3,filter = true) + private String detachment; + @JPos(index=4,primary = true,filter = true) + private String alarmid ; + @JPos(index=5,orderkey = true,timekey = true,update=false) + private Date timestamp; + + @JPos(index=6) + private double longitude ; + @JPos(index=7) + private double latitude ; + @JPos(index=8) + private String address; + @JPos(index=9) + private String notifytarget; + @JPos(index=10,filter = true) + private String state;//notified processed + @JPos(index=11) + private Date processtime; + @JPos(index=12,primary = true,filter = true) + private String sender; + @JPos(index=13,primary = true,filter = true) + private String phone; + @JPos(index=14,primary = true,filter = true) + private String type; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public String getAlarmid() { + return alarmid; + } + + public void setAlarmid(String alarmid) { + this.alarmid = alarmid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public String getNotifytarget() { + return notifytarget; + } + + public void setNotifytarget(String notifytarget) { + this.notifytarget = notifytarget; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setProcesstime(Date processtime) { + this.processtime = processtime; + } + + public Date getProcesstime() { + return processtime; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public String tableName(){ + return "firectrl_station_alarm_table"; + } + + + public boolean ProcessAllAlarm(DataSource dataSource){ + if(station==null) + return false; + state = "processed"; + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"station",station); + cmd.appendValue("state",state); + processtime = new Date(); + cmd.appendValue("processtime",processtime); + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + }catch (Exception e){ + + } + return true; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationAlarmProcessRecordEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationAlarmProcessRecordEntity.java new file mode 100644 index 0000000..3f97b23 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationAlarmProcessRecordEntity.java @@ -0,0 +1,77 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.firestationport.model.sensor.SmokingEventEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationAlarmProcessRecordEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,primary = true,filter = true) + private String alarmid ; + @JPos(index = 2,primary = true,timekey = true,orderkey = true,update = false) + private Date timestamp; + @JPos(index = 3) + private String operate; + @JPos(index = 4) + private String operator; + @JPos(index = 5,strlen = 4096) + private String content; + + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setAlarmid(String alarmid) { + this.alarmid = alarmid; + } + + public String getAlarmid() { + return alarmid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setOperate(String operate) { + this.operate = operate; + } + + public String getOperate() { + return operate; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public String tableName(){ + return "firectrl_station_alarm_process_record_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationBaseInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationBaseInfoEntity.java new file mode 100644 index 0000000..b8613bc --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationBaseInfoEntity.java @@ -0,0 +1,450 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +public class FireStationBaseInfoEntity extends SQLDataObject { + @JPos(index = 0,identify = true,orderkey = true) + private int number; + @JPos(index = 1,primary = true,filter = true) + private String name; + @JPos(index = 2,filter = true) + private String type; //幼儿园,小学,中学,大学 + @JPos(index = 3,filter = true) + private String brigade; + @JPos(index = 4,filter = true) + private String detachment; + @JPos(index = 5,filter = true) + private String orgname; + @JPos(index = 6) + private String nickname; + @JPos(index = 7) + private String nickname1; + @JPos(index = 8,filter = true) + private String level; //监管等级 + @JPos(index = 9) + private String address; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index = 11) + private String detail; + + @JPos(index = 12) + private String phone; + @JPos(index = 13) + private String legal_person; + @JPos(index = 14) + private String legal_person_phone; + @JPos(index = 15,timekey = true) + private Date createtime; + @JPos(index = 16) + private String device_id; + @JPos(index = 17) + private double area; + @JPos(index = 18) + private double heigh; + @JPos(index = 19) + private double longitude; + @JPos(index = 20) + private double latitude; + + @JPos(index = 21,filter = true) + private String ownertype;//公办民办 + + @JPos(index = 22,filter = true) + private String industry;//行业:教育,银行,医院... + @JPos(index = 23) + private String specially_police; + @JPos(index = 24) + private String specially_police_phone; + @JPos(index = 25) + private int roomCount; + @JPos(index = 26) + private int studentCount; + @JPos(index = 27) + private int teacherCount; + @JPos(index = 28) + private int guarderCount; + @JPos(index = 29) + private String comment; + @JPos(index = 30) + private String image; + + private BigDecimal sum; + + public void setNumber(int number) { + this.number = number; + } + + public int getNumber() { + return number; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setOrgname(String orgname) { + this.orgname = orgname; + } + + public String getOrgname() { + return orgname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + public String getNickname() { + return nickname; + } + + public void setNickname1(String nickname1) { + this.nickname1 = nickname1; + } + + public String getNickname1() { + return nickname1; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getLevel() { + return level; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetail(String detail) { + this.detail = detail; + } + + public String getDetail() { + return detail; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setLegal_person(String legal_person) { + this.legal_person = legal_person; + } + + public String getLegal_person() { + return legal_person; + } + + public void setLegal_person_phone(String legal_person_phone) { + this.legal_person_phone = legal_person_phone; + } + + public String getLegal_person_phone() { + return legal_person_phone; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setDevice_id(String device_id) { + this.device_id = device_id; + } + + public String getDevice_id() { + return device_id; + } + + public void setArea(double area) { + this.area = area; + } + + public double getArea() { + return area; + } + + public void setHeigh(double heigh) { + this.heigh = heigh; + } + + public double getHeigh() { + return heigh; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public int getRoomCount() { + return roomCount; + } + + public void setRoomCount(int roomCount) { + this.roomCount = roomCount; + } + + public int getStudentCount() { + return studentCount; + } + + public void setStudentCount(int studentCount) { + this.studentCount = studentCount; + } + + public int getTeacherCount() { + return teacherCount; + } + + public void setTeacherCount(int teacherCount) { + this.teacherCount = teacherCount; + } + + public int getGuarderCount() { + return guarderCount; + } + + public void setGuarderCount(int guarderCount) { + this.guarderCount = guarderCount; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public boolean checkScope(FireStationBaseInfoEntity in){ + if(brigade!=null&&in.brigade!=null){ + if(!brigade.equals(in.brigade)) + return false; + } + + if(borough!=null&&in.borough!=null){ + if(!borough.equals(in.borough)) + return false; + } + + if(detachment!=null&&in.detachment!=null){ + if(!detachment.equals(in.detachment)) + return false; + } + + if(name!=null&&in.name!=null){ + if(!name.equals(in.name)) + return false; + } + + return true; + } + public String tableName(){ + return "firectrl_station_info_table"; + } + + + public static FireStationBaseInfoEntity Query(DataSource dataSource,String name) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + String sql = "select * from " + info.tableName() + " where name='" + name + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, FireStationBaseInfoEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + + public static FireStationBaseInfoEntity QueryByDeviceID(DataSource dataSource,String deviceid) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + String sql = "select * from " + info.tableName() + " where device_id='" + deviceid + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, FireStationBaseInfoEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public String topic(){ + String topic = null; + if(brigade!=null) + topic = brigade; + if(borough!=null){ + if(topic==null) + topic = borough; + else + topic += "/"+borough; + } + if(detachment!=null){ + if(topic==null) + topic = detachment; + else + topic += "/"+detachment; + } + if(name!=null){ + if(topic==null) + topic = name; + else + topic += "/"+name; + } + return topic; + } + + public String getOwnertype() { + return ownertype; + } + + public void setOwnertype(String ownertype) { + this.ownertype = ownertype; + } + + public String getIndustry() { + return industry; + } + + public void setIndustry(String industry) { + this.industry = industry; + } + + public String getSpecially_police() { + return specially_police; + } + + public void setSpecially_police(String specially_police) { + this.specially_police = specially_police; + } + + public String getSpecially_police_phone() { + return specially_police_phone; + } + + public void setSpecially_police_phone(String specially_police_phone) { + this.specially_police_phone = specially_police_phone; + } + + + public static List searchPosition(DataSource dataSource,double lat, double lon, double dRange) { + double latTop = lat + dRange; + double latBottom = lat - dRange; + double lonRight = lon + dRange; + double lonLeft = lon - dRange; + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + //String sql = "select * from " + info.tableName() + " where longitude >= " + lonLeft + " and longitude <=" + lonRight + ; + String sql = "select * from firectrl_station_info_table where longitude>="+lonLeft+" and longitude<="+lonRight+" and latitude>="+latBottom+" and latitude<="+latTop; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, FireStationBaseInfoEntity.class); + if (list != null && list.size() > 0) { + return list; + } + } catch (Exception e) { + + } + return null; + } + + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + + public static BigDecimal querySumery(DataSource dataSource,String canshu) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + String sql = "select sum(studentCount) as sum from " + info.tableName() + " where brigade='" + canshu + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql,FireStationBaseInfoEntity.class); + return list.get(0).getSum(); + } catch (Exception e) { + e.printStackTrace(); + } + return new BigDecimal(0); + } + + public BigDecimal getSum() { + return sum; + } + + public void setSum(BigDecimal sum) { + this.sum = sum; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationBoundEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationBoundEntity.java new file mode 100644 index 0000000..e748f19 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationBoundEntity.java @@ -0,0 +1,59 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class FireStationBoundEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true,orderkey = true) + private String stationName; + @JPos(index = 1,strlen = 4096) + private String venue_bound; + @JPos(index = 2,strlen = 4096) + private String service_bound; + + public void setStationName(String stationName) { + this.stationName = stationName; + } + + public String getStationName() { + return stationName; + } + + public void setVenue_bound(String venue_bound) { + this.venue_bound = venue_bound; + } + + public String getVenue_bound() { + return venue_bound; + } + + public void setService_bound(String service_bound) { + this.service_bound = service_bound; + } + + public String getService_bound() { + return service_bound; + } + + public String tableName( ){ + return "firectrl_station_bound_table"; + } + + + public static FireStationBoundEntity Query(DataSource dataSource, String name) { + FireStationBoundEntity bound = new FireStationBoundEntity(); + String sql = "select * from " + bound.tableName() + " where stationName='" + name + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, FireStationBoundEntity.class); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + + } + return null; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationLineEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationLineEntity.java new file mode 100644 index 0000000..ba3d650 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationLineEntity.java @@ -0,0 +1,174 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.firestationport.model.sensor.SmokingBuzEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SmokingEventEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationLineEntity extends SQLDataObject { + @JPos(index = 0,identify = true) + private int id; + @JPos(index = 1,primary = true,filter = true) + private int station_number; + @JPos(index = 2,filter = true) + private String station_name; + @JPos(index = 3,primary = true,update = false,timekey = true) + private Date online; + @JPos(index = 4) + private Date offline; + + + private long lastActive; + public void setId(int id) { + this.id = id; + + } + + public int getId() { + return id; + } + + public void setStation_number(int station_number) { + this.station_number = station_number; + } + + public int getStation_number() { + return station_number; + } + + public void setStation_name(String station_name) { + this.station_name = station_name; + } + + public String getStation_name() { + return station_name; + } + + public void setOnline(Date online) { + this.online = online; + } + + public Date getOnline() { + return online; + } + + public void setOffline(Date offline) { + this.offline = offline; + } + + public Date getOffline() { + return offline; + } + + public void setLastActive(long lastActive) { + this.lastActive = lastActive; + } + + public long getLastActive() { + return lastActive; + } + + public String tableName(){ + return "firectrl_"+tableExtName+"_line_table"; + } + + public boolean Delete(DataSource dataSource){ + String sql = "DELETE FROM "+tableName()+" WHERE id="+id; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + public static FireStationLineEntity Query(DataSource dataSource,int number, Date time){ + FireStationLineEntity line = new FireStationLineEntity(); + try{ + line.extendName(""+number); + String sql = "select * from "+line.tableName()+" where online='"+ SQLTools.formatDate(time)+"'"; + + List list = SQLTools.ExecuteQuery(dataSource,sql,FireStationLineEntity.class); + if(list!=null&&list.size()>0) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + public static boolean IsOnline(DataSource dataSource,int number,Date time){ + FireStationLineEntity line = new FireStationLineEntity(); + line.extendName(""+number); + String str = SQLTools.formatDate(time); + String sql = "select count(*) from "+line.tableName()+" where offline>='"+str+"' and online<='"+str+"'"; + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + if(count>0) + return true; + }catch (Exception e){ + + } + return false; + } + + + public boolean UpdateEndTime(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"id",id); + cmd .appendValue("offline",offline); + try{ + return SQLTools.ExecuteSQL(dataSource, cmd.getSql()); + }catch (Exception e){ + + } + return false; + } + + public String getQueryCondition(){ + String condition = null; + if(station_name!=null&&!station_name.equals("null")&&station_name.length()>0){ + condition = " station_name='"+station_name+"'"; + } + + return condition; + } + + public int queryCount(DataSource dataSource,int number,String start ,String end){ + String condition = getQueryCondition(); + Date s = SQLTools.StrToDateTime(start); + Date e = SQLTools.StrToDateTime(end); + if(s==null||e==null) + return 0; + String sql = "select count(*) from "+tableName()+" where offline>='"+start+"' and online<='"+end+"'"; + if(condition!=null){ + sql += " and "+condition; + } + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + return count; + }catch (Exception ex){ + + } + return 0; + } + + public List queryPage(DataSource dataSource, String start , String end, int pageindex, int pagesize){ + String condition = getQueryCondition(); + String sql = "select * from "+tableName()+" where offline>='"+start+"' and online<='"+end+"'"; + if(condition!=null){ + sql += " and "+condition; + } + try{ + List list = SQLTools.queryPage(dataSource, FireStationLineEntity.class,sql,pageindex,pagesize,"online"); + return list; + }catch (Exception ex){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationMapInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationMapInfoEntity.java new file mode 100644 index 0000000..b891889 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationMapInfoEntity.java @@ -0,0 +1,111 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class FireStationMapInfoEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String mapid; + @JPos(index=1) + private int width; + @JPos(index=2) + private int height; + @JPos(index = 3) + private double longitude; + @JPos(index = 4) + private double latitude; + @JPos(index = 5,strlen = 4096) + private String vectordata; + @JPos(index=6,filter = true) + private String brigade; + @JPos(index=7,filter = true) + private String borough; + @JPos(index=8,filter = true) + private String detachment; + @JPos(index=9,primary = true,filter = true) + private String station; + + public void setMapid(String mapid) { + this.mapid = mapid; + } + + public String getMapid() { + return mapid; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getWidth() { + return width; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getHeight() { + return height; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setVectordata(String vectordata) { + this.vectordata = vectordata; + } + + public String getVectordata() { + return vectordata; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName( ){ + return "firectrl_station_map_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationPropertyEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationPropertyEntity.java new file mode 100644 index 0000000..182b86c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationPropertyEntity.java @@ -0,0 +1,80 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class FireStationPropertyEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String station; + @JPos(index = 1,primary = true,filter = true,orderkey = true) + private String name; + @JPos(index = 2,filter = true) + private String type; + @JPos(index = 3,strlen = 4096) + private String property; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setProperty(String property) { + this.property = property; + } + + public String getProperty() { + return property; + } + + public String tableName(){ + return "firectrl_station_property_table"; + } + + + public static FireStationPropertyEntity QueryProperty(DataSource dataSource, String station,String name){ + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + pro.setName(name); + pro.setStation(station); + return (FireStationPropertyEntity)pro.QueryIt(dataSource); + } + + public boolean addProperty(DataSource dataSource){ + + if(QueryProperty(dataSource,station,name)!=null){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"station",station); + cmd.appendKey("name",name); + cmd.appendValue("property",property); + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + }catch (Exception e){ + + } + return true; + }else{ + return Insert(dataSource); + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationRuntimeStatusCacheEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationRuntimeStatusCacheEntity.java new file mode 100644 index 0000000..25bd047 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationRuntimeStatusCacheEntity.java @@ -0,0 +1,285 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class FireStationRuntimeStatusCacheEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true,orderkey = true) + private String station; + @JPos(index = 1,threshold = -1) + private int questdone; + @JPos(index = 2,threshold = -1) + private int questtotal; + @JPos(index = 3,threshold = -1) + private int notifyreaded; + @JPos(index = 4,threshold = -1) + private int notifytotal; + @JPos(index = 5,threshold = -1) + private int alarmin; + @JPos(index = 6,threshold = -1) + private int alarmout; + @JPos(index = 7,threshold = -1) + private int onduration; + @JPos(index = 7,threshold = -1) + private int runduration; + @JPos(index = 8,threshold = -1) + private int dutyduration; + @JPos(index = 9,threshold = -1) + private int rollcallin; + @JPos(index = 10,threshold = -1) + private int rollcallack; + @JPos(index = 11,threshold = -1) + private int videocallin; + @JPos(index = 12,threshold = -1) + private int videocallack; + + + @JPos(index = 13,threshold = -1) + private int iotalarm; + @JPos(index = 14,threshold = -1) + private int terminalalarm; + @JPos(index = 15,threshold = -1) + private int partenalarm; + @JPos(index = 16,threshold = -1) + private int fileupload; + @JPos(index = 17,threshold = -1) + private int preplanstart; + @JPos(index = 18,threshold = -1) + private int study; + @JPos(index = 19,threshold = -1) + private int examination; + + @JPos(index = 20,primary = true, filter = true,threshold = -1) + private int sum1; + @JPos(index = 21,primary = true, filter = true,threshold = -1) + private int sum2; + @JPos(index = 22,threshold = -1) + private int sum3; + + @JPos(index = 23,filter = true) + private String brigade; + @JPos(index = 24,filter = true) + private String borough; + @JPos(index = 25,filter = true) + private String detachment; + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setQuestdone(int questdone) { + this.questdone = questdone; + } + + public int getQuestdone() { + return questdone; + } + + public void setQuesttotal(int questtotal) { + this.questtotal = questtotal; + } + + public int getQuesttotal() { + return questtotal; + } + + public void setNotifyreaded(int notifyreaded) { + this.notifyreaded = notifyreaded; + } + + public int getNotifyreaded() { + return notifyreaded; + } + + public void setNotifytotal(int notifytotal) { + this.notifytotal = notifytotal; + } + + public int getNotifytotal() { + return notifytotal; + } + + public void setAlarmin(int alarmin) { + this.alarmin = alarmin; + } + + public int getAlarmin() { + return alarmin; + } + + public void setAlarmout(int alarmout) { + this.alarmout = alarmout; + } + + public int getAlarmout() { + return alarmout; + } + + public void setOnduration(int onduration) { + this.onduration = onduration; + } + + public int getOnduration() { + return onduration; + } + + public void setRunduration(int runduration) { + this.runduration = runduration; + } + + public int getRunduration() { + return runduration; + } + + public void setDutyduration(int dutyduration) { + this.dutyduration = dutyduration; + } + + public int getDutyduration() { + return dutyduration; + } + + public void setRollcallin(int rollcallin) { + this.rollcallin = rollcallin; + } + + public int getRollcallin() { + return rollcallin; + } + + public void setRollcallack(int rollcallack) { + this.rollcallack = rollcallack; + } + + public int getRollcallack() { + return rollcallack; + } + + public void setVideocallin(int videocallin) { + this.videocallin = videocallin; + } + + public int getVideocallin() { + return videocallin; + } + + public void setVideocallack(int videocallack) { + this.videocallack = videocallack; + } + + public int getVideocallack() { + return videocallack; + } + + public void setIotalarm(int iotalarm) { + this.iotalarm = iotalarm; + } + + public int getIotalarm() { + return iotalarm; + } + + public void setTerminalalarm(int terminalalarm) { + this.terminalalarm = terminalalarm; + } + + public int getTerminalalarm() { + return terminalalarm; + } + + public void setPartenalarm(int partenalarm) { + this.partenalarm = partenalarm; + } + + public int getPartenalarm() { + return partenalarm; + } + + public void setFileupload(int fileupload) { + this.fileupload = fileupload; + } + + public int getFileupload() { + return fileupload; + } + + public void setPreplanstart(int preplanstart) { + this.preplanstart = preplanstart; + } + + public int getPreplanstart() { + return preplanstart; + } + + public void setStudy(int study) { + this.study = study; + } + + public int getStudy() { + return study; + } + + public void setExamination(int examination) { + this.examination = examination; + } + + public int getExamination() { + return examination; + } + + public void setSum1(int sum1) { + this.sum1 = sum1; + } + + public int getSum1() { + return sum1; + } + + public void setSum2(int sum2) { + this.sum2 = sum2; + } + + public int getSum2() { + return sum2; + } + + public void setSum3(int sum3) { + this.sum3 = sum3; + } + + public int getSum3() { + return sum3; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + @Override + public String tableName() { + return "firectrl_station_runtime_status_cache_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationSchoolEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationSchoolEntity.java new file mode 100644 index 0000000..00aceb5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationSchoolEntity.java @@ -0,0 +1,309 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class FireStationSchoolEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String name; + @JPos(index = 1,filter = true) + private String brigade; + @JPos(index = 2,filter = true) + private String detachment; + @JPos(index = 3,filter = true) + private String borough; + + @JPos(index = 4) + private int teachers; + @JPos(index = 5) + private int students; + @JPos(index = 6) + private int guardersmax; + @JPos(index = 7) + private int guarders; + @JPos(index = 8) + private int vehicles; + @JPos(index = 9) + private int policesshould; + @JPos(index = 10) + private int staffshould; + @JPos(index = 11) + private int guardershould; + @JPos(index = 12) + private int kitchenstaff; + @JPos(index = 13) + private int schoolbus; + @JPos(index = 14) + private int busdrivers; + @JPos(index = 15) + private int busteachers; + + @JPos(index = 16) + private int sealzone; + @JPos(index = 17) + private int collision; + @JPos(index = 18) + private int alarmpush; + @JPos(index = 19) + private int ipclinked; + @JPos(index = 20) + private int schoolbox; + @JPos(index = 21) + private int kitchensystem; + + @JPos(index = 22) + private int outsideipc; + + @JPos(index = 23, strlen = 4096) + private String innerRing; + @JPos(index = 24, strlen = 4096) + private String middleRing; + @JPos(index = 25, strlen = 4096) + private String outerRing; + + public String tableName(){ + return "station_school_data_table"; + } + public FireStationSchoolEntity(){ + + } + + public FireStationSchoolEntity(String strname){ + name = strname; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public int getTeachers() { + return teachers; + } + + public void setTeachers(int teachers) { + this.teachers = teachers; + } + + public int getStudents() { + return students; + } + + public void setStudents(int students) { + this.students = students; + } + + public int getGuardersmax() { + return guardersmax; + } + + public void setGuardersmax(int guardersmax) { + this.guardersmax = guardersmax; + } + + public int getGuarders() { + return guarders; + } + + public void setGuarders(int guarders) { + this.guarders = guarders; + } + + public int getVehicles() { + return vehicles; + } + + public void setVehicles(int vehicles) { + this.vehicles = vehicles; + } + + public int getPolicesshould() { + return policesshould; + } + + public void setPolicesshould(int policesshould) { + this.policesshould = policesshould; + } + + public int getStaffshould() { + return staffshould; + } + + public void setStaffshould(int staffshould) { + this.staffshould = staffshould; + } + + public int getGuardershould() { + return guardershould; + } + + public void setGuardershould(int guardershould) { + this.guardershould = guardershould; + } + + public int getKitchenstaff() { + return kitchenstaff; + } + + public void setKitchenstaff(int kitchenstaff) { + this.kitchenstaff = kitchenstaff; + } + + public int getSchoolbus() { + return schoolbus; + } + + public void setSchoolbus(int schoolbus) { + this.schoolbus = schoolbus; + } + + public int getBusdrivers() { + return busdrivers; + } + + public void setBusdrivers(int busdrivers) { + this.busdrivers = busdrivers; + } + + public int getBusteachers() { + return busteachers; + } + + public void setBusteachers(int busteachers) { + this.busteachers = busteachers; + } + + public int getSealzone() { + return sealzone; + } + + public void setSealzone(int sealzone) { + this.sealzone = sealzone; + } + + public int getCollision() { + return collision; + } + + public void setCollision(int collision) { + this.collision = collision; + } + + public int getAlarmpush() { + return alarmpush; + } + + public void setAlarmpush(int alarmpush) { + this.alarmpush = alarmpush; + } + + public int getIpclinked() { + return ipclinked; + } + + public void setIpclinked(int ipclinked) { + this.ipclinked = ipclinked; + } + + public int getSchoolbox() { + return schoolbox; + } + + public void setSchoolbox(int schoolbox) { + this.schoolbox = schoolbox; + } + + public int getKitchensystem() { + return kitchensystem; + } + + public void setKitchensystem(int kitchensystem) { + this.kitchensystem = kitchensystem; + } + + public int getOutsideipc() { + return outsideipc; + } + + public void setOutsideipc(int outsideipc) { + this.outsideipc = outsideipc; + } + + public String getInnerRing() { + return innerRing; + } + + public void setInnerRing(String innerRing) { + this.innerRing = innerRing; + } + + public String getMiddleRing() { + return middleRing; + } + + public void setMiddleRing(String middleRing) { + this.middleRing = middleRing; + } + + public String getOuterRing() { + return outerRing; + } + + public void setOuterRing(String outerRing) { + this.outerRing = outerRing; + } +/* + private int number; + private String name; + private String brigade; + private String detachment; + private String borough; + "teachers":100; + "students":2000; + "guardersmax":60; + "guarders":40; + "vehicles":30; + "policesshould":4; + "staffshould":6; + "guardershould":24; + "kitchenstaff":50; + "schoolbus":10; + "busdrivers":16; + "busteachers":10; + "enclosed": 1; + "collision": 1; + "alarmpush":1; + "ipclinked": 1; + "schoolbox": 0; + "kitchensystem":1; + "outsideipc":0; + + */ +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationSignEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationSignEntity.java new file mode 100644 index 0000000..ec21124 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationSignEntity.java @@ -0,0 +1,162 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.clientmanage.model.UserInfoEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationSignEntity extends SQLDataObject { + @JPos(index = 0,identify = true) + private int id; + @JPos(index = 1) + private int station_number; + @JPos(index = 2,primary = true,filter = true) + private String station_name; + @JPos(index = 3,primary = true,update = false,timekey = true) + private Date signin; + @JPos(index = 4) + private Date signout; + + + public void setId(int id) { + this.id = id; + + } + + public int getId() { + return id; + } + + public void setStation_number(int station_number) { + this.station_number = station_number; + } + + public int getStation_number() { + return station_number; + } + + public void setStation_name(String station_name) { + this.station_name = station_name; + } + + public String getStation_name() { + return station_name; + } + + public void setSignin(Date signin) { + this.signin = signin; + } + + public Date getSignin() { + return signin; + } + + public void setSignout(Date signout) { + this.signout = signout; + } + + public Date getSignout() { + return signout; + } + + public String tableName(){ + return "firectrl_"+tableExtName+"_sign_table"; + } + + + + public boolean Delete(DataSource dataSource){ + String sql = "DELETE FROM "+tableName()+" WHERE id="+id; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + public static FireStationSignEntity Query(DataSource dataSource, Date time){ + FireStationSignEntity sign = new FireStationSignEntity(); + try{ + String sql = "select * from "+sign.tableName()+" where signin='"+ SQLTools.formatDate(time)+"'"; + + List list = SQLTools.ExecuteQuery(dataSource,sql,FireStationSignEntity.class); + if(list!=null&&list.size()>0) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + public boolean SetSignOut(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"id",id); + cmd .appendValue("signout",signout); + try{ + return SQLTools.ExecuteSQL(dataSource, cmd.getSql()); + }catch (Exception e){ + + } + return false; + } + + public String getQueryCondition(){ + String condition = null; + if(station_name!=null&&!station_name.equals("null")&&station_name.length()>0){ + condition = " station_name='"+station_name+"'"; + } + + return condition; + } + + public int queryCount(DataSource dataSource,String start ,String end){ + String condition = getQueryCondition(); + String sql = "select count(*) from "+tableName()+" where signout>='"+start+"' and signin<='"+end+"'"; + if(condition!=null){ + sql += " and "+condition; + } + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + return count; + }catch (Exception ex){ + + } + return 0; + } + + public List queryPage(DataSource dataSource, String start , String end, int pageindex, int pagesize){ + String condition = getQueryCondition(); + + String sql = "select * from "+tableName()+" where signout>='"+start+"' and signin<='"+end+"'"; + if(condition!=null){ + sql += " and "+condition; + } + try{ + List list = SQLTools.queryPage(dataSource, FireStationSignEntity.class,sql,pageindex,pagesize,"signin"); + return list; + }catch (Exception ex){ + + } + return null; + } + + public List queryList(DataSource dataSource, String start , String end){ + String condition = getQueryCondition(); + + String sql = "select * from "+tableName()+" where signout>='"+start+"' and signin<='"+end+"'"; + if(condition!=null){ + sql += " and "+condition; + } + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, FireStationSignEntity.class); + return list; + }catch (Exception ex){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationStaffInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationStaffInfoEntity.java new file mode 100644 index 0000000..6b195b3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationStaffInfoEntity.java @@ -0,0 +1,191 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class FireStationStaffInfoEntity extends SQLDataObject{ + @JPos(index = 0,primary = true, filter = true) + private String stationName; + @JPos(index = 1, filter = true,orderkey = true) + private String name; + @JPos(index = 2, filter = true) + private String title; + @JPos(index = 3,primary = true, filter = true) + private String staffid; + @JPos(index = 4, filter = true) + private String comtype;//comunication type, mobile app or intercom + @JPos(index = 5, filter = true) + private String phone; + @JPos(index = 6, filter = true) + private String status; + @JPos(index = 7) + private Date birthday; + @JPos(index = 8, filter = true) + private String sex; + @JPos(index = 9) + private String address; + @JPos(index = 10) + private String password; + @JPos(index = 11) + private double longitude; + @JPos(index = 12) + private double latitude; + @JPos(index = 13) + private double direct; + @JPos(index = 14) + private double speed; + @JPos(index = 15) + private Date reporttime; + @JPos(index = 16) + private String staff_type; + + public void setStationName(String stationName) { + this.stationName = stationName; + } + + public String getStationName() { + return stationName; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setBirthday(Date birthday) { + this.birthday = birthday; + } + + public Date getBirthday() { + return birthday; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getSex() { + return sex; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPassword() { + return password; + } + + public String getAddress() { + return address; + } + + public void setStaffid(String staffid) { + this.staffid = staffid; + } + + public String getStaffid() { + return staffid; + } + + public void setComtype(String comtype) { + this.comtype = comtype; + } + + public String getComtype() { + return comtype; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setDirect(double direct) { + this.direct = direct; + } + public double getDirect() { + return direct; + } + + public void setSpeed(double speed) { + this.speed = speed; + } + + public double getSpeed() { + return speed; + } + + public void setReporttime(Date reporttime) { + this.reporttime = reporttime; + } + + public Date getReporttime() { + return reporttime; + } + + public String tableName( ){ + return "firectrl_station_staff_table"; + } + + public static FireStationStaffInfoEntity Query(DataSource dataSource,String station,String staffid){ + FireStationStaffInfoEntity staff = new FireStationStaffInfoEntity(); + staff.setStationName(station); + staff.setStaffid(staffid); + return (FireStationStaffInfoEntity)staff.QueryIt(dataSource); + + } + + public String getStaff_type() { + return staff_type; + } + + public void setStaff_type(String staff_type) { + this.staff_type = staff_type; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationVideoConfigEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationVideoConfigEntity.java new file mode 100644 index 0000000..f2698b2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireStationVideoConfigEntity.java @@ -0,0 +1,130 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +//http://dev.netease.im/docs/product/直播/产品介绍/简介 +// +// +public class FireStationVideoConfigEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true,orderkey = true) + private String stationName; + @JPos(index = 1, filter = true) + private String channelName; + @JPos(index = 2) + private String channelID; + @JPos(index = 3, timekey = true) + private Date createTime; + + @JPos(index = 4,strlen = 2048) + private String pushAddress; + @JPos(index = 5,strlen = 2048) + private String httpAddress; + @JPos(index = 6,strlen = 2048) + private String hlsAddress; + @JPos(index = 7,strlen = 2048) + private String rtmpAddress; + @JPos(index = 8,primary = true, filter = true) + private String platform; + + public void setStationName(String stationName) { + this.stationName = stationName; + } + + public String getStationName() { + return stationName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public String getChannelName() { + return channelName; + } + + public void setChannelID(String channelID) { + this.channelID = channelID; + } + + public String getChannelID() { + return channelID; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getCreateTime() { + return createTime; + } + + public void setPushAddress(String pushAddress) { + this.pushAddress = pushAddress; + } + + public String getPushAddress() { + return pushAddress; + } + + public void setHttpAddress(String httpAddress) { + this.httpAddress = httpAddress; + } + + public String getHttpAddress() { + return httpAddress; + } + + public void setHlsAddress(String hlsAddress) { + this.hlsAddress = hlsAddress; + } + + public String getHlsAddress() { + return hlsAddress; + } + + public void setRtmpAddress(String rtmpAddress) { + this.rtmpAddress = rtmpAddress; + } + + public String getRtmpAddress() { + return rtmpAddress; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getPlatform() { + return platform; + } + + public String tableName( ){ + return "firectrl_station_video_config_table"; + } + + + public static boolean DeleteAll(DataSource dataSource){ + FireStationVideoConfigEntity video = new FireStationVideoConfigEntity(); + String sql = "DELETE FROM "+video.tableName(); + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + + public static FireStationVideoConfigEntity Query(DataSource dataSource,String name,String platform){ + FireStationVideoConfigEntity video = new FireStationVideoConfigEntity(); + video.setPlatform(platform); + video.setStationName(name); + return (FireStationVideoConfigEntity)video.QueryIt(dataSource); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireUnitEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireUnitEntity.java new file mode 100644 index 0000000..569b987 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/FireUnitEntity.java @@ -0,0 +1,118 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class FireUnitEntity extends SQLDataObject{ + @JPos(index=0,identify = true,orderkey = true) + private int id; + @JPos(index=1,primary = true,filter = true) + private String fireunitname; + @JPos(index=2,filter = true) + private String brigade; + @JPos(index=3,filter = true) + private String contactor; + @JPos(index=4,filter = true) + private String phone; + @JPos(index=5) + private String address; + @JPos(index=6) + private double longitude; + @JPos(index=7) + private double latitude; + @JPos(index=8,filter = true) + private String level; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setFireunitname(String fireunitname) { + this.fireunitname = fireunitname; + } + + public String getFireunitname() { + return fireunitname; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setContactor(String contactor) { + this.contactor = contactor; + } + + public String getContactor() { + return contactor; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getLevel() { + return level; + } + + public String tableName(){ + return "fire_unit_info_table"; + } + + + public static FireUnitEntity Query(DataSource dataSource,String name){ + FireUnitEntity unit = new FireUnitEntity(); + String sql = "select * from "+unit.tableName()+" where fireunitname='"+name+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,FireUnitEntity.class); + if(list!=null&&list.size()>0){ + return list.get(0); + } + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/MessageToStation.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/MessageToStation.java new file mode 100644 index 0000000..02f5cdf --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/MessageToStation.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.model.station; + +public class MessageToStation { + private String title; + private String message; + private Object data; + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setData(Object data) { + this.data = data; + } + + public Object getData() { + return data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/PersonInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/PersonInfoEntity.java new file mode 100644 index 0000000..649f736 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/PersonInfoEntity.java @@ -0,0 +1,225 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class PersonInfoEntity extends SQLDataObject { + @JPos(index = 0,primary = true, filter = true) + private String staffid; + @JPos(index = 1, filter = true) + private String badge ;//employee, temp, forbidden + + @JPos(index = 2, filter = true) + private String name; + @JPos(index = 3, filter = true) + private String sex; + @JPos(index = 4, filter = true) + private String phone; + @JPos(index = 5, filter = true) + private String title; + @JPos(index = 6) + private Date birthday ; + @JPos(index = 7, strlen = 512) + private String address ; + @JPos(index = 8, filter = true) + private String status ; //on | stop + @JPos(index = 9, filter = true) + private String department; + @JPos(index = 10, filter = true) + private String comtype ; + @JPos(index = 11, filter = true) + private String deviceid ; + @JPos(index = 12, strlen = 1024) + private String comment ; + @JPos(index = 13, strlen = 1024) + private String avator ; + @JPos(index = 14, strlen = 4096) + private String image ; + @JPos(index = 15, strlen = 2048) + private String certificates ; + @JPos(index = 16, strlen = 2048) + private String authroom ; + @JPos(index = 17, filter = true) + private String brigade; + @JPos(index = 18, filter = true) + private String borough; + @JPos(index = 19, filter = true) + private String detachment; + @JPos(index = 20,primary = true, filter = true) + private String station; + + public void setStaffid(String staffid) { + this.staffid = staffid; + } + + public String getStaffid() { + return staffid; + } + + public void setBadge(String badge) { + this.badge = badge; + } + + public String getBadge() { + return badge; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getSex() { + return sex; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setBirthday(Date birthday) { + this.birthday = birthday; + } + + public Date getBirthday() { + return birthday; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setDepartment(String department) { + this.department = department; + } + + public String getDepartment() { + return department; + } + + public void setComtype(String comtype) { + this.comtype = comtype; + } + + public String getComtype() { + return comtype; + } + + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public void setAvator(String avator) { + this.avator = avator; + } + + public String getAvator() { + return avator; + } + + public void setCertificates(String certificates) { + this.certificates = certificates; + } + + public String getCertificates() { + return certificates; + } + + public void setAuthroom(String authroom) { + this.authroom = authroom; + } + + public String getAuthroom() { + return authroom; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName( ){ + return "firectrl_station_person_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/PoliceRoomInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/PoliceRoomInfo.java new file mode 100644 index 0000000..2c08dab --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/PoliceRoomInfo.java @@ -0,0 +1,164 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class PoliceRoomInfo extends SQLDataObject { + @JPos(index = 0,identify = true,orderkey = true) + private int number; + @JPos(index = 1,primary = true,filter = true) + private String name; + + @JPos(index = 2,primary = true,filter = true) + private String policestation; + @JPos(index = 3,filter = true) + private String policezone; + @JPos(index = 4,filter = true) + private String communities; + @JPos(index = 5,filter = true) + private int independent; + @JPos(index = 6,filter = true) + private int shared; + @JPos(index = 7,filter = true) + private String status; + @JPos(index = 8,filter = true) + private String address; + @JPos(index = 9,filter = true) + private String phone; + @JPos(index = 10) + private double longitude; + @JPos(index = 11) + private double latitude; + @JPos(index = 12, strlen = 4096) + private String boundary; + @JPos(index = 13,primary = true,filter = true) + private String brigade; + @JPos(index = 14,filter = true) + private String comment; + + public String tableName( ){ + return "policeroom_info_table"; + } + + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPolicestation() { + return policestation; + } + + public void setPolicestation(String policestation) { + this.policestation = policestation; + } + + public String getPolicezone() { + return policezone; + } + + public void setPolicezone(String policezone) { + this.policezone = policezone; + } + + public String getCommunities() { + return communities; + } + + public void setCommunities(String communities) { + this.communities = communities; + } + + public int getIndependent() { + return independent; + } + + public void setIndependent(int independent) { + this.independent = independent; + } + + public int getShared() { + return shared; + } + + public void setShared(int shared) { + this.shared = shared; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getBoundary() { + return boundary; + } + + public void setBoundary(String boundary) { + this.boundary = boundary; + } + + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/PolicemanInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/PolicemanInfo.java new file mode 100644 index 0000000..d30baf3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/PolicemanInfo.java @@ -0,0 +1,253 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class PolicemanInfo extends SQLDataObject { + + public static final String TYPE_Policeman = "policeman"; + public static final String TYPE_Guarder = "guarder"; + public static final String TYPE_Volunteer = "volunteer"; + public static final String TYPE_SchoolManager = "school.manager"; + public static final String TYPE_PoliceManager = "police.manager"; + public static final String STATE_NEW = "new"; + public static final String STATE_REG = "registered"; + public static final String STATE_BANDED = "banded"; + + public static final String ACCOUNT_TYPE_WeChat = "wechat"; + + @JPos(index = 0,identify = true,orderkey = true) + private int number; + @JPos(index = 1,filter = true) + private String name; + @JPos(index = 2,primary = true,filter = true) + private String id; + @JPos(index = 3,filter = true) + private String personType; + @JPos(index = 4,filter = true) + private String sex; + @JPos(index = 5,filter = true) + private String phone; + @JPos(index = 6) + private Date birthday ; + @JPos(index = 7,filter = true) + private String title; + @JPos(index = 8,filter = true) + private String worktime; + @JPos(index = 9,filter = true) + private String brigade; + @JPos(index = 10,filter = true) + private String borough; + @JPos(index = 11,filter = true) + private String detachment; + @JPos(index = 12,filter = true) + private String station; + @JPos(index = 13,filter = true) + private String policestation; + @JPos(index = 14,filter = true) + private String policezone; + @JPos(index = 15,filter = true) + private String communities; + @JPos(index = 16) + private String comment; + @JPos(index = 17) + private String password; + @JPos(index = 18,filter = true) + private String userState; + @JPos(index = 19) + private Date signTimestamp; + @JPos(index = 20) + private String level; + + private String accountType; + private String accountCode; + + public String tableName( ){ + return "policeman_person_info_table"; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPersonType() { + return personType; + } + + public void setPersonType(String personType) { + this.personType = personType; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public Date getBirthday() { + return birthday; + } + + public void setBirthday(Date birthday) { + this.birthday = birthday; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getWorktime() { + return worktime; + } + + public void setWorktime(String worktime) { + this.worktime = worktime; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getPolicestation() { + return policestation; + } + + public void setPolicestation(String policestation) { + this.policestation = policestation; + } + + public String getPolicezone() { + return policezone; + } + + public void setPolicezone(String policezone) { + this.policezone = policezone; + } + + public String getCommunities() { + return communities; + } + + public void setCommunities(String communities) { + this.communities = communities; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public void setPassword(String password) { + this.password = password; + } + public String getPassword() { + return password; + } + + public void setUserState(String userState) { + this.userState = userState; + } + public String getUserState() { + return userState; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + + public Date getSignTimestamp() { + return signTimestamp; + } + + public void setSignTimestamp(Date signTimestamp) { + this.signTimestamp = signTimestamp; + } + + public String getAccountType() { + return accountType; + } + + public void setAccountType(String accountType) { + this.accountType = accountType; + } + + public String getAccountCode() { + return accountCode; + } + + public void setAccountCode(String accountCode) { + this.accountCode = accountCode; + } + + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/ProcessAlarmTaskEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/ProcessAlarmTaskEntity.java new file mode 100644 index 0000000..12edb67 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/ProcessAlarmTaskEntity.java @@ -0,0 +1,245 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class ProcessAlarmTaskEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String taskid; + @JPos(index = 1,filter = true) + private String title; + @JPos(index = 2,strlen = 1024) + private String content; + @JPos(index = 3,update = false,timekey = true,orderkey = true) + private Date createtime; + @JPos(index = 4,filter = true) + private String sender; + @JPos(index = 5,filter = true) + private String receiver; + @JPos(index = 6,filter = true) + private String createmode; + @JPos(index = 7,filter = true,diffconf = true) + private String status; + @JPos(index = 8,filter = true) + private String type; + @JPos(index = 9,filter = true,strlen = 512) + private String address; + @JPos(index = 10) + private double longitude; + @JPos(index = 11) + private double latitude; + @JPos(index = 12,filter = true) + private String relatealarmid; + @JPos(index = 13,filter = true) + private String relatealarmtype; + @JPos(index = 14,strlen = 2048) + private String relatealarmdata; + @JPos(index = 15) + private Date closetime; + @JPos(index=16,filter = true) + private String brigade; + @JPos(index=17,filter = true) + private String borough; + @JPos(index=18,filter = true) + private String detachment; + @JPos(index=19,filter = true) + private String station; + @JPos(index=20,strlen = 4096) + private String checkpoints; + @JPos(index=21) + private String dataType; + @JPos(index=22,strlen = 2048) + private String data; + + + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setCreatetime(Date createtime) { + this.createtime = createtime; + } + + public Date getCreatetime() { + return createtime; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setCreatemode(String createmode) { + this.createmode = createmode; + } + + public String getCreatemode() { + return createmode; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setRelatealarmid(String relatealarmid) { + this.relatealarmid = relatealarmid; + } + + public String getRelatealarmid() { + return relatealarmid; + } + + public void setRelatealarmtype(String relatealarmtype) { + this.relatealarmtype = relatealarmtype; + } + + public String getRelatealarmtype() { + return relatealarmtype; + } + + public void setRelatealarmdata(String relatealarmdata) { + this.relatealarmdata = relatealarmdata; + } + + public String getRelatealarmdata() { + return relatealarmdata; + } + + public void setClosetime(Date closetime) { + this.closetime = closetime; + } + + public Date getClosetime() { + return closetime; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setCheckpoints(String checkpoints) { + this.checkpoints = checkpoints; + } + + public String getCheckpoints() { + return checkpoints; + } + + public String tableName( ){ + return "firectrl_process_alarm_task_table"; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/ProcessAlarmTaskOpRecord.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/ProcessAlarmTaskOpRecord.java new file mode 100644 index 0000000..81bb175 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/ProcessAlarmTaskOpRecord.java @@ -0,0 +1,142 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class ProcessAlarmTaskOpRecord extends SQLDataObject { + @JPos(index = 0,primary = true) + private String taskid; + @JPos(index = 1,filter = true) + private String operation;//create | updateinfo | updatestatus + @JPos(index = 2,filter = true) + private String operator; + @JPos(index = 3,filter = true) + private String operatortype; + @JPos(index = 4,filter = true) + private String operatordevice; + @JPos(index = 5,filter = true) + private String operatordevicetype; + @JPos(index = 6,filter = true) + private String relatealarmid; + @JPos(index = 7,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index = 8,filter = true) + private String receiver; + @JPos(index = 9,strlen = 1024) + private String result; + @JPos(index=10) + private double longitude; + @JPos(index=11) + private double latitude; + @JPos(index=12,strlen = 4096) + private String checkpoints; + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getOperation() { + return operation; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setOperatortype(String operatortype) { + this.operatortype = operatortype; + } + + public String getOperatortype() { + return operatortype; + } + + public void setOperatordevice(String operatordevice) { + this.operatordevice = operatordevice; + } + + public String getOperatordevice() { + return operatordevice; + } + + public void setOperatordevicetype(String operatordevicetype) { + this.operatordevicetype = operatordevicetype; + } + + public String getOperatordevicetype() { + return operatordevicetype; + } + + public void setRelatealarmid(String relatealarmid) { + this.relatealarmid = relatealarmid; + } + + public String getRelatealarmid() { + return relatealarmid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setResult(String result) { + this.result = result; + } + + public String getResult() { + return result; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setCheckpoints(String checkpoints) { + this.checkpoints = checkpoints; + } + + public String getCheckpoints() { + return checkpoints; + } + + public String tableName( ){ + return "firectrl_process_alarm_task_op_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/QuarterInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/QuarterInfo.java new file mode 100644 index 0000000..ae4ca77 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/QuarterInfo.java @@ -0,0 +1,141 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class QuarterInfo extends SQLDataObject { + @JPos(index = 0,identify = true,orderkey = true) + private int number; + @JPos(index = 1,primary = true,filter = true) + private String name; + @JPos(index = 2,primary = true,filter = true) + private String brigade; + @JPos(index = 3,filter = true) + private String policestation; + @JPos(index = 4,filter = true) + private String policezone; + @JPos(index = 5,filter = true) + private String community; + @JPos(index = 6,filter = true) + private String address; + @JPos(index = 7,filter = true) + private String contact; + @JPos(index = 8,filter = true) + private String phone; + @JPos(index = 9) + private double longitude; + @JPos(index = 10) + private double latitude; + @JPos(index = 11, strlen = 4096) + private String boundary; + @JPos(index = 12,filter = true) + private String comment; + + public String tableName( ){ + return "residential_quarter_info_table"; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPolicestation() { + return policestation; + } + + public void setPolicestation(String policestation) { + this.policestation = policestation; + } + + public String getPolicezone() { + return policezone; + } + + public void setPolicezone(String policezone) { + this.policezone = policezone; + } + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getContact() { + return contact; + } + + public void setContact(String contact) { + this.contact = contact; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getBoundary() { + return boundary; + } + + public void setBoundary(String boundary) { + this.boundary = boundary; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationAdjustmentEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationAdjustmentEntity.java new file mode 100644 index 0000000..6feec45 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationAdjustmentEntity.java @@ -0,0 +1,194 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class StationAdjustmentEntity extends SQLDataObject { + @JPos(index = 0,identify = true,orderkey = true) + private int number; + @JPos(index = 1,primary = true,filter = true) + private String id; + @JPos(index = 2,primary = true,filter = true) + private String station; + @JPos(index = 3,primary = true,filter = true) + private String detachment; + @JPos(index = 4,primary = true,filter = true) + private String borough; + @JPos(index = 5,primary = true,filter = true) + private String brigade; + + @JPos(index = 6,filter = true) + private String checker; + + @JPos(index = 7,filter = true) + private String checker_phone; + + @JPos(index = 8,filter = true) + private String checker_department; + + @JPos(index = 9,filter = true) + private String type; + + @JPos(index = 10,filter = true) + private String subtype; + + @JPos(index = 11) + private String description; + + @JPos(index = 12) + private String comment; + + @JPos(index = 13,filter = true) + private int adjust_type; + + @JPos(index = 14,filter = true) + private String operator; + + @JPos(index = 15,timekey = true, orderkey = true) + private Date timestamp; + + @JPos(index = 16,filter = true) + private String status; + + public String tableName( ){ + return "station_adjustment_item_table"; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getChecker() { + return checker; + } + + public void setChecker(String checker) { + this.checker = checker; + } + + public String getChecker_phone() { + return checker_phone; + } + + public void setChecker_phone(String checker_phone) { + this.checker_phone = checker_phone; + } + + public String getChecker_department() { + return checker_department; + } + + public void setChecker_department(String checker_department) { + this.checker_department = checker_department; + } + + public void setType(String type) { + this.type = type; + } + public String getType() { + return type; + } + + public void setSubtype(String subtype){ + this.subtype = subtype; + } + + public String getSubtype() { + return subtype; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public void setAdjust_type(int adjust_type) { + this.adjust_type = adjust_type; + } + + public int getAdjust_type() { + return adjust_type; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationBlacklistEvent.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationBlacklistEvent.java new file mode 100644 index 0000000..3c42bca --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationBlacklistEvent.java @@ -0,0 +1,56 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class StationBlacklistEvent { + + private String facesluiceId; + private String blackName; + private String blackType; + private String pic; + private String idNumber; + + public String getFacesluiceId() { + return facesluiceId; + } + + public void setFacesluiceId(String facesluiceId) { + this.facesluiceId = facesluiceId; + } + + public String getBlackName() { + return blackName; + } + + public void setBlackName(String blackName) { + this.blackName = blackName; + } + + public String getBlackType() { + return blackType; + } + + public void setBlackType(String blackType) { + this.blackType = blackType; + } + + + public String getPic() { + return pic; + } + + public void setPic(String pic) { + this.pic = pic; + } + + public String getIdNumber() { + return idNumber; + } + + public void setIdNumber(String idNumber) { + this.idNumber = idNumber; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationRunningInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationRunningInfoEntity.java new file mode 100644 index 0000000..f21fb03 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationRunningInfoEntity.java @@ -0,0 +1,134 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.List; + +public class StationRunningInfoEntity extends SQLDataObject { + @JPos(index=0,primary = true,filter = true,orderkey = true) + public String station; + @JPos(index=1,filter = true) + public String state;//online, offline + @JPos(index=2,filter = true) + public String signstate;//onsign , outsign + @JPos(index=3,filter = true) + public String alarmstate;//noalarm alarm + @JPos(index=4,filter = true) + public String videostate;//open , close + @JPos(index=5) + public double longitude; + @JPos(index=6) + public double latitude; + @JPos(index=7,filter = true) + public String appversion; + @JPos(index=8) + public String newquest; + @JPos(index=9) + public String runningquest; + + public StationRunningInfoEntity(){ + alarmstate = "noalarm"; + videostate = "close"; + } + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setSignstate(String signstate) { + this.signstate = signstate; + } + + public String getSignstate() { + return signstate; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setAppversion(String appversion) { + this.appversion = appversion; + } + + public String getAppversion() { + return appversion; + } + + public void setNewquest(String newquest) { + this.newquest = newquest; + } + + public String getNewquest() { + return newquest; + } + + public void setRunningquest(String runningquest) { + this.runningquest = runningquest; + } + + public String getRunningquest() { + return runningquest; + } + + public void setAlarmstate(String alarmstate) { + this.alarmstate = alarmstate; + } + + public String getAlarmstate() { + return alarmstate; + } + + public void setVideostate(String videostate) { + this.videostate = videostate; + } + + public String getVideostate() { + return videostate; + } + + public String tableName() { + return "firectrl_station_running_info_table"; + } + + + public static StationRunningInfoEntity Query(DataSource dataSource,String station){ + StationRunningInfoEntity run = new StationRunningInfoEntity(); + String sql = "select * from "+run.tableName()+" where station='"+station+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,StationRunningInfoEntity.class); + if(list!=null&&list.size()>0){ + return list.get(0); + } + }catch (Exception e){ + + } + return null; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationStaffAISignInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationStaffAISignInfo.java new file mode 100644 index 0000000..65de583 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/StationStaffAISignInfo.java @@ -0,0 +1,264 @@ +package com.jingyi.iotserver.firestationport.model.station; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class StationStaffAISignInfo extends SQLDataObject { + @JPos(index=0,primary = true,filter = true) + private String facesluiceId; + @JPos(index=1,primary = true,filter = true) + private String personId; + @JPos(index = 2,primary = true, timekey = true, orderkey = true) + private Date time; + @JPos(index = 3,primary = true,filter = true) + private String station; + @JPos(index = 4,primary = true,filter = true) + private String detachment; + @JPos(index = 5,primary = true,filter = true) + private String borough; + @JPos(index = 6,primary = true,filter = true) + private String brigade; + @JPos(index = 7) + private String customId; + @JPos(index = 8) + private String recordID; + @JPos(index = 9) + private String verifyStatus; + @JPos(index = 10) + private String personType; + @JPos(index = 11) + private String similarity1; + @JPos(index = 12) + private String similarity2; + @JPos(index = 13) + private int sendintime; + @JPos(index = 14) + private String direction; + @JPos(index = 15) + private String otype; + @JPos(index = 16) + private String persionName; + @JPos(index = 17) + private String facesluiceName; + @JPos(index = 18) + private String idCard; + @JPos(index = 19) + private String telnum; + @JPos(index = 20) + private String pushType; + @JPos(index = 21) + private String OpendoorWay; + @JPos(index = 22) + private String cardNum2; + @JPos(index = 23) + private String RFIDCard; + @JPos(index = 24) + private String szQrCodeData; + + public String tableName(){ + return "entrance_ai_face_rec_table"; + } + + public String getCustomId() { + return customId; + } + + public void setCustomId(String customId) { + this.customId = customId; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getRecordID() { + return recordID; + } + + public void setRecordID(String recordID) { + this.recordID = recordID; + } + + public String getVerifyStatus() { + return verifyStatus; + } + + public void setVerifyStatus(String verifyStatus) { + this.verifyStatus = verifyStatus; + } + + public String getPersonType() { + return personType; + } + + public void setPersonType(String personType) { + this.personType = personType; + } + + public String getSimilarity1() { + return similarity1; + } + + public void setSimilarity1(String similarity1) { + this.similarity1 = similarity1; + } + + public String getSimilarity2() { + return similarity2; + } + + public void setSimilarity2(String similarity2) { + this.similarity2 = similarity2; + } + + public int getSendintime() { + return sendintime; + } + + public void setSendintime(int sendintime) { + this.sendintime = sendintime; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getOtype() { + return otype; + } + + public void setOtype(String otype) { + this.otype = otype; + } + + public String getPersionName() { + return persionName; + } + + public void setPersionName(String persionName) { + this.persionName = persionName; + } + + public String getFacesluiceId() { + return facesluiceId; + } + + public void setFacesluiceId(String facesluiceId) { + this.facesluiceId = facesluiceId; + } + + public String getFacesluiceName() { + return facesluiceName; + } + + public void setFacesluiceName(String facesluiceName) { + this.facesluiceName = facesluiceName; + } + + public String getIdCard() { + return idCard; + } + + public void setIdCard(String idCard) { + this.idCard = idCard; + } + + public String getTelnum() { + return telnum; + } + + public void setTelnum(String telnum) { + this.telnum = telnum; + } + + public Date getTime() { + return time; + } + + public void setTime(Date timestamp) { + this.time = timestamp; + } + + public String getPushType() { + return pushType; + } + + public void setPushType(String pushType) { + this.pushType = pushType; + } + + public String getOpendoorWay() { + return OpendoorWay; + } + + public void setOpendoorWay(String opendoorWay) { + this.OpendoorWay = opendoorWay; + } + + public String getCardNum2() { + return cardNum2; + } + + public void setCardNum2(String cardNum2) { + this.cardNum2 = cardNum2; + } + + public String getRFIDCard() { + return RFIDCard; + } + + public void setRFIDCard(String RFIDCard) { + this.RFIDCard = RFIDCard; + } + + public String getSzQrCodeData() { + return szQrCodeData; + } + + public void setSzQrCodeData(String szQrCodeData) { + this.szQrCodeData = szQrCodeData; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/station/TransMsgToStation.java b/src/main/java/com/jingyi/iotserver/firestationport/model/station/TransMsgToStation.java new file mode 100644 index 0000000..cc90a15 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/station/TransMsgToStation.java @@ -0,0 +1,40 @@ +package com.jingyi.iotserver.firestationport.model.station; + +public class TransMsgToStation { + private String alias; + private String title; + private String tag; + private String data; + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getAlias() { + return alias; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public String getTag() { + return tag; + } + + public void setData(String data) { + this.data = data; + } + + public String getData() { + return data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughDaySummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughDaySummaryEntity.java new file mode 100644 index 0000000..de4556d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughDaySummaryEntity.java @@ -0,0 +1,337 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class BoroughDaySummaryEntity extends SQLDataObject { + @JPos(index = 0,identify = true,filter = true) + private String id; + @JPos(index = 1) + private int guarder_sign; + @JPos(index = 2) + private int police_sign; + @JPos(index = 3) + private int volunteer_sign; + @JPos(index = 4) + private int protector_sign; + @JPos(index = 5) + private int visitor; + @JPos(index = 6) + private int visitor_vehicles; + @JPos(index = 7) + private int danger_count; + @JPos(index = 8) + private int pushalarm_count; + @JPos(index = 9) + private int kitchenwarn; + @JPos(index = 10) + private int vehicle_tired; + @JPos(index = 11) + private int vehicle_speed; + @JPos(index = 12) + private int vehicle_fence; + @JPos(index = 13) + private int totalsign; + @JPos(index = 14) + private double guarder_percent; + @JPos(index = 15) + private double police_percent; + @JPos(index = 16) + private double staff_percent; + @JPos(index = 17) + private double protector_percent; + @JPos(index = 18,timekey = true, orderkey = true) + private Date timestamp; + + @JPos(index = 19) + private double score_total; + + @JPos(index = 20,primary = true,filter = true) + private String borough; + @JPos(index = 21,primary = true,filter = true) + private String brigade; + + + @JPos(index = 22,primary = true,filter = true) + private int year; + @JPos(index = 23,primary = true,filter = true) + private int month; + @JPos(index = 24,primary = true,filter = true) + private int day; + + + public String tableName(){ + return "borough_summary_days_table"; + } + + public BoroughDaySummaryEntity(){ + + } + + public BoroughDaySummaryEntity(BoroughEntity boroughInfo, int nYear, int nMonth, int nDay){ + if(boroughInfo != null){ + borough = boroughInfo.getBorough(); + brigade = boroughInfo.getBrigade(); + year = nYear; + month = nMonth; + day = nDay; + String strID = brigade + borough + year+month+day; + setId(strID); + + guarder_sign = 0; + police_sign = 0; + volunteer_sign = 0; + protector_sign = 0; + visitor = 0; + visitor_vehicles = 0; + danger_count = 0; + pushalarm_count = 0; + kitchenwarn = 0; + vehicle_tired = 0; + vehicle_speed = 0; + vehicle_fence = 0; + guarder_percent = 0; + police_percent = 0; + staff_percent = 0; + protector_percent = 0; + + score_total = 0; + } + } + + + public int getGuarder_sign() { + return guarder_sign; + } + + public void setGuarder_sign(int guarder_sign) { + this.guarder_sign = guarder_sign; + } + + public int getPolice_sign() { + return police_sign; + } + + public void setPolice_sign(int police_sign) { + this.police_sign = police_sign; + } + + public int getVolunteer_sign() { + return volunteer_sign; + } + + public void setVolunteer_sign(int volunteer_sign) { + this.volunteer_sign = volunteer_sign; + } + + public int getProtector_sign() { + return protector_sign; + } + + public void setProtector_sign(int protector_sign) { + this.protector_sign = protector_sign; + } + + public int getVisitor() { + return visitor; + } + + public void setVisitor(int visitor) { + this.visitor = visitor; + } + + public int getVisitor_vehicles() { + return visitor_vehicles; + } + + public void setVisitor_vehicles(int visitor_vehicles) { + this.visitor_vehicles = visitor_vehicles; + } + + public int getDanger_count() { + return danger_count; + } + + public void setDanger_count(int danger_count) { + this.danger_count = danger_count; + } + + public int getPushalarm_count() { + return pushalarm_count; + } + + public void setPushalarm_count(int pushalarm_count) { + this.pushalarm_count = pushalarm_count; + } + + public int getKitchenwarn() { + return kitchenwarn; + } + + public void setKitchenwarn(int kitchenwarn) { + this.kitchenwarn = kitchenwarn; + } + + public int getVehicle_tired() { + return vehicle_tired; + } + + public void setVehicle_tired(int vehicle_tired) { + this.vehicle_tired = vehicle_tired; + } + + public int getVehicle_speed() { + return vehicle_speed; + } + + public void setVehicle_speed(int vehicle_speed) { + this.vehicle_speed = vehicle_speed; + } + + public int getVehicle_fence() { + return vehicle_fence; + } + + public void setVehicle_fence(int vehicle_fence) { + this.vehicle_fence = vehicle_fence; + } + + + public double getGuarder_percent() { + return guarder_percent; + } + + public void setGuarder_percent(double guarder_percent) { + this.guarder_percent = guarder_percent; + } + + public double getPolice_percent() { + return police_percent; + } + + public void setPolice_percent(double police_percent) { + this.police_percent = police_percent; + } + + public double getStaff_percent() { + return staff_percent; + } + + public void setStaff_percent(double staff_percent) { + this.staff_percent = staff_percent; + } + + public double getProtector_percent() { + return protector_percent; + } + + public void setProtector_percent(double protector_percent) { + this.protector_percent = protector_percent; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public static List QueryMonth(DataSource dataSource, String boroughName, int nYear, int nMonth) { + BoroughDaySummaryEntity info = new BoroughDaySummaryEntity(); + String sql = "select * from " + info.tableName() + " where borough='" + boroughName + "' and year ='" + nYear + "' and month ='" +nMonth + "'" ; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, BoroughDaySummaryEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public static List QueryBrigadeOneDay(DataSource dataSource, String brigadeName, int nYear, int nMonth, int nDay) { + BoroughDaySummaryEntity info = new BoroughDaySummaryEntity(); + String sql = "select * from " + info.tableName() + " where brigade='" + brigadeName + "' and year ='" + nYear + "' and month ='" +nMonth + "' and day ='" +nDay + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, BoroughDaySummaryEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + + public double getScore_total() { + return score_total; + } + + public void setScore_total(double score_total) { + this.score_total = score_total; + } + + public void setTotalsign(int totalsign) { + this.totalsign = totalsign; + } + + public double getTotalsign() { + return totalsign; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughMonthSummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughMonthSummaryEntity.java new file mode 100644 index 0000000..f2d9920 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughMonthSummaryEntity.java @@ -0,0 +1,274 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class BoroughMonthSummaryEntity extends SQLDataObject { + @JPos(index = 0,identify = true,filter = true) + private String id; + @JPos(index = 1) + private int guarder_sign; + @JPos(index = 2) + private int police_sign; + @JPos(index = 3) + private int volunteer_sign; + @JPos(index = 4) + private int protector_sign; + @JPos(index = 5) + private int visitor; + @JPos(index = 6) + private int visitor_vehicles; + @JPos(index = 7) + private int danger_count; + @JPos(index = 8) + private int pushalarm_count; + @JPos(index = 9) + private int kitchenwarn; + @JPos(index = 10) + private int vehicle_tired; + @JPos(index = 11) + private int vehicle_speed; + @JPos(index = 12) + private int vehicle_fence; + @JPos(index = 13) + private int totalsign; + @JPos(index = 14) + private double guarder_percent; + @JPos(index = 15) + private double police_percent; + @JPos(index = 16) + private double staff_percent; + @JPos(index = 17) + private double protector_percent; + @JPos(index = 18,timekey = true, orderkey = true) + private Date timestamp; + + @JPos(index = 19) + private double score_total; + + @JPos(index = 20,primary = true,filter = true) + private String borough; + @JPos(index = 21,primary = true,filter = true) + private String brigade; + + + @JPos(index = 22,primary = true,filter = true) + private int year; + @JPos(index = 23,primary = true,filter = true) + private int month; + + public String tableName(){ + return "borough_summary_month_table"; + } + + public BoroughMonthSummaryEntity(){ + + } + + public BoroughMonthSummaryEntity(BoroughEntity boroughInfo, int nYear, int nMonth){ + if(boroughInfo != null){ + borough = boroughInfo.getBorough(); + brigade = boroughInfo.getBrigade(); + year = nYear; + month = nMonth; + String strID = brigade + borough + year+month; + setId(strID); + } + } + + public int getGuarder_sign() { + return guarder_sign; + } + + public void setGuarder_sign(int guarder_sign) { + this.guarder_sign = guarder_sign; + } + + public int getPolice_sign() { + return police_sign; + } + + public void setPolice_sign(int police_sign) { + this.police_sign = police_sign; + } + + public int getVolunteer_sign() { + return volunteer_sign; + } + + public void setVolunteer_sign(int volunteer_sign) { + this.volunteer_sign = volunteer_sign; + } + + public int getProtector_sign() { + return protector_sign; + } + + public void setProtector_sign(int protector_sign) { + this.protector_sign = protector_sign; + } + + public int getVisitor() { + return visitor; + } + + public void setVisitor(int visitor) { + this.visitor = visitor; + } + + public int getVisitor_vehicles() { + return visitor_vehicles; + } + + public void setVisitor_vehicles(int visitor_vehicles) { + this.visitor_vehicles = visitor_vehicles; + } + + public int getDanger_count() { + return danger_count; + } + + public void setDanger_count(int danger_count) { + this.danger_count = danger_count; + } + + public int getPushalarm_count() { + return pushalarm_count; + } + + public void setPushalarm_count(int pushalarm_count) { + this.pushalarm_count = pushalarm_count; + } + + public int getKitchenwarn() { + return kitchenwarn; + } + + public void setKitchenwarn(int kitchenwarn) { + this.kitchenwarn = kitchenwarn; + } + + public int getVehicle_tired() { + return vehicle_tired; + } + + public void setVehicle_tired(int vehicle_tired) { + this.vehicle_tired = vehicle_tired; + } + + public int getVehicle_speed() { + return vehicle_speed; + } + + public void setVehicle_speed(int vehicle_speed) { + this.vehicle_speed = vehicle_speed; + } + + public int getVehicle_fence() { + return vehicle_fence; + } + + public void setVehicle_fence(int vehicle_fence) { + this.vehicle_fence = vehicle_fence; + } + + public double getGuarder_percent() { + return guarder_percent; + } + + public void setGuarder_percent(double guarder_percent) { + this.guarder_percent = guarder_percent; + } + + public double getPolice_percent() { + return police_percent; + } + + public void setPolice_percent(double police_percent) { + this.police_percent = police_percent; + } + + public double getStaff_percent() { + return staff_percent; + } + + public void setStaff_percent(double staff_percent) { + this.staff_percent = staff_percent; + } + + public double getProtector_percent() { + return protector_percent; + } + + public void setProtector_percent(double protector_percent) { + this.protector_percent = protector_percent; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public double getScore_total() { + return score_total; + } + + public void setScore_total(double score_total) { + this.score_total = score_total; + } + + public void setTotalsign(int totalsign) { + this.totalsign = totalsign; + } + + public double getTotalsign() { + return totalsign; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughPoliceSummary.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughPoliceSummary.java new file mode 100644 index 0000000..57511b2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BoroughPoliceSummary.java @@ -0,0 +1,29 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import lombok.Data; + +import java.util.List; + +@Data +public class BoroughPoliceSummary { + private String borough; + private int guardCount; + private int policeCount; + private int volunteerCount; + private int teacherCount; + private int guardSignCount; + private int policeSignCount; + private int volunteerSignCount; + private int teacherSignCount; + + private int newsPeakGuard; + private int newsLaw; + private int newsExercise; + private int newsOther; + + private int securityCheckCount; + private int pendingProcessCount; + + private List schoolSummaryList; + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BrigadeDaySummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BrigadeDaySummaryEntity.java new file mode 100644 index 0000000..edbf95b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/BrigadeDaySummaryEntity.java @@ -0,0 +1,314 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import com.jingyi.iotserver.clientmanage.model.BrigadeEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class BrigadeDaySummaryEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String id; + @JPos(index = 1) + private int guarder_sign; + @JPos(index = 2) + private int police_sign; + @JPos(index = 3) + private int volunteer_sign; + @JPos(index = 4) + private int protector_sign; + @JPos(index = 5) + private int visitor; + @JPos(index = 6) + private int visitor_vehicles; + @JPos(index = 7) + private int danger_count; + @JPos(index = 8) + private int pushalarm_count; + @JPos(index = 9) + private int kitchenwarn; + @JPos(index = 10) + private int vehicle_tired; + @JPos(index = 11) + private int vehicle_speed; + @JPos(index = 12) + private int vehicle_fence; + @JPos(index = 13) + private int totalsign; + @JPos(index = 14) + private double guarder_percent; + @JPos(index = 15) + private double police_percent; + @JPos(index = 16) + private double staff_percent; + @JPos(index = 17) + private double protector_percent; + @JPos(index = 18,timekey = true, orderkey = true) + private Date timestamp; + + @JPos(index = 19) + private double score_total; + + @JPos(index = 20,primary = true,filter = true) + private String brigade; + + + @JPos(index = 21,primary = true,filter = true) + private int year; + @JPos(index = 22,primary = true,filter = true) + private int month; + @JPos(index = 23,primary = true,filter = true) + private int day; + + + public String tableName(){ + return "brigade_summary_days_table"; + } + + public BrigadeDaySummaryEntity(){ + + } + + public BrigadeDaySummaryEntity(BrigadeEntity boroughInfo, int nYear, int nMonth, int nDay){ + if(boroughInfo != null){ + brigade = boroughInfo.getBrigade(); + year = nYear; + month = nMonth; + day = nDay; + String strID = brigade + year+month+day; + setId(strID); + + guarder_sign = 0; + police_sign = 0; + volunteer_sign = 0; + protector_sign = 0; + visitor = 0; + visitor_vehicles = 0; + danger_count = 0; + pushalarm_count = 0; + kitchenwarn = 0; + vehicle_tired = 0; + vehicle_speed = 0; + vehicle_fence = 0; + + guarder_percent = 0; + police_percent = 0; + staff_percent = 0; + protector_percent = 0; + + score_total = 0; + totalsign = 0; + } + } + + public int getGuarder_sign() { + return guarder_sign; + } + + public void setGuarder_sign(int guarder_sign) { + this.guarder_sign = guarder_sign; + } + + public int getPolice_sign() { + return police_sign; + } + + public void setPolice_sign(int police_sign) { + this.police_sign = police_sign; + } + + public int getVolunteer_sign() { + return volunteer_sign; + } + + public void setVolunteer_sign(int volunteer_sign) { + this.volunteer_sign = volunteer_sign; + } + + public int getProtector_sign() { + return protector_sign; + } + + public void setProtector_sign(int protector_sign) { + this.protector_sign = protector_sign; + } + + public int getVisitor() { + return visitor; + } + + public void setVisitor(int visitor) { + this.visitor = visitor; + } + + public int getVisitor_vehicles() { + return visitor_vehicles; + } + + public void setVisitor_vehicles(int visitor_vehicles) { + this.visitor_vehicles = visitor_vehicles; + } + + public int getDanger_count() { + return danger_count; + } + + public void setDanger_count(int danger_count) { + this.danger_count = danger_count; + } + + public int getPushalarm_count() { + return pushalarm_count; + } + + public void setPushalarm_count(int pushalarm_count) { + this.pushalarm_count = pushalarm_count; + } + + public int getKitchenwarn() { + return kitchenwarn; + } + + public void setKitchenwarn(int kitchenwarn) { + this.kitchenwarn = kitchenwarn; + } + + public int getVehicle_tired() { + return vehicle_tired; + } + + public void setVehicle_tired(int vehicle_tired) { + this.vehicle_tired = vehicle_tired; + } + + public int getVehicle_speed() { + return vehicle_speed; + } + + public void setVehicle_speed(int vehicle_speed) { + this.vehicle_speed = vehicle_speed; + } + + public int getVehicle_fence() { + return vehicle_fence; + } + + public void setVehicle_fence(int vehicle_fence) { + this.vehicle_fence = vehicle_fence; + } + + + public double getGuarder_percent() { + return guarder_percent; + } + + public void setGuarder_percent(double guarder_percent) { + this.guarder_percent = guarder_percent; + } + + public double getPolice_percent() { + return police_percent; + } + + public void setPolice_percent(double police_percent) { + this.police_percent = police_percent; + } + + public double getStaff_percent() { + return staff_percent; + } + + public void setStaff_percent(double staff_percent) { + this.staff_percent = staff_percent; + } + + public double getProtector_percent() { + return protector_percent; + } + + public void setProtector_percent(double protector_percent) { + this.protector_percent = protector_percent; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public static List QueryMonth(DataSource dataSource, String boroughName, int nYear, int nMonth) { + BoroughDaySummaryEntity info = new BoroughDaySummaryEntity(); + String sql = "select * from " + info.tableName() + " where borough='" + boroughName + "' and year ='" + nYear + "' and month ='" +nMonth + "'" ; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, BoroughDaySummaryEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public double getScore_total() { + return score_total; + } + + public void setScore_total(double score_total) { + this.score_total = score_total; + } + + public void setTotalsign(int totalsign) { + this.totalsign = totalsign; + } + + public double getTotalsign() { + return totalsign; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/SchoolPoliceSummary.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/SchoolPoliceSummary.java new file mode 100644 index 0000000..4833072 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/SchoolPoliceSummary.java @@ -0,0 +1,26 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import lombok.Data; + +@Data +public class SchoolPoliceSummary { + private String station; + + private int guardCount; + private int policeCount; + private int volunteerCount; + private int teacherCount; + + private int guardSignCount; + private int policeSignCount; + private int volunteerSignCount; + private int teacherSignCount; + + private int newsPeakGuard; + private int newsLaw; + private int newsExercise; + private int newsOther; + + private int securityCheckCount; + private int pendingProcessCount; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/StationDaySummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/StationDaySummaryEntity.java new file mode 100644 index 0000000..1feb4cb --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/StationDaySummaryEntity.java @@ -0,0 +1,364 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class StationDaySummaryEntity extends SQLDataObject { + @JPos(index = 0,identify = true,filter = true) + private String id; + @JPos(index = 1) + private int guarder_sign; + @JPos(index = 2) + private int police_sign; + @JPos(index = 3) + private int volunteer_sign; + @JPos(index = 4) + private int protector_sign; + @JPos(index = 5) + private int visitor; + @JPos(index = 6) + private int visitor_vehicles; + @JPos(index = 7) + private int danger_count; + @JPos(index = 8) + private int pushalarm_count; + @JPos(index = 9) + private int kitchenwarn; + @JPos(index = 10) + private int vehicle_tired; + @JPos(index = 11) + private int vehicle_speed; + @JPos(index = 12) + private int vehicle_fence; + @JPos(index = 13) + private int totalsign; + @JPos(index = 14) + private double guarder_percent; + @JPos(index = 15) + private double police_percent; + @JPos(index = 16) + private double staff_percent; + @JPos(index = 17) + private double protector_percent; + @JPos(index = 18,timekey = true, orderkey = true) + private Date timestamp; + + @JPos(index = 19) + private double score_total; + + @JPos(index = 20,primary = true,filter = true) + private String station; + @JPos(index = 21,primary = true,filter = true) + private String detachment; + @JPos(index = 22,primary = true,filter = true) + private String borough; + @JPos(index = 23,primary = true,filter = true) + private String brigade; + + @JPos(index = 24,primary = true,filter = true) + private int year; + @JPos(index = 25,primary = true,filter = true) + private int month; + @JPos(index = 26,primary = true,filter = true) + private int day; + + + public String tableName(){ + return "station_summary_days_table"; + } + + public StationDaySummaryEntity(){ + + } + + public StationDaySummaryEntity(FireStationBaseInfoEntity schoolInfo, int nYear, int nMonth, int nDay){ + if(schoolInfo != null){ + station = schoolInfo.getName(); + borough = schoolInfo.getBorough(); + detachment = schoolInfo.getDetachment(); + brigade = schoolInfo.getBrigade(); + year = nYear; + month = nMonth; + day = nDay; + id = brigade + borough + detachment + station + year+month+day; + + guarder_sign = 0; + police_sign = 0; + volunteer_sign = 0; + protector_sign = 0; + visitor = 0; + visitor_vehicles = 0; + danger_count = 0; + pushalarm_count = 0; + kitchenwarn = 0; + vehicle_tired = 0; + vehicle_speed = 0; + vehicle_fence = 0; + guarder_percent = 0; + police_percent = 0; + staff_percent = 0; + protector_percent = 0; + + score_total = 0; + } + } + + + public int getGuarder_sign() { + return guarder_sign; + } + + public void setGuarder_sign(int guarder_sign) { + this.guarder_sign = guarder_sign; + } + + public int getPolice_sign() { + return police_sign; + } + + public void setPolice_sign(int police_sign) { + this.police_sign = police_sign; + } + + public int getVolunteer_sign() { + return volunteer_sign; + } + + public void setVolunteer_sign(int volunteer_sign) { + this.volunteer_sign = volunteer_sign; + } + + public int getProtector_sign() { + return protector_sign; + } + + public void setProtector_sign(int protector_sign) { + this.protector_sign = protector_sign; + } + + public int getVisitor() { + return visitor; + } + + public void setVisitor(int visitor) { + this.visitor = visitor; + } + + public int getVisitor_vehicles() { + return visitor_vehicles; + } + + public void setVisitor_vehicles(int visitor_vehicles) { + this.visitor_vehicles = visitor_vehicles; + } + + public int getDanger_count() { + return danger_count; + } + + public void setDanger_count(int danger_count) { + this.danger_count = danger_count; + } + + public int getPushalarm_count() { + return pushalarm_count; + } + + public void setPushalarm_count(int pushalarm_count) { + this.pushalarm_count = pushalarm_count; + } + + public int getKitchenwarn() { + return kitchenwarn; + } + + public void setKitchenwarn(int kitchenwarn) { + this.kitchenwarn = kitchenwarn; + } + + public int getVehicle_tired() { + return vehicle_tired; + } + + public void setVehicle_tired(int vehicle_tired) { + this.vehicle_tired = vehicle_tired; + } + + public int getVehicle_speed() { + return vehicle_speed; + } + + public void setVehicle_speed(int vehicle_speed) { + this.vehicle_speed = vehicle_speed; + } + + public int getVehicle_fence() { + return vehicle_fence; + } + + public void setVehicle_fence(int vehicle_fence) { + this.vehicle_fence = vehicle_fence; + } + + public double getGuarder_percent() { + return guarder_percent; + } + + public void setGuarder_percent(double guarder_percent) { + this.guarder_percent = guarder_percent; + } + + public double getPolice_percent() { + return police_percent; + } + + public void setPolice_percent(double police_percent) { + this.police_percent = police_percent; + } + + public double getStaff_percent() { + return staff_percent; + } + + public void setStaff_percent(double staff_percent) { + this.staff_percent = staff_percent; + } + + public double getProtector_percent() { + return protector_percent; + } + + public void setProtector_percent(double protector_percent) { + this.protector_percent = protector_percent; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public static List QueryMonth(DataSource dataSource, String stationName, int nYear, int nMonth) { + StationDaySummaryEntity info = new StationDaySummaryEntity(); + String sql = "select * from " + info.tableName() + " where station='" + stationName + "' and year ='" + nYear + "' and month ='" +nMonth + "'" ; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, StationDaySummaryEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public static List QueryBoroughOneDay(DataSource dataSource, String boroughName, int nYear, int nMonth, int nDay) { + StationDaySummaryEntity info = new StationDaySummaryEntity(); + String sql = "select * from " + info.tableName() + " where borough='" + boroughName + "' and year ='" + nYear + "' and month ='" +nMonth + "' and day ='" +nDay + "'"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, StationDaySummaryEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public static List QuerySignedSchoolOneDay(DataSource dataSource, String brigadeName, int nYear, int nMonth, int nDay) { + StationDaySummaryEntity info = new StationDaySummaryEntity(); + String sql = "select * from " + info.tableName() + " where brigade='" + brigadeName + "' and year ='" + nYear + "' and month ='" +nMonth + "' and day ='" +nDay + "' and totalsign > 0" ; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, StationDaySummaryEntity.class); + return list; + } catch (Exception e) { + + } + return null; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public double getScore_total() { + return score_total; + } + + public void setScore_total(double score_total) { + this.score_total = score_total; + } + + public int getTotalsign() { + return totalsign; + } + + public void setTotalsign(int totalsign) { + this.totalsign = totalsign; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/StationMonthSummaryEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/StationMonthSummaryEntity.java new file mode 100644 index 0000000..f1509c4 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/statistics/StationMonthSummaryEntity.java @@ -0,0 +1,293 @@ +package com.jingyi.iotserver.firestationport.model.statistics; + +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + +public class StationMonthSummaryEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String id; + @JPos(index = 1) + private int guarder_sign; + @JPos(index = 2) + private int police_sign; + @JPos(index = 3) + private int volunteer_sign; + @JPos(index = 4) + private int protector_sign; + @JPos(index = 5) + private int visitor; + @JPos(index = 6) + private int visitor_vehicles; + @JPos(index = 7) + private int danger_count; + @JPos(index = 8) + private int pushalarm_count; + @JPos(index = 9) + private int kitchenwarn; + @JPos(index = 10) + private int vehicle_tired; + @JPos(index = 11) + private int vehicle_speed; + @JPos(index = 12) + private int vehicle_fence; + @JPos(index = 13) + private int totalsign; + @JPos(index = 14) + private double guarder_percent; + @JPos(index = 15) + private double police_percent; + @JPos(index = 16) + private double staff_percent; + @JPos(index = 17) + private double protector_percent; + @JPos(index = 18,timekey = true, orderkey = true) + private Date timestamp; + + @JPos(index = 19) + private double score_total; + + @JPos(index = 20,primary = true,filter = true) + private String station; + @JPos(index = 21,primary = true,filter = true) + private String detachment; + @JPos(index = 22,primary = true,filter = true) + private String borough; + @JPos(index = 23,primary = true,filter = true) + private String brigade; + + @JPos(index = 24,primary = true,filter = true) + private int year; + @JPos(index = 25,primary = true,filter = true) + private int month; + + public String tableName(){ + return "station_summary_months_table"; + } + + public StationMonthSummaryEntity(){ + + } + + public StationMonthSummaryEntity(FireStationBaseInfoEntity schoolInfo, int nYear, int nMonth){ + if(schoolInfo != null){ + station = schoolInfo.getName(); + borough = schoolInfo.getBorough(); + detachment = schoolInfo.getDetachment(); + brigade = schoolInfo.getBrigade(); + year = nYear; + month = nMonth; + String strID = brigade + borough + detachment + station + year + month; + setId(strID); + } + } + public int getGuarder_sign() { + return guarder_sign; + } + + public void setGuarder_sign(int guarder_sign) { + this.guarder_sign = guarder_sign; + } + + public int getPolice_sign() { + return police_sign; + } + + public void setPolice_sign(int police_sign) { + this.police_sign = police_sign; + } + + public int getVolunteer_sign() { + return volunteer_sign; + } + + public void setVolunteer_sign(int volunteer_sign) { + this.volunteer_sign = volunteer_sign; + } + + public int getProtector_sign() { + return protector_sign; + } + + public void setProtector_sign(int protector_sign) { + this.protector_sign = protector_sign; + } + + public int getVisitor() { + return visitor; + } + + public void setVisitor(int visitor) { + this.visitor = visitor; + } + + public int getVisitor_vehicles() { + return visitor_vehicles; + } + + public void setVisitor_vehicles(int visitor_vehicles) { + this.visitor_vehicles = visitor_vehicles; + } + + public int getDanger_count() { + return danger_count; + } + + public void setDanger_count(int danger_count) { + this.danger_count = danger_count; + } + + public int getPushalarm_count() { + return pushalarm_count; + } + + public void setPushalarm_count(int pushalarm_count) { + this.pushalarm_count = pushalarm_count; + } + + public int getKitchenwarn() { + return kitchenwarn; + } + + public void setKitchenwarn(int kitchenwarn) { + this.kitchenwarn = kitchenwarn; + } + + public int getVehicle_tired() { + return vehicle_tired; + } + + public void setVehicle_tired(int vehicle_tired) { + this.vehicle_tired = vehicle_tired; + } + + public int getVehicle_speed() { + return vehicle_speed; + } + + public void setVehicle_speed(int vehicle_speed) { + this.vehicle_speed = vehicle_speed; + } + + public int getVehicle_fence() { + return vehicle_fence; + } + + public void setVehicle_fence(int vehicle_fence) { + this.vehicle_fence = vehicle_fence; + } + + public double getGuarder_percent() { + return guarder_percent; + } + + public void setGuarder_percent(double guarder_percent) { + this.guarder_percent = guarder_percent; + } + + public double getPolice_percent() { + return police_percent; + } + + public void setPolice_percent(double police_percent) { + this.police_percent = police_percent; + } + + public double getStaff_percent() { + return staff_percent; + } + + public void setStaff_percent(double staff_percent) { + this.staff_percent = staff_percent; + } + + public double getProtector_percent() { + return protector_percent; + } + + public void setProtector_percent(double protector_percent) { + this.protector_percent = protector_percent; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public double getScore_total() { + return score_total; + } + + public void setScore_total(double score_total) { + this.score_total = score_total; + } + + + public int getTotalsign() { + return totalsign; + } + + public void setTotalsign(int totalsign) { + this.totalsign = totalsign; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/talk/TalkPlatformAccountInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/model/talk/TalkPlatformAccountInfo.java new file mode 100644 index 0000000..9062bfe --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/talk/TalkPlatformAccountInfo.java @@ -0,0 +1,63 @@ +package com.jingyi.iotserver.firestationport.model.talk; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +public class TalkPlatformAccountInfo extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true,orderkey = true) + private String account; + @JPos(index = 1) + private String username; + @JPos(index = 2) + private String password; + + @JPos(index=3,filter = true) + private String scopelevel;//master brigade borough detachment station + @JPos(index=4,filter = true) + private String levelvalue; + + public void setAccount(String account) { + this.account = account; + } + + public String getAccount() { + return account; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPassword() { + return password; + } + + public void setScopelevel(String scopelevel) { + this.scopelevel = scopelevel; + } + + public String getScopelevel() { + return scopelevel; + } + + public void setLevelvalue(String levelvalue) { + this.levelvalue = levelvalue; + } + + public String getLevelvalue() { + return levelvalue; + } + + @Override + public String tableName() { + return "firectrl_talk_platform_account_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentEntity.java new file mode 100644 index 0000000..f8c36d8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentEntity.java @@ -0,0 +1,190 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class AssignmentEntity extends SQLDataObject { + @JPos(index = 0,identify = true) + int id; + @JPos(index = 1,primary = true,filter = true) + private String assignmentid; + @JPos(index = 2,filter = true) + private String title; + @JPos(index = 3,strlen = 4096) + private String content; + @JPos(index = 4,filter = true) + private String sender; + @JPos(index = 5) + private String receiver; + @JPos(index = 6,filter = true) + private String sendtype; + @JPos(index = 7,filter = true) + private String type; + @JPos(index = 8) + private String address; + @JPos(index = 9,timekey = true,orderkey = true,update = false) + private Date timestamp; + + @JPos(index = 10,filter = true) + private String brigade; + @JPos(index = 11,filter = true) + private String borough; + @JPos(index = 12,filter = true) + private String detachment; + @JPos(index = 13,filter = true) + private String station; + + @JPos(index = 14) + private double longitude; + @JPos(index = 15) + private double latitude; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setAssignmentid(String assignmentid) { + this.assignmentid = assignmentid; + } + + public String getAssignmentid() { + return assignmentid; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setSendtype(String sendtype) { + this.sendtype = sendtype; + } + + public String getSendtype() { + return sendtype; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public String tableName(){ + return "firectrl_assignment_info_table"; + } + + public static AssignmentEntity QueryAssignment(DataSource dataSource,String aid){ + AssignmentEntity as = new AssignmentEntity(); + String sql = "select * from "+as.tableName()+" where assignmentid='"+aid+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,AssignmentEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentEventEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentEventEntity.java new file mode 100644 index 0000000..26b34e9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentEventEntity.java @@ -0,0 +1,87 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.firestationport.model.station.FireMediaInfoEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class AssignmentEventEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String assignmentid; + @JPos(index = 1,primary = true,filter = true) + private String station; + @JPos(index = 2,primary = true,timekey = true,orderkey = true,update = false) + private Date timestamp; + @JPos(index = 3,filter = true) + private String prestate; + @JPos(index = 4,filter = true) + private String poststate; + @JPos(index = 5) + private double longitude; + @JPos(index = 6) + private double latitude; + + public void setAssignmentid(String assignmentid) { + this.assignmentid = assignmentid; + } + + public String getAssignmentid() { + return assignmentid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setPrestate(String prestate) { + this.prestate = prestate; + } + + public String getPrestate() { + return prestate; + } + + + public void setPoststate(String poststate) { + this.poststate = poststate; + } + + public String getPoststate() { + return poststate; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public String tableName(){ + return "firectrl_assignment_event_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentProcessInfoEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentProcessInfoEntity.java new file mode 100644 index 0000000..8c58105 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentProcessInfoEntity.java @@ -0,0 +1,86 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.utils.JPos; +import com.jingyi.iotserver.utils.SQLDataObject; + +import java.util.Date; + + +public class AssignmentProcessInfoEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String assignmentid; + @JPos(index = 1,filter = true) + private String alarmid; + @JPos(index = 2,primary = true,filter = true) + private String station; + @JPos(index = 3,filter = true) + private String reporter; + @JPos(index = 4,timekey = true,orderkey = true,update = false) + private Date reporttime; + @JPos(index = 5,filter = true) + private String commander; + @JPos(index = 6,strlen = 4096) + private String infolist; + + + public void setAssignmentid(String assignmentid) { + this.assignmentid = assignmentid; + } + + public String getAssignmentid() { + return assignmentid; + } + + public void setAlarmid(String alarmid) { + this.alarmid = alarmid; + } + + public String getAlarmid() { + return alarmid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setReporter(String reporter) { + this.reporter = reporter; + } + + public String getReporter() { + return reporter; + } + + public void setReporttime(Date reporttime) { + this.reporttime = reporttime; + } + + public Date getReporttime() { + return reporttime; + } + + public void setCommander(String commander) { + this.commander = commander; + } + + public String getCommander() { + return commander; + } + + public void setInfolist(String infolist) { + this.infolist = infolist; + } + + public String getInfolist() { + return infolist; + } + + @Override + public String tableName() { + return "firectrl_assignment_process_info_table"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentStatusEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentStatusEntity.java new file mode 100644 index 0000000..845b440 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/AssignmentStatusEntity.java @@ -0,0 +1,161 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.firestationport.model.station.StationRunningInfoEntity; +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class AssignmentStatusEntity extends SQLDataObject { + @JPos(index = 0) + private int id; + @JPos(index = 1,primary = true,filter = true) + private String assignmentid; + @JPos(index = 2,primary = true,filter = true) + private String station; + @JPos(index = 3,timekey = true,orderkey = true) + private Date receivetime; + @JPos(index = 4) + private Date processtime; + @JPos(index = 5) + private Date completetime; + @JPos(index = 6,filter = true) + private String state;//received processed completed +/* @JPos(index = 7,filter = true) + private String brigade; + @JPos(index = 8,filter = true) + private String borough; + @JPos(index = 9,filter = true) + private String detachment; +*/ + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setAssignmentid(String assignmentid) { + this.assignmentid = assignmentid; + } + + public String getAssignmentid() { + return assignmentid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setReceivetime(Date receivetime) { + this.receivetime = receivetime; + } + + public Date getReceivetime() { + return receivetime; + } + + public void setProcesstime(Date processtime) { + this.processtime = processtime; + } + + public Date getProcesstime() { + return processtime; + } + + public void setCompletetime(Date completetime) { + this.completetime = completetime; + } + + public Date getCompletetime() { + return completetime; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public String tableName(){ + return "firectrl_assignment_"+tableExtName+"_status_table"; + } +/* + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } +*/ + public boolean UpdateState(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"assignmentid",assignmentid); + cmd.appendKey("station",station); + /* cmd.appendKey("brigade",brigade); + cmd.appendKey("borough",borough); + cmd.appendKey("detachment",detachment); + */ + if(state==null) + return false; + if(state.equals("received")){ + cmd.appendValue("receivetime",receivetime); + }else if(state.equals("processed")){ + cmd.appendValue("processtime",processtime); + }else if(state.equals("completed")){ + cmd.appendValue("completetime",completetime); + }else + return false; + cmd.appendValue("state",state); + try{ + if(QueryIt(dataSource)==null) + Insert(dataSource); + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) { + return false; + } + }catch (Exception e){ + + } + return true; + } + + public static AssignmentStatusEntity QueryAssignmentStatus(DataSource dataSource,String aid,String st, int index){ + AssignmentStatusEntity as = new AssignmentStatusEntity(); + as.extendName(""+index); + String sql = "select * from "+as.tableName()+" where assignmentid='"+aid+"' and station='"+st+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,AssignmentStatusEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/NoticeEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/NoticeEntity.java new file mode 100644 index 0000000..ab8f627 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/NoticeEntity.java @@ -0,0 +1,149 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class NoticeEntity extends SQLDataObject { + @JPos(index = 0,identify = true) + private int id; + @JPos(index = 1,primary = true,filter = true) + private String noticeid; + @JPos(index = 2,filter = true) + private String title; + @JPos(index = 3,strlen = 4096) + private String content; + @JPos(index = 4,filter = true) + private String sender; + @JPos(index = 5) + private String receiver; + @JPos(index = 6,filter = true) + private String sendtype;//toclient togroup + @JPos(index = 7,timekey = true,orderkey = true,update = false) + private Date timestamp; + @JPos(index = 8,filter = true) + private String brigade; + @JPos(index = 9,filter = true) + private String borough; + @JPos(index = 10,filter = true) + private String detachment; + @JPos(index = 11,filter = true) + private String station; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setNoticeid(String noticeid) { + this.noticeid = noticeid; + } + + public String getNoticeid() { + return noticeid; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setSendtype(String sendtype) { + this.sendtype = sendtype; + } + + public String getSendtype() { + return sendtype; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String tableName(){ + return "firectrl_notice_info_table"; + } + + public static NoticeEntity QueryNotice(DataSource dataSource,String nid){ + NoticeEntity notice = new NoticeEntity(); + String sql = "select * from "+notice.tableName()+" where noticeid='"+nid+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,NoticeEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/NoticeStatusEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/NoticeStatusEntity.java new file mode 100644 index 0000000..98b58bd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/NoticeStatusEntity.java @@ -0,0 +1,70 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class NoticeStatusEntity extends SQLDataObject{ + @JPos(index = 0,update = false) + private int id; + @JPos(index = 1,primary = true,filter = true) + private String noticeid; + @JPos(index = 2,primary = true,filter = true) + private String station; + @JPos(index = 3,timekey = true,orderkey = true) + private Date readtime; + @JPos(index = 4) + private String state;//sent read + + public NoticeStatusEntity(){ + state = "sent"; + id = -1; + } + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setNoticeid(String noticeid) { + this.noticeid = noticeid; + } + + public String getNoticeid() { + return noticeid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setReadtime(Date readtime) { + this.readtime = readtime; + } + + public Date getReadtime() { + return readtime; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public String tableName(){ + return "firectrl_notice_"+tableExtName+"_status_table"; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/todev/TimingJobEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/TimingJobEntity.java new file mode 100644 index 0000000..edaf00e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/todev/TimingJobEntity.java @@ -0,0 +1,117 @@ +package com.jingyi.iotserver.firestationport.model.todev; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class TimingJobEntity extends SQLDataObject { + @JPos(index = 0,primary = true,filter = true) + private String number; + @JPos(index = 1,filter = true) + private String status; + @JPos(index = 2,filter = true) + private String username; + @JPos(index = 3,filter = true) + private String type; + @JPos(index = 4,strlen = 1024) + private String scope; + @JPos(index = 5,timekey = true,orderkey = true) + private Date triggertime; + @JPos(index = 6,strlen = 1024) + private String data; + + public void setNumber(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getScope() { + return scope; + } + + public void setTriggertime(Date triggertime) { + this.triggertime = triggertime; + } + + public Date getTriggertime() { + return triggertime; + } + + public void setData(String data) { + this.data = data; + } + + public String getData() { + return data; + } + + public String tableName( ){ + return "iotserver_timing_job_table"; + } + + + + public static TimingJobEntity QueryTimingJob(DataSource dataSource, String numb){ + TimingJobEntity job = new TimingJobEntity(); + String sql = "select * from "+job.tableName()+" where number='"+numb+"'"; + + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,TimingJobEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } + + + + public List queryAcitveList(DataSource dataSource){ + String condition = queryCondition(); + String sql = "select * from "+tableName()+" where status='active' and triggertime>'"+SQLTools.formatDate(new Date())+"' "; + if(condition!=null){ + sql += " and "+condition; + } + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, TimingJobEntity.class); + return list; + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/model/update/SoftwareUpdateTaskEntity.java b/src/main/java/com/jingyi/iotserver/firestationport/model/update/SoftwareUpdateTaskEntity.java new file mode 100644 index 0000000..0cd0e58 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/model/update/SoftwareUpdateTaskEntity.java @@ -0,0 +1,165 @@ +package com.jingyi.iotserver.firestationport.model.update; + +import com.jingyi.iotserver.utils.*; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +public class SoftwareUpdateTaskEntity extends SQLDataObject{ + @JPos(index=0,primary = true,filter = true) + private String taskid; + @JPos(index=1,filter = true) + private String module; + @JPos(index=2) + private int versioncode; + @JPos(index=3) + private String versionname; + @JPos(index=4,filter = true) + private String hardware; + @JPos(index=5) + private String url; + @JPos(index=6,filter = true) + private String mode;//L2H|V2V + @JPos(index=7) + private int devversioncode; + @JPos(index=8) + private String description; + @JPos(index=9,filter = true) + private String status;//active|close + @JPos(index=10,timekey = true,orderkey = true) + private Date timestamp; + @JPos(index=11) + private String scope; + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setMode(String mode) { + this.mode = mode; + } + + public void setModule(String module) { + this.module = module; + } + + public String getModule() { + return module; + } + + public String getMode() { + return mode; + } + + public void setVersioncode(int versioncode) { + this.versioncode = versioncode; + } + + public int getVersioncode() { + return versioncode; + } + + public void setVersionname(String versionname) { + this.versionname = versionname; + } + + public String getVersionname() { + return versionname; + } + + public void setHardware(String hardware) { + this.hardware = hardware; + } + + public String getHardware() { + return hardware; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUrl() { + return url; + } + + public void setDevversioncode(int devversioncode) { + this.devversioncode = devversioncode; + } + + public int getDevversioncode() { + return devversioncode; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getScope() { + return scope; + } + + public String tableName(){ + return "firectrl_station_sw_update_task_table"; + } + + public boolean UpdateStatus(DataSource dataSource){ + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),"taskid",taskid); + cmd.appendValue("status",status); + if(status==null) + return false; + if(!status.equals("active")&&!status.equals("close")) + return false; + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) { + return false; + } + }catch (Exception e){ + + } + return true; + } + + public SoftwareUpdateTaskEntity QueryTask(DataSource dataSource, String tid){ + String sql = "select * from "+tableName()+" where taskid='"+tid+"'"; + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql,SoftwareUpdateTaskEntity.class); + if(list!=null) + return list.get(0); + }catch (Exception e){ + + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/DataStatisticsService.java b/src/main/java/com/jingyi/iotserver/firestationport/services/DataStatisticsService.java new file mode 100644 index 0000000..dbd4edd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/DataStatisticsService.java @@ -0,0 +1,1518 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.clientmanage.model.BrigadeEntity; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.firestationport.model.mdev.MDevPictureEntity; +import com.jingyi.iotserver.firestationport.model.school.GuardSignEventEntity; +import com.jingyi.iotserver.firestationport.model.school.PersonBlacklistEntity; +import com.jingyi.iotserver.firestationport.model.school.SchoolCommonFileEntity; +import com.jingyi.iotserver.firestationport.model.school.SchoolNewsEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.station.CommonDefine; +import com.jingyi.iotserver.firestationport.model.statistics.*; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationSchoolEntity; +import com.jingyi.iotserver.firestationport.services.analyze.StatisticsMessage; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.HttpTools; +import okhttp3.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.FileCopyUtils; + +import javax.sql.DataSource; +import java.io.*; +import java.net.HttpURLConnection; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.TimeUnit; + +@Service +public class DataStatisticsService { + @Autowired + private DataSource dataSource; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private StationServices stationServices; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private MessagePublisher messagePublisher; + + ConcurrentLinkedQueue mStatisticsMsgQueue = new ConcurrentLinkedQueue(); + private Thread statisticsProcessService = null; + + + ConcurrentLinkedQueue mNewsMsgQueue = new ConcurrentLinkedQueue(); + ConcurrentLinkedQueue mSchoolFileMsgQueue = new ConcurrentLinkedQueue(); + + ConcurrentLinkedQueue mGuardSignMsgQueue = new ConcurrentLinkedQueue(); + private Thread newsAgentProcessService = null; + + private boolean blInited = false; + public void Init(){ + if(blInited) + return ; + blInited = true; + statisticsProcessService = new Thread(){ + public void run(){ + while(true){ + try { + if(mStatisticsMsgQueue.size()>0){ + StatisticsMessage msg = mStatisticsMsgQueue.poll(); + processStaticticsEvent(msg); + Thread.sleep(10); + continue; + } + }catch (Exception e){ + } + + try{ + Thread.sleep(2*60*1000); + }catch (Exception e){ + + } + } + } + }; + statisticsProcessService.start(); + + newsAgentProcessService = new Thread(){ + public void run(){ + while(true){ + try { + if(mNewsMsgQueue.size()>0){ + SchoolNewsEntity msg = mNewsMsgQueue.poll(); + processAgentNews(msg); + Thread.sleep(10); + continue; + } + + if(mGuardSignMsgQueue.size()>0){ + GuardSignEventEntity msg = mGuardSignMsgQueue.poll(); + processAgentSign(msg); + Thread.sleep(10); + continue; + } + + if(mSchoolFileMsgQueue.size()>0){ + SchoolCommonFileEntity msg = mSchoolFileMsgQueue.poll(); + processAgentCommonFile(msg); + Thread.sleep(10); + continue; + } + + }catch (Exception e){ + } + + try{ + Thread.sleep(2*60*1000); + }catch (Exception e){ + + } + } + } + }; + newsAgentProcessService.start(); + } + + public void addNewsAgentMessage(SchoolNewsEntity msg) { + try { + mNewsMsgQueue.add(msg); + }catch (Exception e){ + } + } + + public void addGuardSignAgentMessage(GuardSignEventEntity msg) { + try { + mGuardSignMsgQueue.add(msg); + }catch (Exception e){ + } + } + public void addCommonFileAgentMessage(SchoolCommonFileEntity msg) { + try { + mSchoolFileMsgQueue.add(msg); + }catch (Exception e){ + } + } + + public void addStatisticsMessage(StatisticsMessage msg) { + try { + mStatisticsMsgQueue.add(msg); + }catch (Exception e){ + } + } + + public void processStaticticsEvent(StatisticsMessage msg){ + try { + if(msg == null){ + return; + } + switch (msg.getCode()){ + case StatisticsMessage.School_Day_Summary_Code:{ + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource, msg.getStation()); + if(st!=null){ + Calendar previousDayTime = Calendar.getInstance(); + int nYear = previousDayTime.get(Calendar.YEAR); + int nMonth = previousDayTime.get(Calendar.MONTH)+1; + int nDay = previousDayTime.get(Calendar.DAY_OF_MONTH); + if(msg.getYear() > 0){ + nYear = msg.getYear(); + } + if(msg.getMonth() > 0){ + nMonth = msg.getMonth(); + } + if(msg.getDay() > 0){ + nDay = msg.getDay(); + } + + //计算指定station当天数据 + calcStationDaySummary(st, nYear, nMonth, nDay); + + //计算指定boroug当天数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(st.getBorough()); + calcBorough.setBrigade(st.getBrigade()); + + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 当天数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(st.getBrigade()); + + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + + } + }break; + case StatisticsMessage.School_Month_Summary_Code:{ + + }break; + case StatisticsMessage.Borough_Day_Summary_Code:{ + + }break; + case StatisticsMessage.Borough_Month_Summary_Code:{ + + }break; + case StatisticsMessage.All_Summary_Code:{ + Calendar previousDayTime = Calendar.getInstance(); + int nYear = previousDayTime.get(Calendar.YEAR); + int nMonth = previousDayTime.get(Calendar.MONTH)+1; + int nDay = previousDayTime.get(Calendar.DAY_OF_MONTH); + + //TODO:重置station当天实时数据 FireStationSchoolEntity + + calcAllStationLastDaySummary(); + calcAllStationMonthSummary(nYear, nMonth); + calcAllBoroughDaySummary(nYear, nMonth, nDay); + calcAllBoroughMonthSummary(nYear, nMonth); + + calcAllBrigadeDaySummary(nYear, nMonth, nDay); + calcAllBrigadeMonthSummary(nYear, nMonth); + + }break; + case StatisticsMessage.School_Volunteer_Sign:{ + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource, msg.getStation()); + if(st!=null){ + addVolunteerSignEvent(st); + } + }break; + case StatisticsMessage.School_Policeman_Sign:{ + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource, msg.getStation()); + if(st!=null){ + addPolicemanSignEvent(st); + } + }break; + case StatisticsMessage.School_Guard_Sign:{ + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource, msg.getStation()); + if(st!=null){ + addGuarderSignEvent(st); + } + }break; + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + + public void calcAllStationLastDaySummary(){ + try { + List stationList = stationServices.queryAllStationList(5000,0); + if(stationList == null){ + return; + } + + if(stationList.size() <= 0){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + for(FireStationBaseInfoEntity calcStation:stationList){ + // StationLastDaySummaryInfo stationLastSummaryInfo = calcStationLastSummary(calcStation); + createStationDayBaseSummary(calcStation, nYear, nMonth, nDay); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllStationDaySummary(int nYear, int nMonth, int nDay){ + try { + List stationList = stationServices.queryAllStationList(5000,0); + if(stationList == null){ + return; + } + + if(stationList.size() <= 0){ + return; + } + + for(FireStationBaseInfoEntity calcStation:stationList){ + calcStationDaySummary(calcStation, nYear, nMonth, nDay); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllStationMonthSummary(int nYear, int nMonth){ + try { + List stationList = stationServices.queryAllStationList(5000,0); + if(stationList == null){ + return; + } + + if(stationList.size() <= 0){ + return; + } + + for(FireStationBaseInfoEntity calcStation:stationList){ + calcStationMonthSummary(calcStation, nYear, nMonth); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllBoroughDaySummary(int nYear, int nMonth, int nDay){ + try { + List boroughList = stationServices.queryAllBoroughList(5000,0); + if(boroughList == null){ + return; + } + + if(boroughList.size() <= 0){ + return; + } + System.out.println("Statistics: calcBoroughDaySummary borough count " + boroughList.size()); + for(BoroughEntity calcBorough:boroughList){ + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllBoroughMonthSummary(int nYear, int nMonth){ + try { + List boroughList = stationServices.queryAllBoroughList(5000,0); + if(boroughList == null){ + return; + } + + if(boroughList.size() <= 0){ + return; + } + for(BoroughEntity calcBorough:boroughList){ + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllBrigadeDaySummary(int nYear, int nMonth, int nDay){ + try { + List brigadeList = stationServices.queryAllBrigadeList(5000,0); + if(brigadeList == null){ + return; + } + + if(brigadeList.size() <= 0){ + return; + } + System.out.println("Statistics: calcBoroughDaySummary borough count " + brigadeList.size()); + for(BrigadeEntity calcBrigade:brigadeList){ + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllBrigadeMonthSummary(int nYear, int nMonth){ + try { + List brigadeList = stationServices.queryAllBrigadeList(5000,0); + if(brigadeList == null){ + return; + } + + if(brigadeList.size() <= 0){ + return; + } + for(BrigadeEntity calcBrigade:brigadeList){ + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + + /* + ***计算4级单位统计信息 + */ + /* + public StationLastDaySummaryInfo calcStationLastSummary(FireStationBaseInfoEntity calcStation){ + try { + StationLastDaySummaryInfo stationLastSummaryInfo = new StationLastDaySummaryInfo(calcStation); + stationLastSummaryInfo.setTimestamp(new Date()); + + FireStationSchoolEntity schoolInfo = new FireStationSchoolEntity(stationLastSummaryInfo.getStation()); + schoolInfo = (FireStationSchoolEntity)schoolInfo.QueryIt(dataSource); + if(schoolInfo == null){ + StationLastDaySummaryInfo oldStationDay = (StationLastDaySummaryInfo)stationLastSummaryInfo.QueryIt(dataSource); + if(oldStationDay == null){ + stationLastSummaryInfo.Insert(dataSource); + }else{ + stationLastSummaryInfo.Update(dataSource); + } + return stationLastSummaryInfo; + } + double fScore = 0; + stationLastSummaryInfo.setSealzone(schoolInfo.getSealzone()); + if(schoolInfo.getSealzone() > 0){ + fScore += 10; + } + stationLastSummaryInfo.setCollision(schoolInfo.getCollision()); + if(schoolInfo.getCollision() > 0){ + fScore += 10; + } + stationLastSummaryInfo.setAlarmpush(schoolInfo.getAlarmpush()); + if(schoolInfo.getAlarmpush() > 0){ + fScore += 10; + } + stationLastSummaryInfo.setIpclinked(schoolInfo.getIpclinked()); + if(schoolInfo.getIpclinked() > 0){ + fScore += 10; + } + stationLastSummaryInfo.setSchoolbox(schoolInfo.getSchoolbox()); + if(schoolInfo.getSchoolbox() > 0){ + fScore += 10; + } + stationLastSummaryInfo.setKitchensystem(schoolInfo.getKitchensystem()); + if(schoolInfo.getKitchensystem() > 0){ + fScore += 10; + } + + if(schoolInfo.getGuardersmax() > 0){ + double guardCountScore = 5*schoolInfo.getGuarders() / schoolInfo.getGuardersmax(); + if(guardCountScore > 5){ + guardCountScore = 5; + } + fScore += guardCountScore; + } + if(schoolInfo.getGuarders() > 0){ + double guardSignScore = 5*schoolInfo.getGuardershould() / schoolInfo.getGuarders(); + if(guardSignScore > 5){ + guardSignScore = 5; + } + fScore += guardSignScore; + } + + if(stationLastSummaryInfo.getGuarder_sign() > 0){ + fScore += 10; + } + + if(fScore > 100){ + fScore = 100; + } + stationLastSummaryInfo.setScore_total(fScore); + + StationLastDaySummaryInfo oldStationDay = (StationLastDaySummaryInfo)stationLastSummaryInfo.QueryIt(dataSource); + if(oldStationDay == null){ + stationLastSummaryInfo.Insert(dataSource); + }else{ + stationLastSummaryInfo.Update(dataSource); + } + + return stationLastSummaryInfo; + }catch (Exception e){ + e.printStackTrace(); + } + return null; + } + + public void calcStationDaySummary(StationLastDaySummaryInfo lastInfo){ + try { + if(lastInfo == null){ + return; + } + StationDaySummaryEntity newStationDay = new StationDaySummaryEntity(lastInfo); + if(newStationDay.getId() == null){ + return; + } + + StationDaySummaryEntity oldStationDay = (StationDaySummaryEntity)newStationDay.QueryIt(dataSource); + if(oldStationDay == null){ + newStationDay.Insert(dataSource); + }else{ + newStationDay.Update(dataSource); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + */ + + public void calcStationDaySummary(FireStationBaseInfoEntity calcStation, int nYear, int nMonth, int nDay){ + try { + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(calcStation, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + createStationDayBaseSummary(calcStation, nYear, nMonth, nDay); + return; + } + double fScore = 0; + FireStationSchoolEntity schoolInfo = new FireStationSchoolEntity(newStationDay.getStation()); + schoolInfo = (FireStationSchoolEntity)schoolInfo.QueryIt(dataSource); + if(schoolInfo == null){ + if(schoolInfo.getGuardersmax() > 0){ + double guardCountScore = 5*schoolInfo.getGuarders() / schoolInfo.getGuardersmax(); + if(guardCountScore > 5){ + guardCountScore = 5; + } + fScore += guardCountScore; + } + if(schoolInfo.getGuarders() > 0){ + double guardSignScore = 5*schoolInfo.getGuardershould() / schoolInfo.getGuarders(); + if(guardSignScore > 5){ + guardSignScore = 5; + } + fScore += guardSignScore; + } + } + + //TODO: 统计得分 + int signedTotal = newStationDay.getGuarder_sign() + newStationDay.getPolice_sign() + newStationDay.getVolunteer_sign(); + newStationDay.setTotalsign(signedTotal); + int scoreGuarderSign = newStationDay.getGuarder_sign(); + if(scoreGuarderSign > 10){ + scoreGuarderSign = 10; + } + fScore += scoreGuarderSign; + + int scorePushAlarm = 2*newStationDay.getPushalarm_count(); + if(scorePushAlarm > 6){ + scorePushAlarm = 6; + } + fScore -= scorePushAlarm; + + int scoreDanger = 2*newStationDay.getDanger_count(); + if(scoreDanger > 10){ + scoreDanger = 10; + } + fScore -= scoreDanger; + + if(fScore > 100){ + fScore = 100; + } + + newStationDay.setScore_total(fScore); + newStationDay.setTimestamp(new Date()); + + newStationDay.Update(dataSource); + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcStationDaySummary(StationDaySummaryEntity calcStationDayInfo){ + try { + if(calcStationDayInfo == null){ + return; + } + + FireStationSchoolEntity schoolInfo = new FireStationSchoolEntity(calcStationDayInfo.getStation()); + schoolInfo = (FireStationSchoolEntity)schoolInfo.QueryIt(dataSource); + double fScore = 0; + if(schoolInfo != null){ + if(schoolInfo.getGuardersmax() > 0){ + double guardCountScore = 5*schoolInfo.getGuarders() / schoolInfo.getGuardersmax(); + if(guardCountScore > 5){ + guardCountScore = 5; + } + fScore += guardCountScore; + } + if(schoolInfo.getGuarders() > 0){ + double guardSignScore = 5*schoolInfo.getGuardershould() / schoolInfo.getGuarders(); + if(guardSignScore > 5){ + guardSignScore = 5; + } + fScore += guardSignScore; + } + } + + //TODO: 统计得分 + int signedTotal = calcStationDayInfo.getGuarder_sign() + calcStationDayInfo.getPolice_sign() + calcStationDayInfo.getVolunteer_sign(); + calcStationDayInfo.setTotalsign(signedTotal); + + int scoreGuarderSign = calcStationDayInfo.getGuarder_sign(); + if(scoreGuarderSign > 10){ + scoreGuarderSign = 10; + } + fScore += scoreGuarderSign; + + int scorePushAlarm = 2*calcStationDayInfo.getPushalarm_count(); + if(scorePushAlarm > 6){ + scorePushAlarm = 6; + } + fScore -= scorePushAlarm; + + int scoreDanger = 2*calcStationDayInfo.getDanger_count(); + if(scoreDanger > 10){ + scoreDanger = 10; + } + fScore -= scoreDanger; + + if(fScore > 100){ + fScore = 100; + } + System.out.println("Statistics: calcStationDaySummary --" + calcStationDayInfo.getStation() + " " + fScore); + calcStationDayInfo.setScore_total(fScore); + calcStationDayInfo.setTimestamp(new Date()); + + calcStationDayInfo.Update(dataSource); + + }catch (Exception e){ + e.printStackTrace(); + } + } + + private StationDaySummaryEntity createStationDayBaseSummary(FireStationBaseInfoEntity calcStation, int nYear, int nMonth, int nDay){ + StationDaySummaryEntity newStationDay = new StationDaySummaryEntity(calcStation, nYear, nMonth, nDay); + try { + StationDaySummaryEntity oldStationDay = (StationDaySummaryEntity)newStationDay.QueryIt(dataSource); + if(oldStationDay != null){ + //当天数据已经被创建,直接返回 + return oldStationDay; + } + + newStationDay.setTimestamp(new Date()); + + FireStationSchoolEntity schoolInfo = new FireStationSchoolEntity(newStationDay.getStation()); + schoolInfo = (FireStationSchoolEntity)schoolInfo.QueryIt(dataSource); + if(schoolInfo == null){ + //没有查询到学校数据,插入一条0分数据 + newStationDay.Insert(dataSource); + return newStationDay; + } + double fScore = 0; + + if(schoolInfo.getGuardersmax() > 0){ + double guardCountScore = 5*schoolInfo.getGuarders() / schoolInfo.getGuardersmax(); + if(guardCountScore > 5){ + guardCountScore = 5; + } + fScore += guardCountScore; + } + if(schoolInfo.getGuarders() > 0){ + double guardSignScore = 5*schoolInfo.getGuardershould() / schoolInfo.getGuarders(); + if(guardSignScore > 5){ + guardSignScore = 5; + } + fScore += guardSignScore; + } + //只有基础得分,没有动态数据得分 + + newStationDay.setScore_total(fScore); + + newStationDay.Insert(dataSource); + }catch (Exception e){ + e.printStackTrace(); + } + return newStationDay; + } + + public void calcStationMonthSummary(FireStationBaseInfoEntity calcStation, int nYear, int nMonth){ + try { + StationMonthSummaryEntity newStationMonth = new StationMonthSummaryEntity(calcStation, nYear, nMonth); + + List dayList = StationDaySummaryEntity.QueryMonth(dataSource, calcStation.getName(), nYear, nMonth); + + if(dayList == null){ + return; + } + if(dayList.size() <= 0){ + return; + } + int dayCount = dayList.size(); + int guarder_sign_month = 0; + int police_sign_month = 0; + int staff_sign_month = 0; + int protector_sign_month = 0; + int visitor_month = 0; + int visitor_vehicles_month = 0; + int danger_count_month = 0; + int pushalarm_count_month = 0; + int kitchenwarn_month = 0; + int vehicle_tired_month = 0; + int vehicle_speed_month = 0; + int vehicle_fence_month = 0; + double guarder_percent_month = 0; + double police_percent_month = 0; + double staff_percent_month = 0; + double protector_percent_month = 0; + + double score_total_month = 0.0; + + for (StationDaySummaryEntity daySummary:dayList) { + guarder_sign_month += daySummary.getGuarder_sign(); + police_sign_month += daySummary.getPolice_sign(); + staff_sign_month += daySummary.getVolunteer_sign(); + protector_sign_month += daySummary.getProtector_sign(); + visitor_month += daySummary.getVisitor(); + visitor_vehicles_month += daySummary.getVisitor_vehicles(); + danger_count_month += daySummary.getDanger_count(); + pushalarm_count_month += daySummary.getPushalarm_count(); + kitchenwarn_month += daySummary.getKitchenwarn(); + vehicle_tired_month += daySummary.getVehicle_tired(); + vehicle_speed_month += daySummary.getVehicle_speed(); + vehicle_fence_month += daySummary.getVehicle_fence(); + + guarder_percent_month += daySummary.getGuarder_percent(); + police_percent_month += daySummary.getPolice_percent(); + staff_percent_month += daySummary.getStaff_percent(); + protector_percent_month += daySummary.getProtector_percent(); + + score_total_month += daySummary.getScore_total(); + + } + + newStationMonth.setGuarder_sign(guarder_sign_month); + newStationMonth.setPolice_sign(police_sign_month); + newStationMonth.setVolunteer_sign(staff_sign_month); + newStationMonth.setProtector_sign(protector_sign_month); + int signedTotal = newStationMonth.getGuarder_sign() + newStationMonth.getPolice_sign() + newStationMonth.getVolunteer_sign(); + newStationMonth.setTotalsign(signedTotal); + + newStationMonth.setVisitor(visitor_month); + newStationMonth.setVisitor_vehicles(visitor_vehicles_month); + newStationMonth.setDanger_count(danger_count_month); + newStationMonth.setPushalarm_count(pushalarm_count_month); + newStationMonth.setKitchenwarn(kitchenwarn_month); + newStationMonth.setVehicle_tired(vehicle_tired_month); + newStationMonth.setVehicle_speed(vehicle_speed_month); + newStationMonth.setVehicle_fence(vehicle_fence_month); + + newStationMonth.setGuarder_percent(guarder_percent_month/dayCount); + newStationMonth.setPolice_percent(police_percent_month/dayCount); + newStationMonth.setStaff_percent(staff_percent_month/dayCount); + newStationMonth.setProtector_percent(protector_percent_month/dayCount); + + newStationMonth.setScore_total(score_total_month/dayCount); + + newStationMonth.setTimestamp(new Date()); + + StationMonthSummaryEntity oldStationMonth = (StationMonthSummaryEntity)newStationMonth.QueryIt(dataSource); + if(oldStationMonth == null){ + newStationMonth.Insert(dataSource); + }else{ + newStationMonth.Update(dataSource); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + /* + ***计算2级单位统计信息 + */ + + public void calcBoroughDaySummary(BoroughEntity calcBorough, int nYear, int nMonth, int nDay){ + try { + BoroughDaySummaryEntity newBoroughDay = new BoroughDaySummaryEntity(calcBorough, nYear, nMonth, nDay); + + List stationDayList = StationDaySummaryEntity.QueryBoroughOneDay(dataSource, calcBorough.getBorough(), nYear, nMonth, nDay); + + if(stationDayList == null){ + return; + } + int stationCount = stationDayList.size(); + if(stationCount <= 0){ + return; + } + System.out.println("Statistics: calcBoroughDaySummary " + stationCount); + int guarder_sign_borough = 0; + int police_sign_borough = 0; + int staff_sign_borough = 0; + int protector_sign_borough = 0; + int visitor_borough = 0; + int visitor_vehicles_borough = 0; + int danger_count_borough = 0; + int pushalarm_count_borough = 0; + int kitchenwarn_borough = 0; + int vehicle_tired_borough = 0; + int vehicle_speed_borough = 0; + int vehicle_fence_borough = 0; + + double guarder_percent_borough = 0; + double police_percent_borough = 0; + double staff_percent_borough = 0; + double protector_percent_borough = 0; + double score_borough = 0; + + for (StationDaySummaryEntity daySummary:stationDayList) { + guarder_sign_borough += daySummary.getGuarder_sign(); + police_sign_borough += daySummary.getPolice_sign(); + staff_sign_borough += daySummary.getVolunteer_sign(); + protector_sign_borough += daySummary.getProtector_sign(); + visitor_borough += daySummary.getVisitor(); + visitor_vehicles_borough += daySummary.getVisitor_vehicles(); + danger_count_borough += daySummary.getDanger_count(); + pushalarm_count_borough += daySummary.getPushalarm_count(); + kitchenwarn_borough += daySummary.getKitchenwarn(); + vehicle_tired_borough += daySummary.getVehicle_tired(); + vehicle_speed_borough += daySummary.getVehicle_speed(); + vehicle_fence_borough += daySummary.getVehicle_fence(); + guarder_percent_borough += daySummary.getGuarder_percent(); + police_percent_borough += daySummary.getPolice_percent(); + staff_percent_borough += daySummary.getStaff_percent(); + protector_percent_borough += daySummary.getProtector_percent(); + score_borough += daySummary.getScore_total(); + } + + newBoroughDay.setGuarder_sign(guarder_sign_borough); + newBoroughDay.setPolice_sign(police_sign_borough); + newBoroughDay.setVolunteer_sign(staff_sign_borough); + newBoroughDay.setProtector_sign(protector_sign_borough); + + int signedTotal = guarder_sign_borough + police_sign_borough + staff_sign_borough + protector_sign_borough; + newBoroughDay.setTotalsign(signedTotal); + + newBoroughDay.setVisitor(visitor_borough); + newBoroughDay.setVisitor_vehicles(visitor_vehicles_borough); + newBoroughDay.setDanger_count(danger_count_borough); + newBoroughDay.setPushalarm_count(pushalarm_count_borough); + newBoroughDay.setKitchenwarn(kitchenwarn_borough); + newBoroughDay.setVehicle_tired(vehicle_tired_borough); + newBoroughDay.setVehicle_speed(vehicle_speed_borough); + newBoroughDay.setVehicle_fence(vehicle_fence_borough); + + newBoroughDay.setGuarder_percent(guarder_percent_borough/stationCount); + newBoroughDay.setPolice_percent(police_percent_borough/stationCount); + newBoroughDay.setStaff_percent(staff_percent_borough/stationCount); + newBoroughDay.setProtector_percent(protector_percent_borough/stationCount); + newBoroughDay.setScore_total(score_borough/stationCount); + newBoroughDay.setTimestamp(new Date()); + + BoroughDaySummaryEntity oldBoroughDay = (BoroughDaySummaryEntity)newBoroughDay.QueryIt(dataSource); + if(oldBoroughDay == null){ + System.out.println("Statistics: calcBoroughDaySummary insert new"); + newBoroughDay.Insert(dataSource); + }else{ + System.out.println("Statistics: calcBoroughDaySummary update old"); + newBoroughDay.Update(dataSource); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcBoroughMonthSummary(BoroughEntity calcBorough, int nYear, int nMonth){ + try { + BoroughMonthSummaryEntity newBoroughMonth = new BoroughMonthSummaryEntity(calcBorough, nYear, nMonth); + + List dayList = BoroughDaySummaryEntity.QueryMonth(dataSource, calcBorough.getBorough(), nYear, nMonth); + + if(dayList == null){ + return; + } + if(dayList.size() <= 0){ + return; + } + int dayCount = dayList.size(); + int guarder_sign_month = 0; + int police_sign_month = 0; + int staff_sign_month = 0; + int protector_sign_month = 0; + int visitor_month = 0; + int visitor_vehicles_month = 0; + int danger_count_month = 0; + int pushalarm_count_month = 0; + int kitchenwarn_month = 0; + int vehicle_tired_month = 0; + int vehicle_speed_month = 0; + int vehicle_fence_month = 0; + double guarder_percent_month = 0; + double police_percent_month = 0; + double staff_percent_month = 0; + double protector_percent_month = 0; + + double score_total_borough = 0.0; + + for (BoroughDaySummaryEntity daySummary:dayList) { + guarder_sign_month += daySummary.getGuarder_sign(); + police_sign_month += daySummary.getPolice_sign(); + staff_sign_month += daySummary.getVolunteer_sign(); + protector_sign_month += daySummary.getProtector_sign(); + visitor_month += daySummary.getVisitor(); + visitor_vehicles_month += daySummary.getVisitor_vehicles(); + danger_count_month += daySummary.getDanger_count(); + pushalarm_count_month += daySummary.getPushalarm_count(); + kitchenwarn_month += daySummary.getKitchenwarn(); + vehicle_tired_month += daySummary.getVehicle_tired(); + vehicle_speed_month += daySummary.getVehicle_speed(); + vehicle_fence_month += daySummary.getVehicle_fence(); + + guarder_percent_month += daySummary.getGuarder_percent(); + police_percent_month += daySummary.getPolice_percent(); + staff_percent_month += daySummary.getStaff_percent(); + protector_percent_month += daySummary.getProtector_percent(); + + score_total_borough += daySummary.getScore_total(); + } + + + + newBoroughMonth.setGuarder_sign(guarder_sign_month); + newBoroughMonth.setPolice_sign(police_sign_month); + newBoroughMonth.setVolunteer_sign(staff_sign_month); + newBoroughMonth.setProtector_sign(protector_sign_month); + int signedTotal = guarder_sign_month + police_sign_month + staff_sign_month + protector_sign_month; + newBoroughMonth.setTotalsign(signedTotal); + + newBoroughMonth.setVisitor(visitor_month); + newBoroughMonth.setVisitor_vehicles(visitor_vehicles_month); + newBoroughMonth.setDanger_count(danger_count_month); + newBoroughMonth.setPushalarm_count(pushalarm_count_month); + newBoroughMonth.setKitchenwarn(kitchenwarn_month); + newBoroughMonth.setVehicle_tired(vehicle_tired_month); + newBoroughMonth.setVehicle_speed(vehicle_speed_month); + newBoroughMonth.setVehicle_fence(vehicle_fence_month); + + newBoroughMonth.setGuarder_percent(guarder_percent_month/dayCount); + newBoroughMonth.setPolice_percent(police_percent_month/dayCount); + newBoroughMonth.setStaff_percent(staff_percent_month/dayCount); + newBoroughMonth.setProtector_percent(protector_percent_month/dayCount); + newBoroughMonth.setScore_total(score_total_borough/dayCount); + newBoroughMonth.setTimestamp(new Date()); + + BoroughMonthSummaryEntity oldBoroughMonth = (BoroughMonthSummaryEntity)newBoroughMonth.QueryIt(dataSource); + if(oldBoroughMonth == null){ + System.out.println("Statistics: calcBorough month Summary insert new"); + newBoroughMonth.Insert(dataSource); + }else{ + newBoroughMonth.Update(dataSource); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + + /* + ***计算1级单位统计信息 + */ + + public void calcBrigadeDaySummary(BrigadeEntity calcBrigade, int nYear, int nMonth, int nDay){ + try { + BrigadeDaySummaryEntity newBrigadeDay = new BrigadeDaySummaryEntity(calcBrigade, nYear, nMonth, nDay); + + List boroughDayList = BoroughDaySummaryEntity.QueryBrigadeOneDay(dataSource, calcBrigade.getBrigade(), nYear, nMonth, nDay); + + if(boroughDayList == null){ + return; + } + int boroughCount = boroughDayList.size(); + if(boroughCount <= 0){ + return; + } + System.out.println("Statistics: calcBrigadeDaySummary " + boroughCount); + int guarder_sign_borough = 0; + int police_sign_borough = 0; + int staff_sign_borough = 0; + int protector_sign_borough = 0; + int visitor_borough = 0; + int visitor_vehicles_borough = 0; + int danger_count_borough = 0; + int pushalarm_count_borough = 0; + int kitchenwarn_borough = 0; + int vehicle_tired_borough = 0; + int vehicle_speed_borough = 0; + int vehicle_fence_borough = 0; + + double guarder_percent_borough = 0; + double police_percent_borough = 0; + double staff_percent_borough = 0; + double protector_percent_borough = 0; + double score_borough = 0; + + for (BoroughDaySummaryEntity daySummary:boroughDayList) { + guarder_sign_borough += daySummary.getGuarder_sign(); + police_sign_borough += daySummary.getPolice_sign(); + staff_sign_borough += daySummary.getVolunteer_sign(); + protector_sign_borough += daySummary.getProtector_sign(); + visitor_borough += daySummary.getVisitor(); + visitor_vehicles_borough += daySummary.getVisitor_vehicles(); + danger_count_borough += daySummary.getDanger_count(); + pushalarm_count_borough += daySummary.getPushalarm_count(); + kitchenwarn_borough += daySummary.getKitchenwarn(); + vehicle_tired_borough += daySummary.getVehicle_tired(); + vehicle_speed_borough += daySummary.getVehicle_speed(); + vehicle_fence_borough += daySummary.getVehicle_fence(); + guarder_percent_borough += daySummary.getGuarder_percent(); + police_percent_borough += daySummary.getPolice_percent(); + staff_percent_borough += daySummary.getStaff_percent(); + protector_percent_borough += daySummary.getProtector_percent(); + score_borough += daySummary.getScore_total(); + } + + newBrigadeDay.setGuarder_sign(guarder_sign_borough); + newBrigadeDay.setPolice_sign(police_sign_borough); + newBrigadeDay.setVolunteer_sign(staff_sign_borough); + newBrigadeDay.setProtector_sign(protector_sign_borough); + int signedTotal = guarder_sign_borough + police_sign_borough + staff_sign_borough + protector_sign_borough; + newBrigadeDay.setTotalsign(signedTotal); + + newBrigadeDay.setVisitor(visitor_borough); + newBrigadeDay.setVisitor_vehicles(visitor_vehicles_borough); + newBrigadeDay.setDanger_count(danger_count_borough); + newBrigadeDay.setPushalarm_count(pushalarm_count_borough); + newBrigadeDay.setKitchenwarn(kitchenwarn_borough); + newBrigadeDay.setVehicle_tired(vehicle_tired_borough); + newBrigadeDay.setVehicle_speed(vehicle_speed_borough); + newBrigadeDay.setVehicle_fence(vehicle_fence_borough); + + newBrigadeDay.setGuarder_percent(guarder_percent_borough/boroughCount); + newBrigadeDay.setPolice_percent(police_percent_borough/boroughCount); + newBrigadeDay.setStaff_percent(staff_percent_borough/boroughCount); + newBrigadeDay.setProtector_percent(protector_percent_borough/boroughCount); + newBrigadeDay.setScore_total(score_borough/boroughCount); + newBrigadeDay.setTimestamp(new Date()); + + BrigadeDaySummaryEntity oldBrigadeDay = (BrigadeDaySummaryEntity)newBrigadeDay.QueryIt(dataSource); + if(oldBrigadeDay == null){ + System.out.println("Statistics: calcBrigadeDaySummary insert new"); + newBrigadeDay.Insert(dataSource); + }else{ + System.out.println("Statistics: calcBrigadeDaySummary update old"); + newBrigadeDay.Update(dataSource); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcBrigadeMonthSummary(BrigadeEntity calcBrigade, int nYear, int nMonth){ + + } + + + /* + *** 事件处置 + */ + public void addPushAlarmEvent(FireStationBaseInfoEntity stationInfo){ + if(stationInfo == null){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + switch (stationInfo.getIndustry()){ + case CommonDefine.STATION_INDUSTRY_EDU:{ + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(stationInfo, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + newStationDay = createStationDayBaseSummary(stationInfo, nYear, nMonth, nDay); + } + if(newStationDay == null){ + return; + } + int oldAlarmPushCount = newStationDay.getPushalarm_count(); + newStationDay.setPushalarm_count(oldAlarmPushCount+1); + calcStationDaySummary(newStationDay); + + //计算指定boroug数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(stationInfo.getBorough()); + calcBorough.setBrigade(stationInfo.getBrigade()); + + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(stationInfo.getBrigade()); + + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + + }break; + default:break; + } + } + + public void addSensorAlarmEvent(FireStationBaseInfoEntity stationInfo, SensorAlarmEventEntity alarmEvent){ + if(stationInfo == null){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + switch (stationInfo.getIndustry()){ + case CommonDefine.STATION_INDUSTRY_EDU:{ + + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(stationInfo, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + newStationDay = createStationDayBaseSummary(stationInfo, nYear, nMonth, nDay); + } + if(newStationDay == null){ + return; + } + int oldDangerCount = newStationDay.getDanger_count(); + newStationDay.setDanger_count(oldDangerCount+1); + calcStationDaySummary(newStationDay); + calcStationMonthSummary(stationInfo, nYear, nMonth); + + //计算指定boroug数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(stationInfo.getBorough()); + calcBorough.setBrigade(stationInfo.getBrigade()); + + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(stationInfo.getBrigade()); + + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + + }break; + default:break; + } + } + + public void addEntranceFaceEvent(FireStationBaseInfoEntity stationInfo){ + if(stationInfo == null){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(stationInfo, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + newStationDay = createStationDayBaseSummary(stationInfo, nYear, nMonth, nDay); + } + if(newStationDay == null){ + return; + } + int oldGuarderSignCount = newStationDay.getGuarder_sign(); + System.out.println("Statistics: EntranceFac old sign ====" + oldGuarderSignCount); + newStationDay.setGuarder_sign(oldGuarderSignCount+1); + calcStationDaySummary(newStationDay); + calcStationMonthSummary(stationInfo, nYear, nMonth); + + //计算指定boroug数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(stationInfo.getBorough()); + calcBorough.setBrigade(stationInfo.getBrigade()); + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(stationInfo.getBrigade()); + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + } + + public void addVolunteerSignEvent(FireStationBaseInfoEntity stationInfo){ + if(stationInfo == null){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(stationInfo, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + newStationDay = createStationDayBaseSummary(stationInfo, nYear, nMonth, nDay); + } + if(newStationDay == null){ + return; + } + int oldVolunteerSignCount = newStationDay.getVolunteer_sign(); + System.out.println("Statistics: volunteer old sign ====" + oldVolunteerSignCount); + newStationDay.setVolunteer_sign(oldVolunteerSignCount+1); + + calcStationDaySummary(newStationDay); + calcStationMonthSummary(stationInfo, nYear, nMonth); + + //计算指定boroug数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(stationInfo.getBorough()); + calcBorough.setBrigade(stationInfo.getBrigade()); + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(stationInfo.getBrigade()); + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + } + + public void addPolicemanSignEvent(FireStationBaseInfoEntity stationInfo){ + if(stationInfo == null){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(stationInfo, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + newStationDay = createStationDayBaseSummary(stationInfo, nYear, nMonth, nDay); + } + if(newStationDay == null){ + return; + } + int oldPolceSignCount = newStationDay.getPolice_sign(); + // System.out.println("Statistics: police old sign ====" + oldPolceSignCount); + newStationDay.setPolice_sign(oldPolceSignCount+1); + calcStationDaySummary(newStationDay); + calcStationMonthSummary(stationInfo, nYear, nMonth); + + //计算指定boroug数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(stationInfo.getBorough()); + calcBorough.setBrigade(stationInfo.getBrigade()); + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(stationInfo.getBrigade()); + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + } + + public void addGuarderSignEvent(FireStationBaseInfoEntity stationInfo){ + if(stationInfo == null){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + StationDaySummaryEntity tmpStationDay = new StationDaySummaryEntity(stationInfo, nYear, nMonth, nDay); + StationDaySummaryEntity newStationDay = (StationDaySummaryEntity)tmpStationDay.QueryIt(dataSource); + if(newStationDay == null){ + newStationDay = createStationDayBaseSummary(stationInfo, nYear, nMonth, nDay); + } + if(newStationDay == null){ + return; + } + int oldGuarderSignCount = newStationDay.getGuarder_sign(); + System.out.println("Statistics: Guarder old sign ====" + oldGuarderSignCount); + newStationDay.setGuarder_sign(oldGuarderSignCount+1); + calcStationDaySummary(newStationDay); + + //计算指定boroug数据 + BoroughEntity calcBorough = new BoroughEntity(); + calcBorough.setBorough(stationInfo.getBorough()); + calcBorough.setBrigade(stationInfo.getBrigade()); + calcBoroughDaySummary(calcBorough, nYear, nMonth, nDay); + calcBoroughMonthSummary(calcBorough, nYear, nMonth); + + // 计算指定brigade 数据 + BrigadeEntity calcBrigade = new BrigadeEntity(); + calcBrigade.setBrigade(stationInfo.getBrigade()); + calcBrigadeDaySummary(calcBrigade, nYear, nMonth, nDay); + calcBrigadeMonthSummary(calcBrigade, nYear, nMonth); + } + + + protected void processAgentNews(SchoolNewsEntity schoolNews){ + try { + if(schoolNews == null){ + return; + } + System.out.println("processAgentNews: start = "); + String pictureIds = schoolNews.getImages(); + List idList = JSON.parseArray(pictureIds, String.class); + if(idList == null){ + return; + } + if(idList.size() == 0){ + return; + } + + for(String imageId:idList){ + MDevPictureEntity pictureEntity = new MDevPictureEntity(); + + pictureEntity.setId(imageId); + MDevPictureEntity pictureInDB = (MDevPictureEntity)pictureEntity.QueryIt(dataSource); + if(pictureInDB != null){ + System.out.println("processAgentNews: start copy image 2= "); + agentFile2Skynet(pictureInDB); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + protected void processAgentSign(GuardSignEventEntity schoolNews){ + try { + if(schoolNews == null){ + return; + } + System.out.println("processAgent sign files start = "); + String pictureIds = schoolNews.getImages(); + List idList = JSON.parseArray(pictureIds, String.class); + if(idList == null){ + return; + } + if(idList.isEmpty()){ + return; + } + + for(String imageId:idList){ + MDevPictureEntity pictureEntity = new MDevPictureEntity(); + + pictureEntity.setId(imageId); + MDevPictureEntity pictureInDB = (MDevPictureEntity)pictureEntity.QueryIt(dataSource); + if(pictureInDB != null){ + System.out.println("processAgentSign: start copy image 2= "); + agentFile2Skynet(pictureInDB); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + protected void processAgentCommonFile(SchoolCommonFileEntity schoolFile){ + try { + if(schoolFile == null){ + return; + } + System.out.println("processAgentFile: start = "); + String pictureIds = schoolFile.getImages(); + List idList = JSON.parseArray(pictureIds, String.class); + if(idList == null){ + return; + } + if(idList.size() == 0){ + return; + } + + for(String imageId:idList){ + MDevPictureEntity pictureEntity = new MDevPictureEntity(); + + pictureEntity.setId(imageId); + MDevPictureEntity pictureInDB = (MDevPictureEntity)pictureEntity.QueryIt(dataSource); + if(pictureInDB != null){ + System.out.println("processAgentNews: start copy image 2= "); + agentFile2Skynet(pictureInDB); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + protected void agentFileToSkynet(MDevPictureEntity pictureEntity){ + try { + String agentImageUrl = "http://10.8.0.2:8083/mdev/picture/upload"; + String boundary = "******"; + DataOutputStream ds = null; + InputStream inputStream = null; + InputStreamReader inputStreamReader = null; + BufferedReader reader = null; + StringBuffer resultBuffer = new StringBuffer(); + String tempLine = null; + + HttpURLConnection connLogin = HttpTools.createHttpConnection(agentImageUrl); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "multipart/form-data;boundary=" +boundary ); + connLogin.setRequestProperty("Connection","Keep-Alive"); + connLogin.connect(); + + ds = new DataOutputStream(connLogin.getOutputStream()); + StringBuffer strBuf = new StringBuffer(); + strBuf.append("\r\n").append("--").append(boundary).append("\r\n"); + strBuf.append("Content-Disposition:form-data;jsondata=" + JSON.toJSONString(pictureEntity) + "\r\n\r\n"); + ds.write(strBuf.toString().getBytes()); + + + String creator = pictureEntity.getCreator(); + String file = pictureEntity.getFilename(); + + String path = "./pic"; + if(creator!=null&&creator.length()>0) + path += "/"+creator; + if(file==null||file.length()<=0) { + return; + } + String fileName = file; + //获取输入流对象(用于读文件) + FileInputStream fis = new FileInputStream(new File(path, fileName)); + //获取文件后缀(.txt) + String extendFileName = fileName.substring(fileName.lastIndexOf('.')); + + //下载文件,使用spring框架中的FileCopyUtils工具 + FileCopyUtils.copy(fis,ds); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("processSchoolCheckData: fail = " + responseCode); + }else{ + System.out.println("processSchoolCheckData: ok = " + responseCode); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + protected void agentFile2Skynet(MDevPictureEntity pictureEntity){ + try { + String creator = pictureEntity.getCreator(); + String fileName = pictureEntity.getFilename(); + + String path = "./pic"; + if(creator!=null&&creator.length()>0) + path += "/"+creator; + if(fileName==null||fileName.length()<=0) { + return; + } + File mFile = new File(path, fileName); + + String agentImageUrl = "http://10.8.0.2:8083/mdev/picture/upload"; + // String agentImageUrl = "https://www.emc-station.com:8083/mdev/picture/upload"; + // String imageId = pictureEntity.getId(); + // pictureEntity.setId("agent_" + imageId); + + OkHttpClient client = new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS).build(); + final MediaType mt = MediaType.parse("multipart/form-data"); + final MultipartBody body = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("file", mFile.getName(), RequestBody.create(mt, mFile)) + .addFormDataPart("jsondata", JSON.toJSONString(pictureEntity)) + .build(); + + Request r = new Request.Builder().url(agentImageUrl).post(body).build(); + Call call = client.newCall(r); + try{ + Response response = call.execute(); + System.out.println("agentFile2Skynet: result = " + response.body().string()); + }catch (IOException e){ + System.out.println("agentFile2Skynet: fail = " + e); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void scanPersonFile(final String groupName, final String groupLevel){ + new Thread(){ + public void run(){ + String path = "./pic/" + groupName; + File filePath = new File(path); + File[] files = filePath.listFiles(); + if (files != null && files.length > 0) { + //File firstFile = files[0]; + for (File filePerson : files) { + String fileName = filePerson.getName(); + String[] fileDesc = fileName.split("\\."); + if(fileDesc.length == 2){ + String personInfo = fileDesc[0]; + + String[] personInfos = personInfo.split("_"); + if(personInfos.length == 3){ + String personName = personInfos[0]; + String personCert = personInfos[2]; + + PersonBlacklistEntity personBlack = new PersonBlacklistEntity(); + personBlack.setPersonId(personCert); + PersonBlacklistEntity personOld = (PersonBlacklistEntity)personBlack.QueryIt(dataSource); + + personBlack.setGroupType(groupName); + personBlack.setPersonName(personName); + personBlack.setControlStatus("布控中"); + String urlPath = "/mdev/pic/download?creator="+groupName+"&file=" + fileName; + personBlack.setImageUrl(urlPath); + personBlack.setImageData(""); + personBlack.setPersonLevel(groupLevel); + personBlack.setGroupLevel(groupLevel); + + if(personOld == null){ + personBlack.Insert(dataSource); + }else{ + personBlack.Update(dataSource); + } + + } + + } + } + } + } + }.start(); + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/DatabaseDesInfoService.java b/src/main/java/com/jingyi/iotserver/firestationport/services/DatabaseDesInfoService.java new file mode 100644 index 0000000..2f37420 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/DatabaseDesInfoService.java @@ -0,0 +1,245 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.firestationport.model.equipment.FireCtrlInfoDescriptEntity; +import com.jingyi.iotserver.firestationport.model.equipment.StationEquipmentDescript; +import com.jingyi.iotserver.utils.SQLDataObject; + +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.io.*; +import java.util.HashMap; +import java.util.List; + +@Service +public class DatabaseDesInfoService { + @Autowired + private DataSource dataSource; + + @Autowired + private EnvConfigService envConfigService; + + private HashMap dbDescripInfoKeyMap = new HashMap(); + private HashMap dbDescripInfoIndexMap = new HashMap(); + + private HashMap dbEquipDescripInfoKeyMap = new HashMap(); + private HashMap dbEquipDescripInfoIndexMap = new HashMap(); + + public void LoadInfo(){ + + try { + FireCtrlInfoDescriptEntity des = new FireCtrlInfoDescriptEntity(); + List dbinfolist = des.queryList(dataSource,null,null); + if(dbinfolist!=null) { + for (SQLDataObject ob : dbinfolist) { + try { + FireCtrlInfoDescriptEntity info = (FireCtrlInfoDescriptEntity) ob; + if (info != null) { + dbDescripInfoIndexMap.put(info.getNumber(), info); + dbDescripInfoKeyMap.put(info.getInfo_class() + "@" + info.getTitle(), info); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + } + InputStream stream = null; + try { + // Resource resource = new ClassPathResource("static\\dbinfodefine.xml"); + // File file = resource.getFile(); + stream = getClass().getClassLoader().getResourceAsStream("static/dbinfodefine.xml"); + File targetFile = new File("dbinfodefine.xml"); + // FileUtils.copyInputStreamToFile(stream, targetFile); + + // BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(targetFile))); + + SAXReader reader = new SAXReader(); + Document document = reader.read(new InputStreamReader(stream,"utf8")); + Element root = document.getRootElement(); + if("dbinfodefine".equals(root.getName())) { + List list = root.elements(); + for(Element el:list){ + if(el==null) + continue; + if(!"info".equals(el.getName())) + continue; + String cclass = null; + try { + Attribute atr = el.attribute("class"); + cclass = atr.getStringValue(); + }catch (Exception e){ + + } + if(cclass==null) + continue; + + String title = null; + try { + Attribute atr = el.attribute("title"); + title = atr.getStringValue(); + }catch (Exception e){ + + } + if(title==null||title.length()<1) + continue; + + String descript = null; + try { + Attribute atr = el.attribute("descript"); + descript = atr.getStringValue(); + // System.out.println("descript:"+descript); + }catch (Exception e){ + + } + if(descript==null||descript.length()<1) + continue; + + String type = null; + try { + Attribute atr = el.attribute("type"); + type = atr.getStringValue(); + }catch (Exception e){ + + } + if(type==null||type.length()<1) + continue; + FireCtrlInfoDescriptEntity tmp = dbDescripInfoKeyMap.get(cclass+"@"+title); + if(tmp!=null) { + continue; + } + FireCtrlInfoDescriptEntity entity = new FireCtrlInfoDescriptEntity(); + entity.setInfo_class(cclass); + entity.setTitle(title); + entity.setDescript(descript); + entity.setType(type); + entity.Insert(dataSource); + dbDescripInfoIndexMap.put(entity.getNumber(),entity); + dbDescripInfoKeyMap.put(entity.getInfo_class()+"@"+entity.getTitle(),entity); + } + } + }catch (Exception e){ + e.printStackTrace(); + }finally { + try{ + if(stream!=null) + stream.close(); + }catch (Exception e){ + + } + } + + LoadEqupmentConfig(); + } + + + public FireCtrlInfoDescriptEntity getDBInfoDescript(int index){ + return dbDescripInfoIndexMap.get(index); + } + + public FireCtrlInfoDescriptEntity getDBInfoDescript(String info_class,String title){ + return dbDescripInfoKeyMap.get(info_class+"@"+title); + } + + public int getDBInfoDescriptIndex(String cclass,String title){ + FireCtrlInfoDescriptEntity info = dbDescripInfoKeyMap.get(cclass+"@"+title); + if(info==null) + return 0; + return info.getNumber(); + } + public void LoadEqupmentConfig(){ + InputStream stream = null; + try { + + stream = getClass().getClassLoader().getResourceAsStream("static/equipmenttabdefine.xml"); + File targetFile = new File("equipmenttabdefine.xml"); + // FileUtils.copyInputStreamToFile(stream, targetFile); + + SAXReader reader = new SAXReader(); + // Document document = reader.read(new InputStreamReader(new FileInputStream(targetFile),"utf8")); + Document document = reader.read(new InputStreamReader(stream,"utf8")); + + Element root = document.getRootElement(); + if("equipmenttabdefine".equals(root.getName())) { + List list = root.elements(); + for(Element el:list){ + if(el==null) + continue; + if(!"equipment".equals(el.getName())) + continue; + + String title = null; + try { + Attribute atr = el.attribute("title"); + title = atr.getStringValue(); + }catch (Exception e){ + + } + if(title==null||title.length()<1) + continue; + + String descript = null; + try { + Attribute atr = el.attribute("descript"); + descript = atr.getStringValue(); + }catch (Exception e){ + + } + if(descript==null||descript.length()<1) + continue; + + String type = null; + try { + Attribute atr = el.attribute("type"); + type = atr.getStringValue(); + }catch (Exception e){ + + } + if(type==null||type.length()<1) + continue; + + int index = getDBInfoDescriptIndex("equipment",title); + if(index<=0) + continue; + StationEquipmentDescript des = new StationEquipmentDescript(); + des.setIndex(index); + des.setTitle(title); + des.setType(type); + dbEquipDescripInfoKeyMap.put(title,des); + dbEquipDescripInfoIndexMap.put(index,des); + } + } + }catch (Exception e){ + e.printStackTrace(); + }finally { + try{ + if(stream!=null) + stream.close(); + }catch (Exception e){ + + } + } + } + + public StationEquipmentDescript getEquipmentDescript(int index){ + return dbEquipDescripInfoIndexMap.get(index); + } + + public int getDBDescriptIndex(String cclass,String title){ + if(cclass==null||title==null) + return -1; + + FireCtrlInfoDescriptEntity entity = dbDescripInfoKeyMap.get(cclass+"@"+title); + if(entity!=null) + return entity.getNumber(); + return -1; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/DatabaseTransfer.java b/src/main/java/com/jingyi/iotserver/firestationport/services/DatabaseTransfer.java new file mode 100644 index 0000000..7673f53 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/DatabaseTransfer.java @@ -0,0 +1,966 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.jingyi.iotserver.clientmanage.model.*; +import com.jingyi.iotserver.common.configuration.DruidDataSourceConfig; +import com.jingyi.iotserver.firestationport.model.todev.TimingJobEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallAckEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.equipment.EquipmentVerifyEntity; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentEntity; +import com.jingyi.iotserver.firestationport.model.inspection.InspectStationEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionDeviceEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionResultEntity; +import com.jingyi.iotserver.firestationport.model.inspection.RoundInspectionTaskEntity; +import com.jingyi.iotserver.firestationport.model.partner.PartnerAlarm; +import com.jingyi.iotserver.firestationport.model.sensor.*; +import com.jingyi.iotserver.firestationport.model.station.*; +import com.jingyi.iotserver.firestationport.model.todev.*; +import com.jingyi.iotserver.firestationport.model.update.SoftwareUpdateTaskEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBoundEntity; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import com.jingyi.iotserver.utils.SpringContextUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.List; + +@Service +public class DatabaseTransfer { + @Autowired + DataSource dataSource; + + private boolean blInited = false; + private Object locker = new Object(); + + private boolean blTrans = false; + private String transName = ""; + private Thread transservice = null; + public void Init(){ + if(blInited) + return; + blInited = true; + + + transservice = new Thread(){ + public void run(){ + while(true){ + try { + TransTable(); + }catch (Exception e){ + + } + try{ + Thread.sleep(1000); + }catch (Exception e){ + + } + } + } + }; + + transservice.start(); + + } + + private void TransTable(){ + if(!blTrans) + return; + if(transName==null||transName.length()<=0){ + blTrans = false; + return; + } + try{ + if(transName.equals("org")){ + transOrg(); + System.out.println("trans org complete"); + }else if(transName.equals("station")){ + transStation(); + System.out.println("trans station complete"); + }else if(transName.equals("inspect")){ + transInspection(); + System.out.println("trans inspect complete"); + }else if(transName.equals("partner")){ + transPartner(); + System.out.println("trans partner complete"); + }else if(transName.equals("sensor")){ + transSensor(); + System.out.println("trans sensor complete"); + }else if(transName.equals("stationext")){ + transStationExt(); + System.out.println("trans stationext complete"); + }else if(transName.equals("todev")){ + transToDev(); + System.out.println("trans todev complete"); + }else if(transName.equals("stationext2")){ + transStationExt2(); + System.out.println("trans stationext2 complete"); + }else if(transName.equals("rollcall")){ + transRollCall(); + System.out.println("trans rollcall complete"); + } + + }catch (Exception e){ + + } + + blTrans = false; + } + + public boolean startTrans(String name){ + if(blTrans||name==null||name.length()<=0) + return false; + transName = name; + blTrans = true; + return true; + } + + private void transOrg(){ + + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + //borough + BoroughEntity borough = new BoroughEntity(); + List blist = borough.queryList(dataSource,null,null); + if(blist!=null){ + for(SQLDataObject ob:blist){ + BoroughEntity b = (BoroughEntity)ob; + if(b!=null&&b.QueryIt(ds)==null){ + b.Insert(ds); + } + } + } + + try{ + Thread.sleep(50); + }catch (Exception e){ + + } + //brigade + BrigadeEntity brigde = new BrigadeEntity(); + List brlist = brigde.queryList(dataSource,null,null); + if(brlist!=null){ + for(SQLDataObject ob:brlist){ + BrigadeEntity b = (BrigadeEntity)ob; + if(b!=null&&b.QueryIt(ds)==null){ + b.Insert(ds); + } + } + } + + //detachment + DetachmentEntity detachment = new DetachmentEntity(); + List dlist = detachment.queryList(dataSource,null,null); + if(dlist!=null){ + for(SQLDataObject ob:dlist){ + DetachmentEntity b = (DetachmentEntity)ob; + if(b!=null&&b.QueryIt(ds)==null){ + b.Insert(ds); + } + } + } + + //organizationinfo + OrganizationInfoEntity org = new OrganizationInfoEntity(); + List orlist = org.queryList(dataSource,null,null); + if(orlist!=null){ + for(SQLDataObject ob:orlist){ + OrganizationInfoEntity b = (OrganizationInfoEntity)ob; + if(b!=null&&b.QueryIt(ds)==null){ + b.Insert(ds); + } + } + } + try{ + Thread.sleep(50); + }catch (Exception e){ + + } + //role + RoleEntity role = new RoleEntity(); + List rlist = role.queryList(dataSource,null,null); + if(rlist!=null){ + for(SQLDataObject db:rlist){ + RoleEntity b = (RoleEntity)db; + if(b!=null&&b.QueryIt(ds)==null){ + + AuthorityEntity aut = new AuthorityEntity(); + aut.extendName(""+b.getId()); + List autlist = aut.queryList(dataSource,null,null); + if(b.Insert(ds)){ + if(autlist!=null&&autlist.size()>0){ + for(SQLDataObject ob:autlist){ + AuthorityEntity au = (AuthorityEntity)ob; + au.extendName(""+b.getId()); + au.Insert(ds); + } + } + } + + } + } + } + try{ + Thread.sleep(50); + }catch (Exception e){ + + } + //operation + OperatingRecordEntity operate = new OperatingRecordEntity(); + List oplist = null; + int index = 0; + do { + oplist = operate.queryPage(dataSource, "2018-1-1 00:00:00", SQLTools.formatDate(new Date()), index, 500); + if(oplist==null) + break; + if (oplist != null) { + for(SQLDataObject ob:oplist){ + OperatingRecordEntity op = (OperatingRecordEntity)ob; + if(op!=null&&op.QueryIt(ds)==null) + op.Insert(ds); + } + } + index++; + }while(oplist!=null&&oplist.size()>500); + + //third platform + ThirdPlatformInfoEntity thirdp = new ThirdPlatformInfoEntity(); + List tplist = null; + index = 0; + do { + tplist = thirdp.queryPage(dataSource, null,null ,index, 500); + if(tplist==null) + break; + if (tplist != null) { + for(SQLDataObject ob:tplist){ + ThirdPlatformInfoEntity tp = (ThirdPlatformInfoEntity)ob; + if(tp!=null&&tp.QueryIt(ds)==null) + tp.Insert(ds); + } + } + index++; + }while(tplist!=null&&tplist.size()>500); + + try{ + Thread.sleep(50); + }catch (Exception e){ + + } + //user + UserInfoEntity user = new UserInfoEntity(); + List uslist = user.queryList(dataSource,null,null); + if(uslist!=null){ + for (SQLDataObject ob : uslist) { + UserInfoEntity u = (UserInfoEntity)ob; + if (u != null && u.QueryIt(ds) == null) { + u.Insert(ds); + } + } + } + } + + + private void transStation(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + //station + FireStationBaseInfoEntity station = new FireStationBaseInfoEntity(); + int index = 0; + List slist = null; + do { + slist = station.queryPage(dataSource, null,null,index, 500); + index++; + if(slist==null) + break; + if (slist != null) { + for (SQLDataObject ob : slist) { + FireStationBaseInfoEntity b = (FireStationBaseInfoEntity)ob; + if(b!=null&&b.getName()!=null&&b.getName().startsWith("测试微站20")) + continue; + if (b != null && FireStationBaseInfoEntity.Query(ds, b.getName()) == null) { + int number = b.getNumber(); + b.Insert(ds); + + //line + FireStationLineEntity line = new FireStationLineEntity(); + int i=0; + List linelist = null; + line.extendName(""+number); + do { + linelist = line.queryPage(dataSource, "2018-1-1 00:00:00", SQLTools.formatDate(new Date()), i, 500); + i++; + if(linelist==null) + break; + if (linelist != null && linelist.size() > 0) { + for (SQLDataObject li : linelist) { + FireStationLineEntity lin = (FireStationLineEntity)li; + // if(FireStationLineEntity.Query(ds,b.getNumber(),lin.getOnline())==null) + lin.setStation_number(b.getNumber()); + lin.extendName(""+b.getNumber()); + lin.Insert(ds); + } + } + + }while(linelist!=null&&linelist.size()>=500); + + + //sign + FireStationSignEntity sign = new FireStationSignEntity(); + i=0; + List signlist = null; + do { + sign.extendName(""+number); + signlist = sign.queryPage(dataSource, "2018-1-1 00:00:00", SQLTools.formatDate(new Date()), i, 500); + i++; + if(signlist==null) + break; + if (signlist != null && signlist.size() > 0) { + for (SQLDataObject sob : signlist) { + FireStationSignEntity lin = (FireStationSignEntity)sob; + lin.extendName(""+b.getNumber()); + if(lin.QueryIt(ds)==null) { + lin.setStation_number(b.getNumber()); + lin.Insert(ds); + } + } + } + + }while(signlist!=null&&signlist.size()>=500); + + EquipmentVerifyEntity verify = EquipmentVerifyEntity.Query(dataSource,b.getName()); + if(verify!=null){ + verify.setNumber(b.getNumber()); + if(EquipmentVerifyEntity.Query(ds,b.getName())==null){ + verify.Insert(ds); + } + } + + FireStationEquipmentEntity eq = new FireStationEquipmentEntity(); + eq.extendName(""+number); + List equiplist = eq.queryList(dataSource,null,null); + if(equiplist==null) + continue; + for (SQLDataObject eob : equiplist) { + FireStationEquipmentEntity equip = (FireStationEquipmentEntity)eob; + equip.extendName(""+b.getNumber()); + equip.Insert(ds); + } + + } + } + } + }while(slist!=null&&slist.size()>=500); + } + + private void transInspection(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + InspectStationEntity inspect = new InspectStationEntity(); + int index = 0; + List inlist = null; + do{ + inlist = inspect.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(inlist==null) + break; + for( SQLDataObject ob : inlist){ + InspectStationEntity in = (InspectStationEntity)ob; + if(in==null) + continue; + if(InspectStationEntity.Query(ds,in.getNumber())==null) + in.Insert(ds); + } + }while(inlist!=null&&inlist.size()>=500); + + RoundInspectionDeviceEntity round = new RoundInspectionDeviceEntity(); + index = 0; + List roundlist = null; + do{ + roundlist = round.queryPage(dataSource,null,null,index,500); + index++; + if(roundlist==null) + break; + for( SQLDataObject in : roundlist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(roundlist!=null&&roundlist.size()>=500); + + + RoundInspectionResultEntity inspectrel = new RoundInspectionResultEntity(); + index = 0; + List inrellist = null; + do{ + inrellist = inspectrel.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(inrellist==null) + break; + for( SQLDataObject in : inrellist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(inrellist!=null&&inrellist.size()>=500); + + RoundInspectionTaskEntity task = new RoundInspectionTaskEntity(); + index = 0; + List tasklist = null; + do{ + tasklist = task.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(tasklist==null) + break; + for( SQLDataObject in : tasklist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(tasklist!=null&&tasklist.size()>=500); + + } + + private void transPartner(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + PartnerAlarm alarm = new PartnerAlarm(); + int index = 0; + List alarmlist = null; + do{ + alarmlist = alarm.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(alarmlist==null) + break; + for( SQLDataObject in : alarmlist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(alarmlist!=null&&alarmlist.size()>=500); + } + + private void transSensor(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + SensorDeviceEntity sensor = new SensorDeviceEntity(); + int index = 0; + List slist = null; + do{ + slist = sensor.queryPage(dataSource,null,null,index,500); + index++; + if(slist==null) + break; + for(SQLDataObject sob:slist){ + SensorDeviceEntity s = (SensorDeviceEntity)sob; + if(s==null) + continue; + if(SensorDeviceEntity.Query(ds,s.getDeviceid())!=null) + continue; + int id = s.getId(); + s.Insert(ds); +/* + ACBEventEntity event = new ACBEventEntity(); + event.setDeviceid(s.getDeviceid()); + List elist = null; + int i=0; + do{ + elist = event.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),i,500); + i++; + if(elist==null) + break; + for(SQLDataObject ob:elist){ + ACBEventEntity e = (ACBEventEntity)ob; + e.setDevid(id); + if(e.QueryIt(ds)==null) + e.Insert(ds); + } + }while(elist!=null&&elist.size()>=500); + */ + } + }while(slist!=null&&slist.size()>=500); + +/* + AlerterHostEventEntity alerter = new AlerterHostEventEntity(); + List alerterlist = null; + index = 0; + do{ + alerterlist = alerter.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(alerterlist==null) + break; + for( SQLDataObject ob : alerterlist){ + AlerterHostEventEntity in = (AlerterHostEventEntity)ob; + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(alerterlist!=null&&alerterlist.size()>=500); + + EarthInductorBuzEventEntity ei = new EarthInductorBuzEventEntity(); + List eilist = null; + index = 0; + do{ + eilist = ei.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(eilist==null) + break; + for( SQLDataObject ob : eilist){ + EarthInductorBuzEventEntity in = (EarthInductorBuzEventEntity)ob; + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(eilist!=null&&eilist.size()>=500); + + EarthInductorEventEntity eie = new EarthInductorEventEntity(); + List eielist = null; + index = 0; + do{ + eielist = eie.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(eielist==null) + break; + for( SQLDataObject in : eielist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(eielist!=null&&eielist.size()>=500); + + GasSensorEventEntity gas = new GasSensorEventEntity(); + List gaslist = null; + index = 0; + do{ + gaslist = gas.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(gaslist==null) + break; + for( SQLDataObject in : gaslist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(gaslist!=null&&gaslist.size()>=500); + + LiquidGageAlarmSettingEntity lgalarm = new LiquidGageAlarmSettingEntity(); + List lgalist = null; + index = 0; + do{ + lgalist = lgalarm.queryPage(dataSource,index,500); + index++; + if(gaslist==null) + break; + for( LiquidGageAlarmSettingEntity in : lgalist){ + if(in==null) + continue; + if(LiquidGageAlarmSettingEntity.QuerySetting(ds,in.getDeviceid())==null) + in.Insert(ds); + } + }while(lgalist!=null&&lgalist.size()>=500); + + LiquidGageEventEntity liq = new LiquidGageEventEntity(); + List liqlist = null; + index = 0; + do{ + liqlist = liq.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(liqlist==null) + break; + for( SQLDataObject in : liqlist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(liqlist!=null&&liqlist.size()>=500); + + PipePressureEventEntity pip = new PipePressureEventEntity(); + List piplist = null; + index = 0; + do{ + piplist = pip.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(piplist==null) + break; + for( SQLDataObject in : piplist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(piplist!=null&&piplist.size()>=500); + + SmokingBuzEventEntity smoking = new SmokingBuzEventEntity(); + List smokinglist = null; + index = 0; + do{ + smokinglist = smoking.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(smokinglist==null) + break; + for( SQLDataObject in : smokinglist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(smokinglist!=null&&smokinglist.size()>=500); + + SmokingEventEntity smk = new SmokingEventEntity(); + List smklist = null; + index = 0; + do{ + smklist = smk.queryPage(dataSource,"2021-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(smklist==null) + break; + for( SQLDataObject in : smklist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(smklist!=null&&smklist.size()>=500); +*/ + } + + private void transStationExt(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + FireMediaInfoEntity media = new FireMediaInfoEntity(); + List medialist = null; + int index = 0; + do{ + medialist = media.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(medialist==null) + break; + for( SQLDataObject in : medialist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(medialist!=null&&medialist.size()>=500); + + FireStationAlarmEntity alarm = new FireStationAlarmEntity(); + List alarmlist = null; + index = 0; + do{ + alarmlist = alarm.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(alarmlist==null) + break; + for( SQLDataObject ob : alarmlist){ + FireStationAlarmEntity in = (FireStationAlarmEntity)ob; + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(alarmlist!=null&&alarmlist.size()>=500); + + FireStationAlarmProcessRecordEntity ap = new FireStationAlarmProcessRecordEntity(); + List aplist = null; + index = 0; + do{ + aplist = ap.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(aplist==null) + break; + for( SQLDataObject in : aplist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(aplist!=null&&aplist.size()>=500); + + FireStationPropertyEntity pro = new FireStationPropertyEntity(); + List prolist = null; + prolist = pro.queryList(dataSource,null,null); + if(prolist!=null) { + for (SQLDataObject in : prolist) { + if (in == null) + continue; + if (in.QueryIt(ds) == null) + in.Insert(ds); + } + } + + FireUnitEntity unit = new FireUnitEntity(); + List unitlist = null; + index = 0; + do{ + unitlist = unit.queryPage(dataSource,null,null,index,500); + index++; + if(unitlist==null) + break; + for( SQLDataObject ob : unitlist){ + FireUnitEntity in = (FireUnitEntity) ob; + if(in==null) + continue; + if(FireUnitEntity.Query(ds,in.getFireunitname())==null) + in.Insert(ds); + } + }while(unitlist!=null&&unitlist.size()>=500); + + StationRunningInfoEntity run = new StationRunningInfoEntity(); + List runlist = null; + index = 0; + do{ + runlist = run.queryPage(dataSource,null,null,index,500); + index++; + if(unitlist==null) + break; + for( SQLDataObject ob : runlist){ + StationRunningInfoEntity in = (StationRunningInfoEntity)ob; + if(in==null) + continue; + if(StationRunningInfoEntity.Query(ds,in.getStation())==null) + in.Insert(ds); + } + }while(runlist!=null&&runlist.size()>=500); + } + + private void transToDev(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + AssignmentEntity as = new AssignmentEntity(); + List aslist = null; + int index = 0; + do{ + aslist = as.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(aslist==null) + break; + for( SQLDataObject ob : aslist){ + AssignmentEntity in = (AssignmentEntity)ob; + if(in==null) + continue; + if(AssignmentEntity.QueryAssignment(ds,in.getAssignmentid())==null) { + int id = in.getId(); + in.Insert(ds); + + AssignmentStatusEntity status = new AssignmentStatusEntity(); + status.setId(id); + List statuslist = null; + int i=0; + do{ + status.extendName(""+id); + statuslist = status.queryPage(dataSource,null,null,i,500); + if(statuslist==null) + break; + for(SQLDataObject sob:statuslist){ + AssignmentStatusEntity s= (AssignmentStatusEntity)sob; + if(s==null) + continue; + s.setId(in.getId()); + s.extendName(""+in.getId()); + s.Insert(ds); + } + i++; + }while(statuslist!=null&&statuslist.size()>=500); + } + } + }while(aslist!=null&&aslist.size()>=500); + + + AssignmentEventEntity asevent = new AssignmentEventEntity(); + List aseventlist = null; + index = 0; + do{ + aseventlist = asevent.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(aseventlist==null) + break; + for( SQLDataObject ob : aseventlist){ + AssignmentEventEntity in = (AssignmentEventEntity)ob; + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(aseventlist!=null&&aseventlist.size()>=500); + + NoticeEntity notice = new NoticeEntity(); + List noticelist = null; + index = 0; + do{ + noticelist = notice.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(noticelist==null) + break; + for( SQLDataObject ob : noticelist){ + NoticeEntity in = (NoticeEntity)ob; + if(in==null) + continue; + if(NoticeEntity.QueryNotice(ds,in.getNoticeid())==null) { + int id = in.getId(); + in.Insert(ds); + + NoticeStatusEntity status = new NoticeStatusEntity(); + status.setId(id); + status.extendName(""+id); + List statuslist = null; + int i=0; + do{ + statuslist = status.queryPage(dataSource,null,null,i,500); + if(statuslist==null) + break; + for(SQLDataObject sob:statuslist){ + NoticeStatusEntity s = (NoticeStatusEntity)sob; + if(s==null) + continue; + s.setId(in.getId()); + s.extendName(""+in.getId()); + s.Insert(ds); + } + i++; + }while(statuslist!=null&&statuslist.size()>=500); + } + } + }while(noticelist!=null&¬icelist.size()>=500); + + TimingJobEntity tjob = new TimingJobEntity(); + List tjoblist = null; + index = 0; + do{ + tjoblist = tjob.queryPage(dataSource,null,null,index,500); + index++; + if(tjoblist==null) + break; + for( SQLDataObject ob : tjoblist){ + TimingJobEntity in = (TimingJobEntity)ob; + if(in==null) + continue; + if(TimingJobEntity.QueryTimingJob(ds,in.getNumber())==null) + in.Insert(ds); + } + }while(tjoblist!=null&&tjoblist.size()>=500); + } + + private void transStationExt2(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + FireStationBoundEntity bound = new FireStationBoundEntity(); + List boundlist = null; + int index = 0; + do{ + boundlist = bound.queryPage(dataSource,null,null,index,500); + index++; + if(boundlist==null) + break; + for( SQLDataObject in : boundlist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(boundlist!=null&&boundlist.size()>=500); + + FireStationStaffInfoEntity staff = new FireStationStaffInfoEntity(); + List stafflist = null; + index = 0; + do{ + stafflist = staff.queryPage(dataSource,null,null,index,500); + index++; + if(stafflist==null) + break; + for( SQLDataObject in : stafflist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(stafflist!=null&&stafflist.size()>=500); + + FireStationVideoConfigEntity video = new FireStationVideoConfigEntity(); + List videolist = null; + index = 0; + do{ + videolist = video.queryPage(dataSource,null,null,index,500); + index++; + if(videolist==null) + break; + for( SQLDataObject in : videolist){ + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(videolist!=null&&videolist.size()>=500); + + SoftwareUpdateTaskEntity task = new SoftwareUpdateTaskEntity(); + List tasklist = null; + tasklist = task.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),0,1000); + if(tasklist!=null){ + + for (SQLDataObject in : tasklist) { + if (in == null) + continue; + SoftwareUpdateTaskEntity d = (SoftwareUpdateTaskEntity)in; + if (d.QueryTask(ds, d.getTaskid()) == null) + in.Insert(ds); + } + } + } + + private void transRollCall(){ + DruidDataSourceConfig config = (DruidDataSourceConfig) SpringContextUtil.getBean(DruidDataSourceConfig.class); + DataSource ds = config.getMySqlDataSource(); + + FireStationRollCallEntity call = new FireStationRollCallEntity(); + List calllist = null; + int index = 0; + do{ + calllist = call.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(calllist==null) + break; + for( SQLDataObject ob : calllist){ + FireStationRollCallEntity in = (FireStationRollCallEntity)ob; + if(in==null) + continue; + if(FireStationRollCallEntity.Query(ds,in.getNumber())==null) + in.Insert(ds); + } + }while(calllist!=null&&calllist.size()>=500); + + FireStationRollCallAckEntity ack = new FireStationRollCallAckEntity(); + List acklist = null; + index = 0; + do{ + acklist = ack.queryPage(dataSource,"2018-1-1 00:00:00",SQLTools.formatDate(new Date()),index,500); + index++; + if(acklist==null) + break; + for( SQLDataObject ob : acklist){ + FireStationRollCallAckEntity in = (FireStationRollCallAckEntity)ob; + if(in==null) + continue; + if(in.QueryIt(ds)==null) + in.Insert(ds); + } + }while(acklist!=null&&acklist.size()>=500); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/ExcelService.java b/src/main/java/com/jingyi/iotserver/firestationport/services/ExcelService.java new file mode 100644 index 0000000..cc0bbb7 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/ExcelService.java @@ -0,0 +1,89 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.jingyi.iotserver.firestationport.model.complexquery.RollcallReportForm; +import com.jingyi.iotserver.utils.SQLTools; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.format.CellFormat; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.util.CellRangeAddress; +import org.springframework.stereotype.Service; + +import java.awt.*; +import java.io.File; +import java.io.FileOutputStream; +import java.util.Date; + + +//http://www.cnblogs.com/langtianya/p/6434843.html + +@Service +public class ExcelService { + + public String saveRollcallReport(RollcallReportForm reportform){ + String dat = SQLTools.formatDate(new Date()); + dat = dat.replace(' ','-'); + dat = dat.replace(':','-'); + String path = ".\\rollcallreport-"+dat+".xls"; + FileOutputStream xlsFile = null; + try{ + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet("点名报表"); + + HSSFFont font = workbook.createFont(); + font.setFontHeightInPoints((short)28); + + HSSFRow sfrow = sheet.createRow(0); + sfrow.setHeightInPoints(60); + sheet.addMergedRegion(new CellRangeAddress(0,0,0,8)); + + + + HSSFCellStyle style = workbook.createCellStyle(); + style.setFont(font); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + + HSSFRow sfrow1 = sheet.createRow(1); + sheet.addMergedRegion(new CellRangeAddress(1,1,0,3)); + sheet.addMergedRegion(new CellRangeAddress(1,1,5,8)); + sheet.addMergedRegion(new CellRangeAddress(2,2,0,3)); + sheet.addMergedRegion(new CellRangeAddress(2,2,5,8)); + + HSSFCell cell = sfrow.createCell((short)0); + cell.setCellValue("微型消防站在岗点名统计报表"); + cell.setCellStyle(style); + + font.setFontHeightInPoints((short)20); + cell = sfrow1.createCell(0); + cell.setCellValue("总应答次数"); + cell.setCellStyle(style); + cell = sfrow1.createCell(5); + cell.setCellValue("总点名次数"); + cell.setCellStyle(style); + + HSSFRow sfrow2 = sheet.createRow(2); + cell = sfrow2.createCell(0); + cell.setCellValue(reportform.getAck()); + cell.setCellStyle(style); + cell = sfrow2.createCell(5); + cell.setCellValue(reportform.getExpect()); + cell.setCellStyle(style); + + xlsFile = new FileOutputStream(path); + workbook.write(xlsFile); + workbook.close(); + + }catch (Exception e){ + e.printStackTrace(); + }finally { + try { + if(xlsFile!=null) + xlsFile.close(); + }catch (Exception e){ + + } + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/SchoolSummaryQuartz.java b/src/main/java/com/jingyi/iotserver/firestationport/services/SchoolSummaryQuartz.java new file mode 100644 index 0000000..3fe852f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/SchoolSummaryQuartz.java @@ -0,0 +1,183 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.services.analyze.StatisticsMessage; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.utils.HttpTools; +import com.jingyi.iotserver.utils.SkynetHikAPI; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.sql.DataSource; +import java.io.BufferedWriter; +import java.io.File; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; + +@Component +public class SchoolSummaryQuartz { + + @Autowired + private DataSource dataSource; + @Autowired + private DataStatisticsService dataStatisticsService; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + @Scheduled(cron = "0 5 0 * * ?") + // @Scheduled(cron = "0 35 13 * * ?") + public void execute(){ + //System.out.println("SchoolSummaryQuartz: execute"); + + StatisticsMessage msg = new StatisticsMessage(); + msg.setCode(StatisticsMessage.All_Summary_Code); + msg.setBorough(""); + msg.setBrigade(""); + msg.setDetachment(""); + msg.setStation(""); + msg.setDay(0); + msg.setYear(0); + msg.setMonth(0); + + dataStatisticsService.addStatisticsMessage(msg); + } + + @Scheduled(cron = "0 */2 * * * ?") + @PostConstruct + public void executeSkenetQuery(){ + //System.out.println("skynet face alarm query: execute"); + + if(FireCtrlSystemInit.netMode == 0) { + SkynetHikAPI.queryFaceAlarmRecords(ioTCtrlServer, dataSource, clientWebsocketManager); + } + } + + /* + public void calcAllStationDaySummary(){ + try { + List stationList = stationServices.queryAllStationList(5000,0); + if(stationList == null){ + return; + } + + if(stationList.size() <= 0){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + for(FireStationBaseInfoEntity calcStation:stationList){ + calcStationDaySummary(calcStation, nYear, nMonth, nDay); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void calcAllStationMonthSummary(){ + try { + List stationList = stationServices.queryAllStationList(5000,0); + if(stationList == null){ + return; + } + + if(stationList.size() <= 0){ + return; + } + Calendar curTime = Calendar.getInstance(); + int nYear = curTime.get(Calendar.YEAR); + int nMonth = curTime.get(Calendar.MONTH)+1; + //int nDay = curTime.get(Calendar.DAY_OF_MONTH); + + for(FireStationBaseInfoEntity calcStation:stationList){ + calcStationMonthSummary(calcStation, nYear, nMonth); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + */ + + // @Scheduled(cron = "0 */3 * * * ?") + private void scanBlacklistData(){ + String path = "./pic/精神病人"; + File filePath = new File(path); + File[] files = filePath.listFiles(); + if (files != null && files.length > 0) { + File firstFile = files[0]; + String fileName = firstFile.getName(); + + System.out.println("scanBlacklistData: " + fileName); + String[] fileDesc = fileName.split("\\."); + if(fileDesc.length == 2){ + String personInfo = fileDesc[0]; + + String[] personInfos = personInfo.split("_"); + if(personInfos.length == 3){ + String personName = personInfos[0]; + String personCert = personInfos[2]; + System.out.println("scanBlacklistData: " + personName); + System.out.println("scanBlacklistData: " + personCert); + + } + + } + + /* + for (File filePerson : files) { + + } + + */ + } + } + + + @Scheduled(cron = "0 */20 * * * ?") + @PostConstruct + public void keepLiveToMultiAlarmPlat(){ + if(FireCtrlSystemInit.netMode == 0) { + return; + } + + HttpURLConnection connLogin; + try { + String agentUrlLong = "http://175.6.124.250:8082/multialarm/platform/live" ; + System.out.println("process http into multi alarm plat: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("platKey", "LS0001"); + connLogin.setRequestProperty("platToken", "LS0001"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + JSONObject jsBody = new JSONObject(); + jsBody.put("platKey", "LS0001"); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(JSON.toJSONString(jsBody)); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("multi_alarm platform keep live: fail = " + responseCode); + } + }catch (Exception e){ + System.out.println("multi_alarm platform keep live: fail = " + e.getMessage()); + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/SensorService.java b/src/main/java/com/jingyi/iotserver/firestationport/services/SensorService.java new file mode 100644 index 0000000..76a28ad --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/SensorService.java @@ -0,0 +1,2548 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; + +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.complexquery.ACBParameterCalculate; +import com.jingyi.iotserver.firestationport.model.mdev.MDevPictureEntity; +import com.jingyi.iotserver.firestationport.model.multiPlatform.MultiAlarmEvent; +import com.jingyi.iotserver.firestationport.model.publicsafe.PublicAlarmEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmSummaryEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.sensor.rfid.RfidEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.water.WaterFlowDayEntity; +import com.jingyi.iotserver.firestationport.model.sensor.water.WaterFlowHourEntity; +import com.jingyi.iotserver.firestationport.model.sensor.water.WaterFlowInfoEntity; +import com.jingyi.iotserver.firestationport.model.sensor.water.WaterFlowMonthEntity; +import com.jingyi.iotserver.firestationport.model.sensor.ys.YsAlarmEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.sensor.*; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.model.station.StationBlacklistEvent; +import com.jingyi.iotserver.firestationport.model.station.StationStaffAISignInfo; +import com.jingyi.iotserver.firestationport.services.eyeapp.SensorEventPusher; +import com.jingyi.iotserver.firestationport.services.sensor.SensorRunInfoManager; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; + +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.*; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.*; +import okhttp3.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.sql.DataSource; +import java.io.*; +import java.net.HttpURLConnection; +import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.TimeUnit; + +@Service +public class SensorService { + @Autowired + private DataSource dataSource; + + @Autowired + private EnvConfigService envConfigService; + + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private DataStatisticsService dataStatisticsService; + + @Autowired + private FireStationLiveManager stationLiveManager; + + @Autowired + SensorRunInfoManager sensorRunInfoManager; + + @Autowired + SensorEventPusher sensorEventPusher; + + @Autowired + private StationServices stationServices; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private MessagePublisher messagePublisher; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + ConcurrentLinkedQueue mPushButtonMsgQueue = new ConcurrentLinkedQueue(); + ConcurrentLinkedQueue mEntranceAIFaceMsgQueue = new ConcurrentLinkedQueue(); + ConcurrentLinkedQueue mYsAlarmMsgQueue = new ConcurrentLinkedQueue(); + private Thread pushButtonservice = null; + + private boolean blInited = false; + public void Init(){ + if(blInited) + return ; + blInited = true; + pushButtonservice = new Thread(){ + public void run(){ + while(true){ + try { + if(mPushButtonMsgQueue.size()>0){ + String msg = mPushButtonMsgQueue.poll(); + processPushButtonEvent(msg); + } + if(mEntranceAIFaceMsgQueue.size()>0){ + String msg = mEntranceAIFaceMsgQueue.poll(); + processEntranceFaceEvent(msg); + } + /* + if(mYsAlarmMsgQueue.size()>0){ + YsAlarmEntity msg = mYsAlarmMsgQueue.poll(); + processYsAlarmEvent(msg); + } + + */ + }catch (Exception e){ + } + + try{ + Thread.sleep(1*1000); + }catch (Exception e){ + + } + } + } + }; + + pushButtonservice.start(); + + } + public RespEntity addSensor(SensorDeviceEntity sensor){ + SensorDeviceEntity s = SensorDeviceEntity.Query(dataSource,sensor.getDeviceid()); + if(s!=null) + return new RespEntity(RespCode.EXIST); + if(sensor.getPower()<=0) + sensor.setPower(100); + if(sensor.getEnableuse()==null) + sensor.setEnableuse("use"); + if(sensor.getAlarm()==null||!sensor.getAlarm().equals("close")) + sensor.setAlarm("open"); + else + sensor.setAlarm("close"); + if(sensor.getStatus()==null) + sensor.setStatus("unknown"); + sensor.Insert(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + + public RespEntity deleteSensor(String devicesid){ + SensorDeviceEntity s = SensorDeviceEntity.Query(dataSource,devicesid); + if(s==null) + return new RespEntity(RespCode.NOTEXIST); + s.Delete(dataSource); + return new RespEntity(RespCode.SUCCESS); + } + + public RespEntity updateSensor(SensorDeviceEntity sensor){ + SensorDeviceEntity s = SensorDeviceEntity.Query(dataSource,sensor.getDeviceid()); + if(s==null) + return new RespEntity(RespCode.NOTEXIST); + + + if(sensor.Update(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + + } + + public List queryStationSensor(SensorDeviceEntity sensor){ + return sensor.queryList(dataSource,null,null); + + } + + public int querySensorCount(SensorDeviceEntity sensor){ + return sensor.queryCount(dataSource,null,null); + } + + + public List querySensorPage(int pagesize, int pageindex, SensorDeviceEntity sensor){ + return sensor.queryPage(dataSource,null,null,pageindex,pagesize); + + } + + private void generateSensorEvent(SensorEventEntity se,Date timestamp,SensorDeviceEntity sensor){ + if(se!=null){ + se.setDeviceid(sensor.getDeviceid()); + se.setDevicetype(sensor.getDevicetype()); + se.setBrigade(sensor.getBrigade()); + se.setBorough(sensor.getBorough()); + se.setDetachment(sensor.getDetachment()); + se.setStation(sensor.getOwner()); + se.setState("created"); + se.setTimestamp(timestamp); + se.setEventid(GUIDUtil.GenreralScerect(se.getDeviceid()+se.getDevicetype()+se.getTimestamp().getTime())); + + se.Insert(dataSource); + MessageToStation msg = new MessageToStation(); + msg.setMessage("sensor-event-notify"); + msg.setData(se); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + // if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + // JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + // } + messagePublisher.sendMessage( sensor.getOwner(),str); + } + } + public void processSmokingEvent(List events){ + for(SmokingEventEntity event:events){ + if(event.getDeviceid()==null) + continue; + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + continue; + sensorRunInfoManager.setSensorActive(sensor); + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + continue; + try { + if(event.getEvent().equals("alarm")&&(sensor.getAlarm()==null||!sensor.getAlarm().equals("open"))) + continue; + event.setOwner(sensor.getOwner()); + event.Insert(dataSource); + }catch (Exception e){ + + } + SensorEventEntity se = null; + try{ + sensor.setActivetime(new Date(event.getTimestamp()*1000)); + String status = event.getEvent(); + if(status.equals("cancelalarm")) { + stopSmokingBuzEvent(event.getDeviceid()); + return; + }else if(status.equals("heartbeat")) { + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus("normal"); + }else if(status.equals("lowpower")) { + se = new SensorEventEntity(); + se.setEvent("smoke.lowpower"); + sensor.setPower(10); + }else{ + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus(status); + se = new SensorEventEntity(); + if(sensor.getStatus().equals("alarm")) + se.setEvent("smoke.fire"); + else if(sensor.getStatus().equals("broken")) + se.setEvent("smoke.broken"); + else + se = null; + } + sensor.Update(dataSource); + + generateSensorEvent(se,new Date(event.getTimestamp()),sensor); + + SmokingSensorNotify notify = new SmokingSensorNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(event.getDevicetype()); + notify.setStation(sensor.getOwner()); + notify.setStatus(sensor.getStatus());//process status + + if(status.equals("heartbeat")) { + notify.setStatus(sensor.getStatus()); + notify.setPower(sensor.getPower()); + } + else if(status.equals("lowpower")) { + notify.setStatus(sensor.getStatus()); + sensor.setPower(10); + } + + + notify.setTimestamp(new Date(event.getTimestamp()*1000)); + OrganiztionUri from = fireStationLiveManager.getStationUri(notify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.station); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + //send notify to station + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("smoking-notify"); + msg.setData(notify); + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + + } + if(status.equals("alarm")){ + try { + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,sensor.getOwner()); + SmokingBuzEventEntity buzevent = SmokingBuzEventEntity.Query(dataSource,event.getDeviceid(), "start"); + if (buzevent == null){ + buzevent = new SmokingBuzEventEntity(); + buzevent.setDeviceid(sensor.getDeviceid()); + buzevent.setOwner(sensor.getOwner()); + buzevent.setBrigade(st.getBrigade()); + buzevent.setBorough(st.getBorough()); + buzevent.setDetachment(st.getDetachment()); + buzevent.setBuztype("smoking-alarm"); + buzevent.setStarttime(new Date()); + buzevent.setStatus("start"); + buzevent.setDevicetype("smoking"); + buzevent.Insert(dataSource); + SmokingBuzEventNotify buznotify = new SmokingBuzEventNotify(); + buznotify.setStation(sensor.getOwner()); + buznotify.setBrigade(st.getBrigade()); + buznotify.setBorough(st.getBorough()); + buznotify.setDetachment(st.getDetachment()); + buznotify.setBuztype(buzevent.getBuztype()); + buznotify.setDeviceid(buzevent.getDeviceid()); + buznotify.setDevicetype(buzevent.getDevicetype()); + buznotify.setStarttime(buzevent.getStarttime()); + buznotify.setStatus(buzevent.getStatus()); + buznotify.setEventid(buzevent.getEventid()); + + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.station); + pro.setDevice_id(buznotify.getDeviceid()); + pro.setDevice_type(buznotify.getDevicetype()); + pro.setNotifyflag(sensor.getHouseowner()); + buznotify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(buznotify); + sensorEventPusher.PushSensorEvent(buznotify); + } + + + //send event to station + MessageToStation msg = new MessageToStation(); + msg.setMessage("smoking-alarm-event"); + msg.setData(buzevent); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + } + messagePublisher.sendMessage( sensor.getOwner(),str); + + + } + }catch (Exception e){ + + } + } + + }catch (Exception e){ + + } + } + } + + public void processEarthInductorEvent(EarthInductorEventEntity event){ + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + return; + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + return; + sensorRunInfoManager.setSensorActive(sensor); + try { + event.setOwner(sensor.getOwner()); + if(event.getEvent().equals("idle")||event.getEvent().equals("occupy")) + event.Insert(dataSource); + }catch (Exception e){ + try{ + if(event.getEvent().equals("idle")||event.getEvent().equals("occupy")) { + event.Insert(dataSource); + } + }catch (Exception el){ + + } + } + SensorEventEntity se = null; + try{ + sensor.setActivetime(new Date(event.getTimestamp())); + String status = event.getEvent(); + if(status.equals("idle")||status.equals("idle-heartbeat")) + sensor.setStatus("idle"); + else if(status.equals("occupy")||status.equals("occupy-heartbeat")) + sensor.setStatus("occupy"); + else + return ; + if(status.equals("occupy")) { + se = new SensorEventEntity(); + se.setEvent("occupy"); + } + sensor.Update(dataSource); + generateSensorEvent(se,new Date(event.getTimestamp()),sensor); + + EarthInductorNotify notify = new EarthInductorNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(event.getDevicetype()); + notify.setStation(sensor.getOwner()); + notify.setPower(sensor.getPower()); + + if(status.equals("idle")||status.equals("idle-heartbeat")) + notify.setStatus("idle"); + else if(status.equals("occupy")||status.equals("occupy-heartbeat")) + notify.setStatus("occupy"); + + + notify.setTimestamp(new Date(event.getTimestamp())); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource,notify.getStation()); + + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + + //send notify to station + + MessageToStation msg = new MessageToStation(); + msg.setMessage("earthinductor-notify"); + msg.setData(notify); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) + { + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + } + messagePublisher.sendMessage(sensor.getOwner(),str); + if(notify.getStatus().equals("occupy")){ + sensorRunInfoManager.SetEarthInductorOccupy(event.getDeviceid()); + + }else if(notify.getStatus().equals("idle")){ + sensorRunInfoManager.SetEarthInductorIdle(event.getDeviceid()); + } + + }catch (Exception e){ + + } + + } + + public RespEntity stopSmokingBuzEvent(String deviceid){ + + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,deviceid); + if(sensor!=null){ + // SensorDeviceEntity temp = new SensorDeviceEntity(); + /// temp.setDeviceid(sensor.getDeviceid()); + sensor.setStatus("normal"); + sensor.Update(dataSource); + } + + SmokingSensorNotify notify = new SmokingSensorNotify(); + notify.setDeviceid(sensor.getDeviceid()); + notify.setDevicetype(sensor.getDevicetype()); + notify.setStation(sensor.getOwner()); + notify.setStatus("normal");//process status + notify.setPower(sensor.getPower()); + + + notify.setTimestamp(new Date()); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource,notify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + //send notify to station + MessageToStation msg = new MessageToStation(); + msg.setMessage("smoking-notify"); + msg.setData(notify); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + + } + messagePublisher.sendMessage(sensor.getOwner(),str); + SmokingBuzEventEntity buzevent = SmokingBuzEventEntity.Query(dataSource,deviceid, "start"); + if(buzevent==null) + return new RespEntity(RespCode.NOTEXIST); + + + buzevent.Stop(dataSource); + //notify client & station + SmokingBuzEventNotify buznotify = new SmokingBuzEventNotify(); + buznotify.setStation(buzevent.getOwner()); + buznotify.setBrigade(buzevent.getBrigade()); + buznotify.setBorough(buzevent.getBorough()); + buznotify.setDetachment(buzevent.getDetachment()); + buznotify.setBuztype(buzevent.getBuztype()); + buznotify.setDeviceid(buzevent.getDeviceid()); + buznotify.setDevicetype(buzevent.getDevicetype()); + buznotify.setStarttime(buzevent.getStarttime()); + buznotify.setStatus(buzevent.getStatus()); + buznotify.setEventid(buzevent.getEventid()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(buznotify.getDeviceid()); + pro.setDevice_type(buznotify.getDevicetype()); + pro.setNotifyflag(sensor.getHouseowner()); + buznotify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(buznotify); + sensorEventPusher.PushSensorEvent(buznotify); + } + + //send event to station + msg = new MessageToStation(); + msg.setMessage("smoking-alarm-event"); + msg.setData(buzevent); + msg.setTitle("iot"); + str = JsonHelper.convertObjectToStr(msg); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + } + messagePublisher.sendMessage(sensor.getOwner(),str); + return new RespEntity(RespCode.SUCCESS); + } + + public RespEntity ownerProcessSmokingBuzEvent(SmokingBuzEventEntity buzevent){ + if(buzevent==null||buzevent.getEventid()<0) + return new RespEntity(RespCode.ERROR_REQUEST); + SmokingBuzEventEntity bevent = SmokingBuzEventEntity.Query(dataSource,buzevent.getEventid()); + if(bevent==null) + return new RespEntity(RespCode.NOTEXIST); + + try { + if (buzevent.getStatus()!=null&&buzevent.getStatus().equals("stop") && bevent.getStatus()!=null&&bevent.getStatus().equals("start")) { + stopSmokingBuzEvent(buzevent.getDeviceid()); + } else { + buzevent.setStatus(null); + } + buzevent.Update(dataSource); + return new RespEntity(RespCode.SUCCESS); + }catch (Exception e){ + return new RespEntity(RespCode.EXCEPTION); + } + + } + + public List querySatationSmokingBuzEvent(String owner,String status){ + SmokingBuzEventEntity event = new SmokingBuzEventEntity(); + event.setOwner(owner); + event.setStatus(status); + return event.queryList(dataSource,null,null); + } + + public List querySatationEarthInductorBuzEvent(String owner, String status){ + EarthInductorBuzEventEntity event = new EarthInductorBuzEventEntity(); + event.setOwner(owner); + event.setStatus(status); + return event.queryList(dataSource,null,null); + } + + + public void processPipePressureEvent(List events) { + + for(PipePressureEventEntity event:events){ + if(event.getDeviceid()==null) + continue; + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + continue; + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + continue; + sensorRunInfoManager.setSensorActive(sensor); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + event.Insert(dataSource); + SensorEventEntity se = null; + ArrayList selist = new ArrayList(); + try{ + sensor.setActivetime(event.getTimestamp()); + String status = event.getEvent(); + if(status.equals("heartbeat")) { + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus("normal"); + }else if(status.equals("alarm")){ + + + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus(status); + } + LiquidGageAlarmSettingEntity setting = LiquidGageAlarmSettingEntity.QuerySetting(dataSource,sensor.getDeviceid()); + if(setting!=null){ + String alarm = null; + if(event.getkPa()>=setting.getHightout()){ + if(alarm==null) + alarm = "out1high"; + else + alarm += "|out1high"; + se = new SensorEventEntity(); + se.setEvent("waterpressure.overload"); + selist.add(se); + } + + if(event.getkPa() events){ + for(LiquidGageEventEntity event:events){ + if(event.getDeviceid()==null) + continue; + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + continue; + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + continue; + sensorRunInfoManager.setSensorActive(sensor); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + try { + event.setOwner(sensor.getOwner()); + event.Insert(dataSource); + }catch (Exception e){ + continue; + } + SensorEventEntity se = null; + ArrayList selist = new ArrayList(); + LiquidGageAlarmSettingEntity setting = LiquidGageAlarmSettingEntity.QuerySetting(dataSource,sensor.getDeviceid()); + if(setting!=null){ + String alarm = null; + if(event.getmH2O()>=setting.getHightout()){ + if(alarm==null) + alarm = "out1high"; + else + alarm += "|out1high"; + se = new SensorEventEntity(); + se.setEvent("waterpressure.overload"); + selist.add(se); + } + + if(event.getmH2O() events){ + for(GasSensorEventEntity event:events){ + if(event.getDeviceid()==null) + continue; + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + continue; + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + continue; + sensorRunInfoManager.setSensorActive(sensor); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + try { + event.setOwner(sensor.getOwner()); + event.Insert(dataSource); + }catch (Exception e){ + continue; + } + + SensorEventEntity se = null; + + try{ + sensor.setActivetime(event.getTimestamp()); + String status = event.getEvent(); + if(status.equals("heartbeat")) { + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus("normal"); + }else if(status.equals("alarm")){ + se = new SensorEventEntity(); + se.setEvent("alarm"); + se.setDescription(status); + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus(status); + } + sensor.setLineState("online"); + sensor.Update(dataSource); + // generateSensorEvent(se,event.getTimestamp(),sensor); + // if(event.getEvent().equals("alarm")&&(sensor.getAlarm()!=null&&sensor.getAlarm().equals("open"))) + { + //send alarm notify to client + GasSensorNotify notify = new GasSensorNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(event.getDevicetype()); + notify.setStation(sensor.getOwner()); + + notify.setEvent(event.getEvent());//process status + notify.setStatus(event.getStatus()); + notify.setTimestamp(event.getTimestamp()); + notify.setAlarmtype(event.getAlarmtype()); + + notify.setPower(event.getPower()); + notify.setTemperature(event.getTemperature()); + notify.setHumidity(event.getHumidity()); + notify.setTvoc(event.getTvoc()); + + notify.setCh2o(event.getCh2o()); + notify.setCo(event.getCo()); + notify.setCo2(event.getCo2()); + notify.setOxygen(event.getOxygen()); + + notify.setAmmonia(event.getAmmonia()); + notify.setHepatic(event.getHepatic()); + notify.setChlorine(event.getChlorine()); + notify.setEx(event.getEx()); + notify.setPm25(event.getPm2d5()); + notify.setPm10(event.getPm10()); + notify.setRadiosignal(event.getRadiosignal()); + notify.setOxygen3(event.getOxygen3()); + notify.setCh4(event.getCh4()); + notify.setOilfume(event.getOilfume()); + notify.setArg0(event.getArg0()); + notify.setArg0name(event.getArg0name()); + notify.setArg1(event.getArg1()); + notify.setArg1name(event.getArg1name()); + notify.setArg2(event.getArg2()); + notify.setArg2name(event.getArg2name()); + OrganiztionUri from = fireStationLiveManager.getStationUri(notify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.station); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + + + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + //send notify to station + + + try { + MessageToStation msg = new MessageToStation(); + msg.setMessage("gasstatus"); + msg.setData(event); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + //messagePublisher.sendMessage(sensor.getOwner(),str); + }catch (Exception e){ + + } + } + + }catch (Exception e){ + + } + } + } + + public void processAlerterHostEvent(List events){ + for(AlerterHostEventEntity event:events){ + if(event.getDeviceid()==null) + continue; + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + continue; + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + continue; + sensorRunInfoManager.setSensorActive(sensor); + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + try { + event.setOwner(sensor.getOwner()); + if(!event.getEvent().equals("source-data")) + event.Insert(dataSource); + }catch (Exception e){ + continue; + } + SensorEventEntity se = null; + System.out.println("hostalart:"+event.getEvent()); + System.out.println("devid:"+event.getDeviceid()); + System.out.println("alarm:"+event.getAlarm()); + try{ + sensor.setActivetime(event.getTimestamp()); + String status = event.getEvent(); + if(status.equals("heartbeat")) { + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus("normal"); + return; + }else if(status.equals("alarm")){ + se = new SensorEventEntity(); + se.setEvent("alarm"); + se.setDescription(event.getEvent()); + if(sensor.getStatus()==null||!sensor.getStatus().equals("alarm")) + sensor.setStatus(status); + } + generateSensorEvent(se,event.getTimestamp(),sensor); + + // if(event.getEvent().equals("alarm")&&(sensor.getAlarm()!=null&&sensor.getAlarm().equals("open"))) + { + + //send notify to station + try { + // if(status.equals("alarm")) + MessageToStation msg = new MessageToStation(); + msg.setMessage("alerterhost"); + msg.setData(event); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + } + messagePublisher.sendMessage(sensor.getOwner(),str); + }catch (Exception e){ + + } + } + + }catch (Exception e){ + + } + } + } + + public void processAlarmHostEvent(List events){ + for(STVAlarmEventEntity event:events){ + if(event.getDeviceid()==null) + continue; + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,event.getDeviceid()); + if(sensor==null) + continue; + if(sensor.getEnableuse()==null||!sensor.getEnableuse().equals("use")) + continue; + + String position = String.format("%02d", event.getSystemaddress()) + String.format("%03d",event.getLineaddress()) + String.format("%03d", event.getDeviceaddress()); + + SensorSubDeviceEntity sub = new SensorSubDeviceEntity(); + sub.setDeviceid(event.getDeviceid()); + sub.setPosition(position); + sub = (SensorSubDeviceEntity)sub.QueryIt(dataSource); + if(sub!=null&&sub.getDescription()!=null){ + event.setDescription(sub.getDescription()); + } + sensorRunInfoManager.setSensorActive(sensor); + if(event.getType()==8||event.getType()==28){ + sensor.setActivetime(event.getTimestamp()); + continue; + } + event.setOwner(sensor.getOwner()); + event.setDevicetype(sensor.getDevicetype()); + try { + event.setOwner(sensor.getOwner()); + event.Insert(dataSource); + }catch (Exception e){ + continue; + } + + System.out.println("devid:"+event.getDeviceid()); + System.out.println("alarm:"+event.getAlarm()); + try{ + sensor.setActivetime(event.getTimestamp()); + + + // if(event.getEvent().equals("alarm")&&(sensor.getAlarm()!=null&&sensor.getAlarm().equals("open"))) + { + //send alarm notify to client + AlarmHostEventNotify notify = new AlarmHostEventNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(event.getDevicetype()); + notify.setStation(sensor.getOwner()); + notify.setTimestamp(event.getTimestamp()); + + notify.setId(event.getId()); + notify.setSource(event.getSource()); + + notify.setType(event.getType()); + notify.setSystemtype(event.getSystemtype()); + notify.setSystemaddress(event.getSystemaddress()); + + notify.setLineaddress(event.getLineaddress()); + notify.setDeviceaddress(event.getDeviceaddress()); + notify.setDescription(event.getDescription()); + notify.setMode(event.getMode()); + notify.setAlarm(event.getAlarm()); + notify.setBreakdown(event.getBreakdown()); + notify.setBlock(event.getBlock()); + notify.setSupervise(event.getSupervise()); + notify.setStatus(event.getStatus()); + notify.setResponse(event.getResponse()); + notify.setDelay(event.getDelay()); + notify.setMasterpowerbreak(event.getMasterpowerbreak()); + notify.setStandbypowerbreak(event.getStandbypowerbreak()); + notify.setBusbreak(event.getBusbreak()); + notify.setAuto(event.getAuto()); + notify.setConfigchanged(event.getConfigchanged()); + notify.setReset(event.getReset()); + notify.setAlarmstate(event.getAlarmstate()); + notify.setReporttime(event.getReporttime()); + notify.setAcktime(event.getAcktime()); + notify.setDevtype(event.getDevtype()); + + OrganiztionUri from = fireStationLiveManager.getStationUri(notify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.station); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + + + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + //send notify to station + try { + // if(status.equals("alarm")) + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarmhost"); + msg.setData(event); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot",str , 0); + } + messagePublisher.sendMessage(sensor.getOwner(),str); + }catch (Exception e){ + + } + } + + }catch (Exception e){ + + } + } + } + + public ACBParameterCalculate calACBParameter(String deviceid,String startstr,String endstr){ + ACBStatusEntity status = new ACBStatusEntity(); + + status.setDeviceid(deviceid); + ACBParameterCalculate param = new ACBParameterCalculate(); + param.setDeviceid(deviceid); + + List list = null; + int index=0; + int count = 0; + do { + list = status.queryPage(dataSource, startstr, endstr, index, 500); + if(index==0&&list!=null&&list.size()>0){ + param.aldmin = 999999999.0; + param.aamin = 999999999.0; + param.atmin = 999999999.0; + param.avmin = 999999999.0; + param.awmin = 999999999.0; + param.apfmin = 999999999.0; + param.gldmin = 999999999.0; + param.gamin = 999999999.0; + param.gtmin = 999999999.0; + param.gvmin = 999999999.0; + param.gwmin = 999999999.0; + param.gpfmin = 999999999.0; + param.bamin = 999999999.0; + param.btmin = 999999999.0; + param.bvmin = 999999999.0; + + param.bwmin = 999999999.0; + param.bpfmin = 999999999.0; + param.camin = 999999999.0; + param.ctmin = 999999999.0; + param.cvmin = 999999999.0; + param.cwmin = 999999999.0; + param.cpfmin = 999999999.0; + param.namin = 999999999.0; + param.ntmin = 999999999.0; + } + index++; + if(list!=null&&list.size()>0) { + for (SQLDataObject ob : list){ + ACBStatusEntity st = (ACBStatusEntity)ob; + if(st==null) + continue; + double t = st.getAld(); + + param.ald += t; + if(param.aldmaxt) + param.aldmin = t; + + t = st.getAa(); + param.aa += t; + if(param.aamaxt) + param.aamin = t; + + t = st.getAt(); + param.at += t; + if(param.atmaxt) + param.atmin = t; + + t = st.getAv(); + param.av += t; + if(param.avmaxt) + param.avmin = t; + + t = st.getAw(); + param.aw += t; + if(param.awmaxt) + param.awmin = t; + + t = st.getApf(); + param.apf += t; + if(param.apfmaxt) + param.apfmin = t; + + t = st.getGld(); + param.gld += t; + if(param.gldmaxt) + param.gldmin = t; + + t = st.getGa(); + param.ga += t; + if(param.gamaxt) + param.gamin = t; + + t = st.getGt(); + param.gt += t; + if(param.gtmaxt) + param.gtmin = t; + + t = st.getGv(); + param.gv += t; + if(param.gvmaxt) + param.gvmin = t; + + t = st.getGw(); + param.gw += t; + if(param.gwmaxt) + param.gwmin = t; + + t = st.getGpf(); + param.gpf += t; + if(param.gpfmaxt) + param.gpfmin = t; + + t = st.getBa(); + param.ba += t; + if(param.bamaxt) + param.bamin = t; + + t = st.getBt(); + param.bt += t; + if(param.btmaxt) + param.btmin = t; + + t = st.getBv(); + param.bv += t; + if(param.bvmaxt) + param.bvmin = t; + + t = st.getBw(); + param.bw += t; + if(param.bwmaxt) + param.bwmin = t; + + t = st.getBpf(); + param.bpf += t; + if(param.bpfmaxt) + param.bpfmin = t; + + t = st.getCa(); + param.ca += t; + if(param.camaxt) + param.camin = t; + + t = st.getCt(); + param.ct += t; + if(param.ctmaxt) + param.ctmin = t; + + t = st.getCv(); + param.cv += t; + if(param.cvmaxt) + param.cvmin = t; + + t = st.getCw(); + param.cw += t; + if(param.cwmaxt) + param.cwmin = t; + + t = st.getCpf(); + param.cpf += t; + if(param.cpfmaxt) + param.cpfmin = t; + + t = st.getNa(); + param.na += t; + if(param.namaxt) + param.namin = t; + + t = st.getNt(); + param.nt += t; + if(param.ntmaxt) + param.ntmin = t; + + count++; + } + } + }while(list!=null&&list.size()>=500); + + if(count>0) { + param.ald /= count; + param.aa /= count; + param.at /= count; + param.av /= count; + param.aw /= count; + param.apf /= count; + + param.gld /= count; + param.ga /= count; + param.gt /= count; + param.gv /= count; + param.gw /= count; + param.gpf /= count; + + param.ba /= count; + param.bt /= count; + param.bv /= count; + param.bw /= count; + param.bpf /= count; + + param.ca /= count; + param.ct /= count; + param.cv /= count; + param.cw /= count; + param.cpf /= count; + param.na /= count; + param.nt /= count; + } + return param; + } + + public void processWaterMeterEvent(JsonNode eventlist){ + + if(!eventlist.isArray()) + return ; + for(int i=0;i0){ + WaterMeterMonthCountEntity count = new WaterMeterMonthCountEntity(); + count.setDeviceid(sensor.getDeviceid()); + count.setOwner(sensor.getOwner()); + count.setDevicetype(sensor.getDevicetype()); + count.setMonthcount(monthcount[0]); + Date mon = new Date(ts); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(mon); //放入Date类型数据 + count.setYear(calendar.get(Calendar.YEAR)); + count.setMonth(calendar.get(Calendar.MONTH)); + if(count.QueryIt(dataSource)==null){ + count.Insert(dataSource); + }else { + count.Update(dataSource); + } + + if(index>1){ + count = new WaterMeterMonthCountEntity(); + count.setDeviceid(sensor.getDeviceid()); + count.setOwner(sensor.getOwner()); + count.setDevicetype(sensor.getDevicetype()); + count.setMonthcount(monthcount[1]); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + if(month==1) { + month = 12; + year--; + }else{ + month --; + } + + count.setYear(year); + count.setMonth(month); + WaterMeterMonthCountEntity pre = (WaterMeterMonthCountEntity)count.QueryIt(dataSource); + if(pre==null){ + count.Insert(dataSource); + }else if(pre.getMonthcount()!=count.getMonthcount()) { + count.Update(dataSource); + } + } + } + } + evobj.setMonthcount(monthcount[0]); + + + float [] daycount = new float[64]; + index = 0; + countnde = JsonHelper.getLevel2(node,"daycount"); + if(countnde!=null&&countnde.isArray()) { + for(int j=0;j0){ + WaterMeterDayCountEntity count = new WaterMeterDayCountEntity(); + count.setDeviceid(sensor.getDeviceid()); + count.setOwner(sensor.getOwner()); + count.setDevicetype(sensor.getDevicetype()); + count.setDaycount(daycount[1]); + + Date day = new Date(ts-24*60*60*1000); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(day); //放入Date类型数据 + count.setYear(calendar.get(Calendar.YEAR)); + count.setMonth(calendar.get(Calendar.MONTH)); + count.setDay(calendar.get(Calendar.DATE)); + + if(count.QueryIt(dataSource)==null){ + count.Insert(dataSource); + } + } + } + evobj.setDaycount(daycount[0]); + + float [] hourcount = new float[48]; + index = 0; + countnde = JsonHelper.getLevel2(node,"hourcount"); + if(countnde!=null&&countnde.isArray()) { + String str = ""; + for(int j=0;j1){ + str += ","; + } + str += monthcount[index-1]; + } + } + + if(index>0){ + + for(int j=0;j lastEvents = oldEvent.QueryLasts(dataSource,1); + if(lastEvents != null && !lastEvents.isEmpty()){ + SensorAlarmEventEntity lastEvent= (SensorAlarmEventEntity)lastEvents.get(0); + Date lastTimestamp = lastEvent.getTimestamp(); + if(lastTimestamp != null){ + long lastDuration = timestamp.getTime() - lastTimestamp.getTime(); + + if(lastDuration < 30000){ + return null; + } + } + } + }catch (Exception e){ + //e.printStackTrace(); + } + + + alarmEvent.Insert(dataSource); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(timestamp); //放入Date类型数据 + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(timestamp); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmPoint.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmPoint.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(1); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(0); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldPushCount = alarmSummaryDB.getPushCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setPushCount(1+oldPushCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmPoint.getBrigade()); + pro.setBorough(alarmPoint.getBorough()); + pro.setDetachment(alarmPoint.getDetachment()); + pro.setStation(alarmPoint.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmPoint.getDeviceType()); + notify.attachProperty(pro); + + clientWebsocketManager.addWebNotify(notify); + + if(FireCtrlSystemInit.netMode == 1) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmPoint.getStation(), str); + System.out.println("report alarm to station: "+ str); + if(PushAlarmPointEntity.Translate_On.equals(alarmEvent.getNeedTranslate())){ + try{ + MultiAlarmEvent multiAlarmEvent = new MultiAlarmEvent(alarmEvent); + System.out.println("report alarm to multi-plat 一键报警: "+ JSON.toJSONString(multiAlarmEvent)); + multiAlarmEvent.reportToMultiPlat(); + }catch (Exception e){ + System.out.println("report alarm to multi-plat 一键报警 fail: "+ e); + } + } + } + + return alarmEvent; + } + + public void agentAlarmPointEvent(SensorAlarmEventEntity alarmEvent){ + if(alarmEvent == null){ + return; + } + PushAlarmPointEntity alarmPoint = PushAlarmPointEntity.Query(dataSource, alarmEvent.getDeviceId()); + if(alarmPoint == null){ + return; + } + + alarmEvent.setDevicetype(alarmPoint.getDeviceType()); + alarmEvent.setAlarmSource(alarmPoint.getDwmc()); + alarmEvent.setAddress(alarmPoint.getDwdz()); + alarmEvent.setLatitude(alarmPoint.getLatitude()); + alarmEvent.setLongitude(alarmPoint.getLongitude()); + alarmEvent.setSubAddress(alarmPoint.getPointAddress()); + alarmEvent.setStation(alarmPoint.getStation()); + alarmEvent.setDetachment(alarmPoint.getDetachment()); + alarmEvent.setBorough(alarmPoint.getBorough()); + alarmEvent.setBrigade(alarmPoint.getBrigade()); + alarmEvent.setCity(alarmPoint.getCity()); + alarmEvent.setDistrict(alarmPoint.getDistrict()); + alarmEvent.setTown(alarmPoint.getTown()); + alarmEvent.Insert(dataSource); + + Date timestamp = new Date(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(timestamp); //放入Date类型数据 + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(timestamp); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmPoint.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmPoint.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(1); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(0); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldPushCount = alarmSummaryDB.getPushCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setPushCount(1+oldPushCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmPoint.getBrigade()); + pro.setBorough(alarmPoint.getBorough()); + pro.setDetachment(alarmPoint.getDetachment()); + pro.setStation(alarmPoint.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmPoint.getDeviceType()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + public void addVoiceAlarmEvent(String dev_id){ + PushAlarmPointEntity alarmPoint = PushAlarmPointEntity.Query(dataSource, dev_id); + if(alarmPoint == null){ + return; + } + + Date timestamp = new Date(); + String eventId = alarmPoint.getPointId() + "_" + timestamp.getTime(); + + SensorAlarmEventEntity alarmEvent = new SensorAlarmEventEntity(); + alarmEvent.setEventId(eventId); + alarmEvent.setDeviceId(alarmPoint.getDeviceId()); + alarmEvent.setDevicetype(alarmPoint.getDeviceType()); + alarmEvent.setAlarmSource(alarmPoint.getDwmc()); + alarmEvent.setAddress(alarmPoint.getDwdz()); + alarmEvent.setLatitude(alarmPoint.getLatitude()); + alarmEvent.setLongitude(alarmPoint.getLongitude()); + alarmEvent.setSubAddress(alarmPoint.getPointAddress()); + alarmEvent.setStation(alarmPoint.getStation()); + alarmEvent.setDetachment(alarmPoint.getDetachment()); + alarmEvent.setBorough(alarmPoint.getBorough()); + alarmEvent.setBrigade(alarmPoint.getBrigade()); + alarmEvent.setCity(alarmPoint.getCity()); + alarmEvent.setDistrict(alarmPoint.getDistrict()); + alarmEvent.setTown(alarmPoint.getTown()); + + alarmEvent.setTimestamp(timestamp); + alarmEvent.setAlarmType(SensorAlarmEventEntity.Alarm_Type_SOS_Voice); + alarmEvent.setAlarmCode("语音求助"); + alarmEvent.setState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setReadState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setEventData(""); + alarmEvent.setAlarmTarget(alarmPoint.getPointName()); + + alarmEvent.setUser1Name(alarmPoint.getUserName()); + alarmEvent.setUser1Phone(alarmPoint.getUserPhone()); + alarmEvent.setUser2Name(alarmPoint.getUser2Name()); + alarmEvent.setUser2Phone(alarmPoint.getUser2Phone()); + alarmEvent.setUser3Name(alarmPoint.getUser3Name()); + alarmEvent.setUser3Phone(alarmPoint.getUser3Phone()); + + alarmEvent.setNeedTranslate(alarmPoint.getNeedTranslate()); + + SensorAlarmEventEntity oldEvent = new SensorAlarmEventEntity(); + oldEvent.setDeviceId(alarmPoint.getDeviceId()); + try { + List lastEvents = oldEvent.QueryLasts(dataSource,1); + if(lastEvents != null && !lastEvents.isEmpty()){ + SensorAlarmEventEntity lastEvent= (SensorAlarmEventEntity)lastEvents.get(0); + Date lastTimestamp = lastEvent.getTimestamp(); + if(lastTimestamp != null){ + long lastDuration = timestamp.getTime() - lastTimestamp.getTime(); + if(lastDuration < 30000){ + return; + } + } + } + }catch (Exception e){ + } + alarmEvent.Insert(dataSource); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(timestamp); //放入Date类型数据 + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(timestamp); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmPoint.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmPoint.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(1); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(0); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldPushCount = alarmSummaryDB.getPushCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setPushCount(1+oldPushCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmPoint.getBrigade()); + pro.setBorough(alarmPoint.getBorough()); + pro.setDetachment(alarmPoint.getDetachment()); + pro.setStation(alarmPoint.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmPoint.getDeviceType()); + notify.attachProperty(pro); + // System.out.println("websocket send sensor event 一键报警: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + if(FireCtrlSystemInit.netMode == 1) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmPoint.getStation(), str); + } + } + + private void addNewMDevAlarmEventSummary(SensorAlarmEventEntity alarmEvent){ + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + String strDay = SQLTools.formatDay(alarmEvent.getTimestamp()); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmEvent.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmEvent.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(0); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(1); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = alarmSummaryDB.getMdevCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setMdevCount(1+oldMDevCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + SensorAlarmSummaryEntity boroughSummary = new SensorAlarmSummaryEntity(); + boroughSummary.setRecordId(alarmEvent.getBorough() + "-" + strDay); + SensorAlarmSummaryEntity boroughSummaryDB = (SensorAlarmSummaryEntity)boroughSummary.QueryIt(dataSource); + if(boroughSummaryDB == null){ + boroughSummaryDB = new SensorAlarmSummaryEntity(); + boroughSummaryDB.setRecordId(alarmSummary.getRecordId()); + boroughSummaryDB.setBrigade(alarmEvent.getBorough()); + boroughSummaryDB.setYear(strY); + boroughSummaryDB.setMonth(strM); + boroughSummaryDB.setWeek(strWeek); + boroughSummaryDB.setDay(strD); + boroughSummaryDB.setPushCount(0); + boroughSummaryDB.setAlarmTotal(1); + boroughSummaryDB.setAiCount(0); + boroughSummaryDB.setSkynetCount(0); + boroughSummaryDB.setMdevCount(1); + boroughSummaryDB.setTimestamp(new Date()); + boroughSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = boroughSummaryDB.getMdevCount(); + int oldTotalCount = boroughSummaryDB.getAlarmTotal(); + boroughSummaryDB.setMdevCount(1+oldMDevCount); + boroughSummaryDB.setAlarmTotal(1+oldTotalCount); + boroughSummaryDB.Update(dataSource); + } + + SensorAlarmSummaryEntity detachmentSummary = new SensorAlarmSummaryEntity(); + detachmentSummary.setRecordId(alarmEvent.getDetachment() + "-" + strDay); + SensorAlarmSummaryEntity detachmentSummaryDB = (SensorAlarmSummaryEntity)detachmentSummary.QueryIt(dataSource); + if(detachmentSummaryDB == null){ + detachmentSummaryDB = new SensorAlarmSummaryEntity(); + detachmentSummaryDB.setRecordId(alarmSummary.getRecordId()); + detachmentSummaryDB.setBrigade(alarmEvent.getDetachment()); + detachmentSummaryDB.setYear(strY); + detachmentSummaryDB.setMonth(strM); + detachmentSummaryDB.setWeek(strWeek); + detachmentSummaryDB.setDay(strD); + detachmentSummaryDB.setPushCount(0); + detachmentSummaryDB.setAlarmTotal(1); + detachmentSummaryDB.setAiCount(0); + detachmentSummaryDB.setSkynetCount(0); + detachmentSummaryDB.setMdevCount(1); + detachmentSummaryDB.setTimestamp(new Date()); + detachmentSummaryDB.Insert(dataSource); + }else{ + int oldMDevCount = detachmentSummaryDB.getMdevCount(); + int oldTotalCount = detachmentSummaryDB.getAlarmTotal(); + detachmentSummaryDB.setMdevCount(1+oldMDevCount); + detachmentSummaryDB.setAlarmTotal(1+oldTotalCount); + detachmentSummaryDB.Update(dataSource); + } + + } + + public void addWechatAlarmEvent(PublicAlarmEntity wcAlarm){ + Date timestamp = new Date(); + + SensorAlarmEventEntity alarmEvent = new SensorAlarmEventEntity(); + alarmEvent.setEventId(wcAlarm.getAlarmId()); + alarmEvent.setDeviceId(wcAlarm.getReporterAccount()); + alarmEvent.setDevicetype("app"); + alarmEvent.setAlarmSource("wechat"); + alarmEvent.setAddress(wcAlarm.getAddress()); + alarmEvent.setLatitude(wcAlarm.getLatitude()); + alarmEvent.setLongitude(wcAlarm.getLongitude()); + alarmEvent.setSubAddress(wcAlarm.getStreet()); + alarmEvent.setStation("测试组11628584787489"); + alarmEvent.setDetachment("平台设备测试1628584772586"); + alarmEvent.setBorough("平台设备测试1628584751394"); + alarmEvent.setBrigade("lonsungsh"); + alarmEvent.setTimestamp(timestamp); + alarmEvent.setAlarmType("sos"); + alarmEvent.setAlarmCode("求助"); + alarmEvent.setState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setReadState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setEventData(""); + alarmEvent.setAlarmTarget(""); + alarmEvent.setUser1Name(wcAlarm.getReporterName()); + alarmEvent.setUser1Phone(""); + alarmEvent.setUser2Name(""); + alarmEvent.setUser2Phone(""); + alarmEvent.setUser3Name(""); + alarmEvent.setUser3Phone(""); + + alarmEvent.Insert(dataSource); + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmEvent.getBrigade()); + pro.setBorough(alarmEvent.getBorough()); + pro.setDetachment(alarmEvent.getDetachment()); + pro.setStation(alarmEvent.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmEvent.getDevicetype()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + + if(FireCtrlSystemInit.netMode == 1) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmEvent.getStation(), str); + + /* + try{ + MultiAlarmEvent multiAlarmEvent = new MultiAlarmEvent(alarmEvent); + System.out.println("report alarm to multi-plat 一键报警: "+ JSON.toJSONString(multiAlarmEvent)); + multiAlarmEvent.reportToMultiPlat(); + }catch (Exception e){ + System.out.println("report alarm to multi-plat 一键报警 fail: "+ e); + } + + */ + } + } + + public void processRfidEvent(List events){ + + } + + private static int skyRand = 0; + public void processEntranceFaceEvent(String json){ + try { + //System.out.println("face data: "+json); + + JSONObject jsFace = JSON.parseObject(json); + String dataType =jsFace.getString("operator"); + if(dataType == null){ + return; + } + if(dataType.equalsIgnoreCase("RecPush")){ + JSONObject jsFaceObj = jsFace.getJSONObject("info"); + if(jsFaceObj == null){ + return; + } + + String facesluiceId = jsFaceObj.getString("facesluiceId"); + String personId = jsFaceObj.getString("personId"); + String customId = jsFaceObj.getString("customId"); + String RecordID = jsFaceObj.getString("RecordID"); + String VerifyStatus = jsFaceObj.getString("VerifyStatus"); + String PersonType = jsFaceObj.getString("PersonType"); + String similarity1 = jsFaceObj.getString("similarity1"); + String similarity2 = jsFaceObj.getString("similarity2"); + int Sendintime = jsFaceObj.getIntValue("Sendintime"); + String direction = jsFaceObj.getString("direction"); + String otype = jsFaceObj.getString("otype"); + String persionName = jsFaceObj.getString("persionName"); + String facesluiceName = jsFaceObj.getString("facesluiceName"); + String idCard = jsFaceObj.getString("idCard"); + String telnum = jsFaceObj.getString("telnum"); + String PushType = jsFaceObj.getString("PushType"); + String OpendoorWay = jsFaceObj.getString("OpendoorWay"); + String cardNum2 = jsFaceObj.getString("cardNum2"); + String RFIDCard = jsFaceObj.getString("RFIDCard"); + String szQrCodeData = jsFaceObj.getString("szQrCodeData"); + + StationStaffAISignInfo jsFaceRec = new StationStaffAISignInfo(); + jsFaceRec.setFacesluiceId(facesluiceId); + jsFaceRec.setPersonId(personId);; + jsFaceRec.setCustomId(customId); + jsFaceRec.setRecordID(RecordID); + jsFaceRec.setVerifyStatus(VerifyStatus); + jsFaceRec.setPersonType(PersonType); + jsFaceRec.setSimilarity1(similarity1); + jsFaceRec.setSimilarity2(similarity2); + jsFaceRec.setSendintime(Sendintime); + jsFaceRec.setDirection(direction); + jsFaceRec.setOtype(otype); + jsFaceRec.setPersionName(persionName); + jsFaceRec.setFacesluiceName(facesluiceName); + jsFaceRec.setIdCard(idCard); + jsFaceRec.setTelnum(telnum); + jsFaceRec.setPushType(PushType); + jsFaceRec.setOpendoorWay(OpendoorWay); + jsFaceRec.setCardNum2(cardNum2); + jsFaceRec.setRFIDCard(RFIDCard); + jsFaceRec.setSzQrCodeData(szQrCodeData); + + if(jsFaceRec.getFacesluiceId() == null){ + return; + } + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, jsFaceRec.getFacesluiceId()); + if (sensor == null){ + return; + } + System.out.println("face iot device: "+sensor.getDeviceid()); + sensorRunInfoManager.setSensorActive(sensor); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, sensor.getOwner()); + if (from == null) { + return; + } + System.out.println("face iot station: "+sensor.getOwner()); + jsFaceRec.setBorough(from.getBorough()); + jsFaceRec.setBrigade(from.getBrigade()); + jsFaceRec.setStation(from.getName()); + jsFaceRec.setDetachment(from.getDetachment()); + jsFaceRec.setTime(new Date()); + jsFaceRec.Insert(dataSource); + + // dataStatisticsService.addEntranceFaceEvent(from); + }else if(dataType.equalsIgnoreCase("StrSnapPush")){ + JSONObject jsSnapObj = jsFace.getJSONObject("info"); + if(jsSnapObj == null){ + return; + } + + String facesluiceId = jsSnapObj.getString("facesluiceId"); + if(skyRand == 0){ + facesluiceId = "43010250001310659563"; + skyRand = 1; + }else if(skyRand == 1){ + facesluiceId = "43010250001310234736"; + skyRand = 2; + }else if(skyRand == 2){ + facesluiceId = "43010250001310234736"; + skyRand = 3; + }else if(skyRand == 3){ + facesluiceId = "43010250001310596520"; + skyRand = 4; + } else if(skyRand == 4){ + facesluiceId = "43010206001310427256"; + skyRand = 5; + } else if(skyRand == 5){ + facesluiceId = "43010250001310596520"; + skyRand = 6; + } else if(skyRand == 6){ + facesluiceId = "43010206001310779856"; + skyRand = 7; + }else{ + facesluiceId = "43010206001310930944"; + skyRand = 0; + } + String picData = jsSnapObj.getString("pic"); + String snapId = jsSnapObj.getString("SnapID"); + + if(facesluiceId == null){ + return; + } + System.out.println("face data: "+facesluiceId); + SkynetIPCEntity sensor = SkynetIPCEntity.Query(dataSource, facesluiceId); + if (sensor == null){ + return; + } + System.out.println("skynet ipc: "+JSON.toJSONString(sensor)); + FireStationBaseInfoEntity stationInfo = FireStationBaseInfoEntity.Query(dataSource, sensor.getStation()); + if (stationInfo == null) { + return; + } + + StationBlacklistEvent blacklistEvent = new StationBlacklistEvent(); + blacklistEvent.setBlackName("王xx"); + blacklistEvent.setBlackType("省级重点人员"); + blacklistEvent.setFacesluiceId(facesluiceId); + blacklistEvent.setPic(picData); + blacklistEvent.setIdNumber("88989809875459898"); + + if(skyRand == 0){ + blacklistEvent.setBlackName("王xx"); + blacklistEvent.setBlackType("市重点人员"); + blacklistEvent.setIdNumber("88989809875459898"); + }else if(skyRand == 1){ + blacklistEvent.setBlackName("刘xx"); + blacklistEvent.setBlackType("省级重点人员"); + blacklistEvent.setIdNumber("77989809875459898"); + }else if(skyRand == 2){ + blacklistEvent.setBlackName("许xx"); + blacklistEvent.setBlackType("市重点人员"); + blacklistEvent.setIdNumber("97989809875459898"); + }else if(skyRand == 3){ + blacklistEvent.setBlackName("张嘎子"); + blacklistEvent.setBlackType("省级重点人员"); + blacklistEvent.setIdNumber("27989809875459898"); + }else if(skyRand == 5){ + blacklistEvent.setBlackName("王二麻子"); + blacklistEvent.setBlackType("省级重点人员"); + blacklistEvent.setIdNumber("31089809875459898"); + }else{ + blacklistEvent.setBlackName("吴大傻"); + blacklistEvent.setBlackType("市重点人员"); + blacklistEvent.setIdNumber("47989809875459898"); + } + + Date timestamp = new Date(); + + // String imageId = facesluiceId+"_"+blacklistEvent.getBlackName()+"_"+ timestamp.getTime(); + String eventId = facesluiceId+"_"+snapId+"_"+ timestamp.getTime(); + // EventImageEntity imageData = new EventImageEntity(imageId); + // imageData.setImageData(picData); + // imageData.setEventId(eventId); + // imageData.Insert(dataSource); + + // blacklistEvent.setPic(imageId); + + SensorAlarmEventEntity alarmEvent = new SensorAlarmEventEntity(); + alarmEvent.setEventId(eventId); + alarmEvent.setDeviceId(facesluiceId); + alarmEvent.setDevicetype(sensor.getDeviceType()); + alarmEvent.setAlarmSource(sensor.getName()); + alarmEvent.setAddress(sensor.getName()); + alarmEvent.setLatitude(sensor.getLatitude()); + alarmEvent.setLongitude(sensor.getLongitude()); + alarmEvent.setSubAddress(""); + alarmEvent.setStation(stationInfo.getName()); + alarmEvent.setDetachment(stationInfo.getDetachment()); + alarmEvent.setBorough(stationInfo.getBorough()); + alarmEvent.setBrigade(stationInfo.getBrigade()); + alarmEvent.setTimestamp(timestamp); + alarmEvent.setAlarmType(SensorAlarmEventEntity.Alarm_Type_AI_Entrance); + alarmEvent.setAlarmCode("高危人员预警"); + alarmEvent.setState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setEventData(JSON.toJSONString(blacklistEvent)); + alarmEvent.setAlarmTarget(blacklistEvent.getBlackName()); + alarmEvent.Insert(dataSource); + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(stationInfo.getBrigade()); + pro.setBorough(stationInfo.getBorough()); + pro.setDetachment(stationInfo.getDetachment()); + pro.setStation(stationInfo.getName()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(sensor.getDeviceType()); + notify.attachProperty(pro); + System.out.println("websocket send sensor event: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(sensor.getStation(),str); + + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + + private void ensureDir(){ + String path = "./pic"; + File dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + + path += "/ys"; + dir = new File(path); + if(!dir.exists()){ + dir.mkdir(); + } + } + + private void processYsAlarmEvent(YsAlarmEntity ysAlarm){ + if(ysAlarm.QueryIt(dataSource) == null){ + ysAlarm.Insert(dataSource); + } + + ensureDir(); + + String fileUrl = ysAlarm.getPictureUrl(); + String path = "./pic/ys/"; + String fileName = ysAlarm.getAlarmId()+".jpg"; + OkHttpClient client = new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS).build(); + + Request r = new Request.Builder().get().url(fileUrl).build(); + Call call = client.newCall(r); + + try { + Response response = call.execute(); + InputStream inputStream = Objects.requireNonNull(response.body().byteStream()); + + BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(path + fileName))); + + byte[] buffer = new byte[128*1024]; + int len = 0; + while((len = inputStream.read(buffer)) != -1) { + out.write(buffer,0,len); + } + out.flush(); + out.close(); + + MDevPictureEntity pupdate = new MDevPictureEntity(); + pupdate.setId(ysAlarm.getAlarmId()); + pupdate.setFilename(fileName); + String uri = "/mdev/pic/download?creator=ys"; + uri += "&file="+fileName; + pupdate.setUri(uri); + pupdate.setFilename(fileName); + pupdate.setUri(uri); + pupdate.setUploadtime(new Date()); + pupdate.setCreator("ys"); + pupdate.Insert(dataSource); + + } catch (FileNotFoundException e) { + return ; + } catch (IOException e) { + return ; + } + } + + + @Scheduled(cron = "0 */5 * * * ?") + public void addWaterFlowSimData(){ + if(FireCtrlSystemInit.netMode == 0) { + return; + } + + try { + SensorDeviceEntity waterDevice = new SensorDeviceEntity(); + waterDevice.setDevicetype("watercheck2"); + + List deviceList = waterDevice.queryList(dataSource, null, null); + if(deviceList == null){ + return; + } + if(deviceList.isEmpty()){ + return; + } + int listMax = deviceList.size()-1; + int listPos = (int)(Math.random()*listMax); + SensorDeviceEntity tgtDevice = (SensorDeviceEntity)deviceList.get(listPos); + WaterFlowInfoEntity waterFlowInfo = new WaterFlowInfoEntity(); + long randomFlow = (long)(Math.random()*400 + 50); + waterFlowInfo.setFlow(randomFlow); + waterFlowInfo.setTimestamp(new Date()); + waterFlowInfo.setWaterDeviceId(tgtDevice.getDeviceid()); + waterFlowInfo.setStation(tgtDevice.getOwner()); + waterFlowInfo.setBrigade(tgtDevice.getBrigade()); + waterFlowInfo.setBorough(tgtDevice.getBorough()); + waterFlowInfo.setDetachment(tgtDevice.getDetachment()); + addWaterFlowInfo(waterFlowInfo); + }catch (Exception e){ + System.out.println("addWaterFlowSimData live: fail = " + e.getMessage()); + } + } + public void addWaterFlowInfo(WaterFlowInfoEntity waterFlowInfo){ + + waterFlowInfo.setRecordId(waterFlowInfo.getWaterDeviceId() + waterFlowInfo.getTimestamp().getTime()); + waterFlowInfo.Insert(dataSource); + + Calendar signDayTime = Calendar.getInstance(); + String nYear = String.valueOf(signDayTime.get(Calendar.YEAR)); + String nMonth = String.valueOf(signDayTime.get(Calendar.MONTH)+1); + String nDay = String.valueOf(signDayTime.get(Calendar.DAY_OF_MONTH)); + String nHour = String.valueOf(signDayTime.get(Calendar.HOUR_OF_DAY)); + + WaterFlowHourEntity flowHour = new WaterFlowHourEntity(waterFlowInfo, nYear, nMonth, nDay,nHour); + WaterFlowHourEntity flowHourOld = (WaterFlowHourEntity)flowHour.QueryIt(dataSource); + if(flowHourOld == null){ + flowHour.Insert(dataSource); + }else{ + flowHourOld.setFlow(flowHourOld.getFlow() + flowHour.getFlow()); + flowHourOld.Update(dataSource); + } + + WaterFlowDayEntity flowDay = new WaterFlowDayEntity(waterFlowInfo, nYear, nMonth, nDay); + WaterFlowDayEntity flowDayOld = (WaterFlowDayEntity)flowDay.QueryIt(dataSource); + if(flowDayOld == null){ + flowDay.Insert(dataSource); + }else{ + flowDayOld.setFlow(flowDayOld.getFlow() + flowDay.getFlow()); + flowDayOld.Update(dataSource); + } + + WaterFlowMonthEntity flowMonth = new WaterFlowMonthEntity(waterFlowInfo, nYear, nMonth); + WaterFlowMonthEntity flowMonthOld = (WaterFlowMonthEntity)flowMonth.QueryIt(dataSource); + if(flowMonthOld == null){ + flowMonth.Insert(dataSource); + }else{ + flowMonthOld.setFlow(flowMonthOld.getFlow() + flowMonth.getFlow()); + flowMonthOld.Update(dataSource); + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/StationServices.java b/src/main/java/com/jingyi/iotserver/firestationport/services/StationServices.java new file mode 100644 index 0000000..1e365ca --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/StationServices.java @@ -0,0 +1,916 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.clientmanage.model.BoroughEntity; +import com.jingyi.iotserver.clientmanage.model.BrigadeEntity; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; + +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; + +import com.jingyi.iotserver.firestationport.model.complexquery.CountInfo; +import com.jingyi.iotserver.firestationport.model.complexquery.TimeCountInfo; +import com.jingyi.iotserver.firestationport.model.equipment.FireCtrlInfoDescriptEntity; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentEntity; +import com.jingyi.iotserver.firestationport.model.equipment.FireStationEquipmentInfoEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallAckEntity; +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallEntity; +import com.jingyi.iotserver.firestationport.model.station.*; +import com.jingyi.iotserver.firestationport.model.todev.NoticeEntity; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.services.station.StationRuningInfo; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.StationAlarmNotify; +import com.jingyi.iotserver.firestationport.websocket.message.StationAlarmProcessNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +@Service +public class StationServices { + + @Autowired + private DataSource dataSource; + + @Autowired + private DatabaseDesInfoService databaseDesInfoService; +// private JsonNode pro; + + @Autowired + private EnvConfigService envConfigService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private MessagePublisher messagePublisher; + + private String getStationScopeCondition(List list){ + String condition = null; + if(list!=null&&list.size()>0){ + for(FireStationBaseInfoEntity info : list){ + if(info!=null){ + + String subcon = null; + String brigade = info.getBrigade(); + if(brigade!=null&&brigade.length()>0){ + if(subcon==null) { + subcon = " (brigade='" + brigade + "' "; + }else{ + subcon += " AND brigade='" + brigade + "' "; + } + } + + String borough = info.getBorough(); + if(borough!=null&&borough.length()>0){ + if(subcon==null) { + subcon = " (borough='" + borough + "' "; + }else{ + subcon += " AND borough='" + borough + "' "; + } + } + + String detachment = info.getDetachment(); + if(detachment!=null&&detachment.length()>0){ + if(subcon==null) { + subcon = " (detachment='" + detachment + "' "; + }else{ + subcon += " AND detachment='" + detachment + "' "; + } + } + + String name = info.getName(); + if(name!=null&&name.length()>0){ + if (condition == null) { + condition = "WHERE name='" + name + "'"; + } else { + condition += " AND name='" + name + "'"; + } + } + + if(subcon!=null) { + subcon += ") "; + if(condition==null) { + condition = subcon; + }else{ + condition += " OR "+subcon; + } + + } + } + } + } + return condition; + } + + public int queryStationCountByScope(List scopelist) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + String condition = getStationScopeCondition(scopelist); + if(condition==null) + return SQLTools.ExecuteQueryCount(dataSource, info.tableName(), null); + + return SQLTools.ExecuteQueryCount(dataSource, info.tableName(), condition); + } + + public List queryStationListByScope(List scopelist, int pagesize, int pageindex) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + String condition = getStationScopeCondition(scopelist); + if (condition != null) + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName() + + " WHERE " + condition, pageindex, pagesize, "number"); + else + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName() + , pageindex, pagesize, "number"); + } + + public int queryStationCount(FireStationBaseInfoEntity station) { + if (station == null) + station = new FireStationBaseInfoEntity(); + return station.queryCount(dataSource,null,null); + } + + public List queryStationList(FireStationBaseInfoEntity station, int pagesize, int pageindex) { + if (station == null) + station = new FireStationBaseInfoEntity(); + return station.queryPage(dataSource,null,null,pageindex,pagesize); + } + + public List queryAllStationList( int pagesize, int pageindex) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName(), pageindex, pagesize, "number"); + } + + public List queryAllStationListByIndustry( int pagesize, int pageindex, String sIndustry) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName() +" WHERE industry='" + sIndustry + "'", pageindex, pagesize, "number"); + } + + public List queryAllBoroughList(int pagesize, int pageindex) { + BoroughEntity info = new BoroughEntity(); + return SQLTools.queryPage(dataSource, BoroughEntity.class, "SELECT * FROM " + info.tableName(), pageindex, pagesize, "borough"); + } + + public List queryAllBrigadeList(int pagesize, int pageindex) { + BrigadeEntity info = new BrigadeEntity(); + return SQLTools.queryPage(dataSource, BrigadeEntity.class, "SELECT * FROM " + info.tableName(), pageindex, pagesize, "brigade"); + } + + public List queryStationListOnCreateTime(FireStationBaseInfoEntity station, int pagesize, int pageindex) { + FireStationBaseInfoEntity info = new FireStationBaseInfoEntity(); + if (station == null) + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName() + , pageindex, pagesize, "number"); + String condition = null; + String brigade = station.getBrigade(); + String borough = station.getBorough(); + String detachment = station.getDetachment(); + String name = station.getName(); + String orgname = station.getOrgname(); + Date createtime = station.getCreatetime(); + if (brigade != null && brigade.length() > 0) { + condition = "WHERE brigade='" + brigade + "'"; + } + + if (borough != null && borough.length() > 0) { + if (condition == null) { + condition = "WHERE borough='" + borough + "'"; + } else { + condition += " AND borough='" + borough + "'"; + } + } + + if (detachment != null && detachment.length() > 0) { + if (condition == null) { + condition = "WHERE detachment='" + detachment + "'"; + } else { + condition += " AND detachment='" + detachment + "'"; + } + } + + if(name!=null&&name.length()>0){ + if (condition == null) { + condition = "WHERE name='" + name + "'"; + } else { + condition += " AND name='" + name + "'"; + } + } + + if (orgname != null && orgname.length() > 0) { + if (condition == null) { + condition = "WHERE orgname='" + orgname + "'"; + } else { + condition += " AND orgname='" + orgname + "'"; + } + } + if(createtime!=null){ + if (condition == null) { + condition = "WHERE createtime<='" + SQLTools.formatDate(createtime) + "'"; + } else { + condition += " AND createtime<='" + SQLTools.formatDate(createtime) + "'"; + } + } + if (condition != null) + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName() + + " " + condition, pageindex, pagesize, "number"); + else + return SQLTools.queryPage(dataSource, FireStationBaseInfoEntity.class, "SELECT * FROM " + info.tableName() + , pageindex, pagesize, "number"); + } + + public boolean deleteStation(FireStationBaseInfoEntity station) { + boolean rel = false; + try { + fireStationLiveManager.removeStation(station.getName()); + station.Delete(dataSource); + rel = true; + } catch (Exception e) { + + } + return rel; + } + + public List queryStationEquipment(FireStationBaseInfoEntity station) { + if (station == null) + return null; + List list = new ArrayList(); + if (station != null) { + FireStationEquipmentEntity eq = new FireStationEquipmentEntity(); + eq.extendName(""+station.getNumber()); + List equips = eq.queryList(dataSource,null,null); + if (equips != null) { + for (SQLDataObject ob : equips) { + if (ob != null) { + FireStationEquipmentEntity equip = (FireStationEquipmentEntity)ob; + FireCtrlInfoDescriptEntity des = databaseDesInfoService.getDBInfoDescript(equip.getInfo_number()); + if (des != null) { + FireStationEquipmentInfoEntity info = new FireStationEquipmentInfoEntity(); + info.setCount(equip.getCount()); + info.setTitle(des.getTitle()); + info.setName(des.getDescript()); + list.add(info); + // System.out.println(des.getDescript()); + } + } + } + } + } + return list; + } + + public List queryStationEquipmentByName(String stationname) { + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + return queryStationEquipment(station); + } + + public List queryStationEquipmentByDeviceID(String devid) { + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.QueryByDeviceID(dataSource,devid); + return queryStationEquipment(station); + } + + public boolean updateStationEquipment(FireStationBaseInfoEntity station, String equipmentstr) { + + + + Map list = parseEquipmentInof(equipmentstr); + if (list == null || list.size() <= 0) + return false; + FireStationEquipmentEntity equ = new FireStationEquipmentEntity(); + equ.extendName(""+station.getNumber()); + List old = equ.queryList(dataSource,null,null); + if (old != null && old.size() > 0) { + for (SQLDataObject ob : old) { + FireStationEquipmentEntity eq = (FireStationEquipmentEntity)ob; + if (eq != null) { + FireStationEquipmentEntity neweq = list.remove(eq.getInfo_number()); + if (neweq != null && neweq.getCount() != eq.getCount()) { + neweq.extendName(""+station.getNumber()); + neweq.Update(dataSource); + } + } + } + } + + for (Integer index : list.keySet()) { + FireStationEquipmentEntity eq = list.get(index); + if (eq != null) { + eq.extendName(""+station.getNumber()); + eq.Insert(dataSource); + } + } + return true; + } + + public boolean updateStationEquipment(FireStationBaseInfoEntity station, Map list) { + + FireStationEquipmentEntity equ = new FireStationEquipmentEntity(); + equ.extendName(""+station.getNumber()); + List old = equ.queryList(dataSource,null,null); + if (old != null && old.size() > 0) { + for (SQLDataObject ob : old) { + FireStationEquipmentEntity eq = (FireStationEquipmentEntity)ob; + if (eq != null) { + FireStationEquipmentEntity neweq = list.remove(eq.getInfo_number()); + if (neweq != null && neweq.getCount() != eq.getCount()) { + neweq.extendName(""+station.getNumber()); + neweq.Update(dataSource); + } + } + } + } + + for (Integer index : list.keySet()) { + FireStationEquipmentEntity eq = list.get(index); + if (eq != null) { + eq.extendName(""+station.getNumber()); + eq.Insert(dataSource); + } + } + + return true; + } + + private Map parseEquipmentInof(String equips) { + ObjectMapper mapper = new ObjectMapper(); + try { + + JsonNode rootnode = mapper.readTree(equips); + if (rootnode == null) + return null; + Map equipments = new HashMap(); + Iterator> iterator = rootnode.fields(); + while (iterator.hasNext()) { + Map.Entry property = iterator.next(); + String title = property.getKey(); + if (title != null) { + JsonNode pro = property.getValue(); + if (pro != null && pro.isInt()) { + int index = databaseDesInfoService.getDBInfoDescriptIndex("equipment", title); + if (index <= 0) + continue; + if (databaseDesInfoService.getEquipmentDescript(index) != null) { + FireStationEquipmentEntity equip = new FireStationEquipmentEntity(); + equip.setInfo_number(index); + equip.setCount(pro.asInt()); + equip.setType(1); + equipments.put(equip.getInfo_number(), equip); + } + } + } + } + + return equipments; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public boolean updateStationStaff(FireStationStaffInfoEntity staff) { + if(staff!=null) + return staff.Update(dataSource); + return false; + } + + public RespEntity addStationStaff(FireStationStaffInfoEntity staff) { + + if (FireStationStaffInfoEntity.Query(dataSource,staff.getStationName(),staff.getStaffid()) != null) + return new RespEntity(RespCode.EXIST); + + if(staff.Insert(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } + + + public RespEntity deleteStationStaff(FireStationStaffInfoEntity staff) { + + if (FireStationStaffInfoEntity.Query(dataSource,staff.getStationName(),staff.getStaffid()) == null) + return new RespEntity(RespCode.NOTEXIST); + + if(staff.Delete(dataSource)) + return new RespEntity(RespCode.SUCCESS); + else + return new RespEntity(RespCode.FAIL); + } + + + + + public RespEntity queryStationOnlineTime(FireStationBaseInfoEntity station, Date start, Date end) { + long seconds = 0; + int count = 0; + int index = 0; + String startstr = SQLTools.formatDate(start); + String endstr = SQLTools.formatDate(end); + List stationlist = null; + do{ + stationlist = queryStationList(station,1000,index); + + if (stationlist == null) + break; + for(SQLDataObject ob:stationlist) { + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + List list = null; + try{ + FireStationLineEntity ln = new FireStationLineEntity(); + ln.extendName(""+s.getNumber()); + list = ln.queryPage(dataSource, startstr, endstr,0,1000); + }catch (Exception e){ + + } + count ++; + if (list == null || list.size() <= 0) + continue; + + long sl = start.getTime(); + long el = end.getTime(); + for (SQLDataObject li : list) { + FireStationLineEntity line = (FireStationLineEntity) li; + if (line != null && line.getOnline() != null && line.getOffline() != null) { + long onl = line.getOnline().getTime(); + long offl = line.getOffline().getTime(); + if (sl > onl) + onl = sl; + if (offl > el) + offl = el; + seconds += (offl - onl) / 1000; + } + } + } + index++; + }while(stationlist!=null&&stationlist.size()>=1000); + String data = "{\"seconds\":" + seconds + ",\"total\":" + ((end.getTime() - start.getTime()) / 1000*count) +",\"count\":"+count+ "}"; + return new RespEntity(RespCode.SUCCESS, data); + } + + public TimeCountInfo queryStationOnlineTimeCountInfo(FireStationBaseInfoEntity station, Date start, Date end) { + long seconds = 0; + int count = 0; + int index = 0; + TimeCountInfo tcount = new TimeCountInfo(); + List stationlist = null; + do{ + stationlist = queryStationList(station,1000,index); + + if (stationlist == null) + break; + for(SQLDataObject ob:stationlist) { + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + List list = new ArrayList(); + try{ + FireStationLineEntity line = new FireStationLineEntity(); + line.extendName(""+s.getNumber()); + line.setStation_name(s.getName()); + int i=0; + List tmp = null; + do { + tmp = line.queryPage(dataSource, SQLTools.formatDate(start), SQLTools.formatDate(end), i, 1000); + i++; + list.addAll(tmp); + }while(tmp!=null&&tmp.size()>=1000); + }catch (Exception e){ +// e.printStackTrace(); + } + count ++; + if (list == null || list.size() <= 0) + continue; + + long sl = start.getTime(); + long el = end.getTime(); + for (SQLDataObject li : list) { + FireStationLineEntity line = (FireStationLineEntity)li; + if (line != null && line.getOnline() != null && line.getOffline() != null) { + long onl = line.getOnline().getTime(); + long offl = line.getOffline().getTime(); + if (sl > onl) + onl = sl; + if (offl > el) + offl = el; + seconds += (offl - onl) / 1000; + } + } + } + index++; + }while(stationlist!=null&&stationlist.size()>=1000); + tcount.seconds = (int)seconds; + tcount.total = (int)((end.getTime() - start.getTime()) / 1000*count); + + return tcount; + } + + public RespEntity queryStationOnSignTime(FireStationBaseInfoEntity station, Date start, Date end) { + long seconds = 0; + int count = 0; + int index = 0; + List stationlist = null; + do{ + stationlist = queryStationList(station,1000,index); + + if (stationlist == null) + break; + for(SQLDataObject ob:stationlist) { + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + count++; + List list = null; + try { + FireStationSignEntity sign = new FireStationSignEntity(); + sign.extendName(""+ s.getNumber()); + list = sign.queryList(dataSource, SQLTools.formatDate(start), SQLTools.formatDate(end)); + }catch (Exception e){ + + } + if (list == null || list.size() <= 0) + continue; + long sl = start.getTime(); + long el = end.getTime(); + for (SQLDataObject sob : list) { + FireStationSignEntity sign = (FireStationSignEntity)sob; + if (sign != null && sign.getSignin() != null && sign.getSignout() != null) { + long onl = sign.getSignin().getTime(); + long offl = sign.getSignout().getTime(); + if (sl > onl) + onl = sl; + if (offl > el) + offl = el; + seconds += (offl - onl) / 1000; + } + } + } + index++; + }while(stationlist!=null&&stationlist.size()>=1000); + String data = "{\"seconds\":" + seconds + ",\"total\":" + ((end.getTime() - start.getTime()) / 1000*count) +",\"count\":"+count+ "}"; + return new RespEntity(RespCode.SUCCESS, data); + } + + public TimeCountInfo queryStationOnSignTimeCountInfo(FireStationBaseInfoEntity station, Date start, Date end) { + long seconds = 0; + int count = 0; + int index = 0; + TimeCountInfo tcount = new TimeCountInfo(); + List stationlist = null; + do{ + stationlist = queryStationList(station,1000,index); + + if (stationlist == null) + break; + for(SQLDataObject ob:stationlist) { + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + count++; + List list = new ArrayList(); + List tmp = null; + try { + int i=0; + FireStationSignEntity sign = new FireStationSignEntity(); + sign.setStation_name(s.getName()); + sign.extendName(""+s.getNumber()); + do { + list = sign.queryPage(dataSource, SQLTools.formatDate(start), SQLTools.formatDate(end),i,1000); + }while(tmp!=null&&tmp.size()>=1000); + }catch (Exception e){ + + } + if (list == null || list.size() <= 0) + continue; + long sl = start.getTime(); + long el = end.getTime(); + for (SQLDataObject sob : list) { + FireStationSignEntity sign = (FireStationSignEntity)sob; + if (sign != null && sign.getSignin() != null && sign.getSignout() != null) { + long onl = sign.getSignin().getTime(); + long offl = sign.getSignout().getTime(); + if (sl > onl) + onl = sl; + if (offl > el) + offl = el; + seconds += (offl - onl) / 1000; + } + } + } + index++; + }while(stationlist!=null&&stationlist.size()>=1000); + tcount.seconds = (int)seconds; + tcount.total = (int)((end.getTime() - start.getTime()) / 1000*count); + return tcount; + } + + public RespEntity queryStationOnSignTime(String name, Date start, Date end) { + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,name); + if (station == null) + return new RespEntity(RespCode.NOTEXIST); + FireStationSignEntity sig = new FireStationSignEntity(); + sig.extendName(""+station.getNumber()); + List list = sig.queryList(dataSource, SQLTools.formatDate(start), SQLTools.formatDate(end)); + if (list == null || list.size() <= 0) + return new RespEntity(RespCode.EMPTY); + long seconds = 0; + long sl = start.getTime(); + long el = end.getTime(); + for (SQLDataObject ob : list) { + FireStationSignEntity sign = (FireStationSignEntity)ob; + if (sign != null && sign.getSignin() != null && sign.getSignout() != null) { + long onl = sign.getSignin().getTime(); + long offl = sign.getSignout().getTime(); + if (sl > onl) + onl = sl; + if (offl > el) + offl = el; + seconds += (offl - onl) / 1000; + } + } + + String data = "{\"seconds\":" + seconds + ",\"total\":" + ((end.getTime() - start.getTime()) / 1000) + "}"; + return new RespEntity(RespCode.SUCCESS, data); + } + + + public CountInfo queryStationCountOntime(FireStationBaseInfoEntity station, Date time) { + + int index = 0; + CountInfo tcount = new CountInfo(); + List stationlist = null; + do{ + station.setCreatetime(time); + stationlist = queryStationListOnCreateTime(station,1000,index); + + if (stationlist == null) + break; + tcount.total += stationlist.size(); + for(FireStationBaseInfoEntity s:stationlist) { + try{ + FireStationLineEntity line = new FireStationLineEntity(); + if(FireStationLineEntity.IsOnline(dataSource,s.getNumber(),time)) { + tcount.count++; + }else{ + StationRuningInfo info = fireStationLiveManager.getStationInfo(s.getName()); + if(info!=null&&info.lineState){ + if(time.getTime()>info.lastActiveTime) + tcount.count++; + } + } + }catch (Exception e){ + + } + + } + index++; + }while(stationlist!=null&&stationlist.size()>=1000); + + + return tcount; + } + + public void addRollCallAck(FireStationRollCallAckEntity ack) { + try { + if(ack.QueryIt(dataSource)==null) + ack.Insert(dataSource); + else + ack.Update(dataSource); + if(ack!=null&&ack.getState()!=null&&ack.getState().equals("ignore")){ + NoticeEntity notice = new NoticeEntity(); + notice.setNoticeid(""+System.currentTimeMillis()); + notice.setTitle("点名未响应!"); + notice.setContent("点名未响应:"+ack.getRollcallnumber()); + notice.setTimestamp(new Date()); + notice.setSender("system"); + + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", ack.getStationname(), "notify", content, 0); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("notify"); + msg.setData(content); + msg.setTitle("notify"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(ack.getStationname(),str); + } + + } catch (Exception e) { + + } + } + + public RespEntity addRollCall(FireStationRollCallEntity rollcall) { + RespEntity rel = null; + try { + String number = rollcall.getNumber(); + if (number == null || number.length() <= 0) + return new RespEntity(RespCode.ERROR_REQUEST); + FireStationRollCallEntity roll = (FireStationRollCallEntity)rollcall.QueryIt(dataSource); + if (roll != null) { + return new RespEntity(RespCode.EXIST); + } + + rollcall.Insert(dataSource); + SendRollCall(rollcall); + rel = new RespEntity(RespCode.SUCCESS); + } catch (Exception e) { + rel = new RespEntity(RespCode.FAIL); + } + return rel; + } + + public void SendRollCall(FireStationRollCallEntity rollcall){ + try{ + String callstr = "{\"number\":\""+rollcall.getNumber()+"\",\"sender\":\""+rollcall.getUsername()+"\",\"starttime\":\""+SQLTools.formatDate(rollcall.getStarttime())+"\"}"; + + List list = ( List)SQLTools.getEntityListFromJson(rollcall.getScope(),OrganiztionUri.class); + if(list==null) + return ; + ConcurrentHashMap receiverlist = new ConcurrentHashMap(); + for(OrganiztionUri org:list){ + if(org!=null){ + String group = null; + String station = null; + if(org.getStation()!=null) { + station = org.getStation(); + }else if(org.getDetachment()!=null){ + group = org.getDetachment(); + }else if(org.getBorough()!=null){ + group = org.getBorough(); + }else if(org.getBrigade()!=null){ + group = org.getBrigade(); + } + try { + MessageToStation msg = new MessageToStation(); + msg.setMessage("rollcall"); + msg.setData(callstr); + msg.setTitle("rollcall"); + String str = JsonHelper.convertObjectToStr(msg); + + if(station!=null) { + JpushClientUtil.sendMessageToDevice("firectrl", station, "rollcall", callstr, 0); + messagePublisher.sendMessage( station,str); + // FireStationBaseInfoEntity ss = FireStationBaseInfoEntity.Query(dataSource,station); + // if(ss!=null) + // receiverlist.put(ss.getName(),ss.getName()); + }else if (group != null) { + JpushClientUtil.sendMessageToGroup("firectrl", group, "rollcall", callstr, 0); + messagePublisher.sendMessage( group,str); + /* int count = queryStationCount(s); + for(int i=0;i<(count-1)/500;i++){ + Listreceivcer = queryStationList(s,500,i); + for(FireStationBaseInfoEntity ss:receivcer){ + receiverlist.put(ss.getName(),ss.getName()); + } + }*/ + } + + + }catch (Exception e){ + + } + } + } + /* + if(receiverlist.size()>0) { + RollCallMonitor rollCallMonitor = new RollCallMonitor(); + rollCallMonitor.setNumber(rollcall.getNumber()); + rollCallMonitor.setTimestamp(System.currentTimeMillis()); + rollCallMonitor.setStationTable(receiverlist); + fireStationLiveManager.addRollCallMonitor(rollCallMonitor); + } + */ + }catch (Exception e){ + } + } + + + public int queryRollCallCount(FireStationRollCallEntity rollcall, String start, String end) { + String condition = null; + + if (rollcall == null) { + rollcall = new FireStationRollCallEntity(); + } + + return rollcall.queryCount(dataSource,start,end); + } + + + public List queryRollCallList(FireStationRollCallEntity rollcall, String start, String end, int pagesize, int pageindex) { + + if (rollcall == null) + rollcall = new FireStationRollCallEntity(); + + return rollcall.queryPage(dataSource,start,end,pageindex,pagesize); + } + + + public int queryRollCallAckCount(FireStationRollCallAckEntity rollcallack, String start, String end) { + String condition = null; + if (start != null) { + condition = " acktime>='" + start + "'"; + } + if (end != null) { + if (condition != null) + condition += " AND acktime<='" + end + "'"; + else + condition = " acktime<='" + end + "'"; + } + + if (rollcallack == null) { + rollcallack = new FireStationRollCallAckEntity(); + } + + return rollcallack.queryCount(dataSource,start,end); + } + + + public List queryRollCallAckList(FireStationRollCallAckEntity rollcallack, String start, String end, int pagesize, int pageindex) { + + if (rollcallack == null) + rollcallack = new FireStationRollCallAckEntity(); + + return rollcallack.queryPage(dataSource,start,end,pageindex,pagesize); + } + + public boolean addStationAlarm(FireStationAlarmEntity alarm){ + if(!alarm.Insert(dataSource)) + return false; + //push alarm to web client + StationAlarmNotify notify = new StationAlarmNotify(); + notify.setAddress(alarm.getAddress()); + notify.setAlarmid(alarm.getAlarmid()); + notify.setLatitude(alarm.getLatitude()); + notify.setLongitude(alarm.getLongitude()); + notify.setTimestamp(alarm.getTimestamp()); + notify.setStation(alarm.getStation()); + notify.setSender(alarm.getSender()); + notify.setPhone(alarm.getPhone()); + notify.setType(alarm.getType()); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(alarm.getStation()); + pro.setBrigade(alarm.getBrigade()); + pro.setBorough(alarm.getBorough()); + pro.setDetachment(alarm.getDetachment()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + + fireStationLiveManager.setStationAlarm(alarm.getStation()); + //send alarm to notifytarget + String content = JsonHelper.convertObjectToStr(notify); + if(content!=null) + { + JpushClientUtil.sendMessageToGroup("firectrl",alarm.getNotifytarget(),"alart",content,0); + MessageToStation msg = new MessageToStation(); + msg.setMessage("alart"); + msg.setData(content); + msg.setTitle("alart"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( alarm.getNotifytarget(),str); + } + return true; + } + + public boolean processStationAlarm(FireStationAlarmEntity alarm,String processor){ + fireStationLiveManager.rmStationAlarm(alarm.getStation()); + + + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,alarm.getStation()); + if(station!=null) { + StationAlarmProcessNotify notify = new StationAlarmProcessNotify(); + notify.setAlarmid(alarm.getAlarmid()); + notify.setStation(alarm.getStation()); + notify.setTimestamp(new Date()); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(station.getName()); + pro.setBrigade(station.getBrigade()); + pro.setBorough(station.getBorough()); + pro.setDetachment(station.getDetachment()); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + NoticeEntity notice = new NoticeEntity(); + notice.setNoticeid(""+System.currentTimeMillis()); + notice.setTitle("报警已处理"); + notice.setContent("报警已被处理!"); + notice.setTimestamp(new Date()); + notice.setSender(processor); + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", alarm.getStation(), "notify", content, 0); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("notify"); + msg.setData(content); + msg.setTitle("notify"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage( alarm.getStation(),str); + + return true; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/TimingJobManager.java b/src/main/java/com/jingyi/iotserver/firestationport/services/TimingJobManager.java new file mode 100644 index 0000000..7868454 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/TimingJobManager.java @@ -0,0 +1,155 @@ +package com.jingyi.iotserver.firestationport.services; + +import com.jingyi.iotserver.firestationport.model.rollcall.FireStationRollCallEntity; +import com.jingyi.iotserver.firestationport.model.todev.TimingJobEntity; +import com.jingyi.iotserver.utils.SQLDataObject; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.*; + +@Service +public class TimingJobManager { + @Autowired + private DataSource dataSource; + + + @Autowired + private StationServices stationServices; + + private boolean blInited = false; + private Object locker = new Object(); + private HashMap mJobsMap = new HashMap(); + private Thread scanservice = null; + public void Init(){ + if(blInited) + return; + blInited = true; + + TimingJobEntity jb= new TimingJobEntity(); + jb.setStatus("active"); + List jobs = jb.queryList(dataSource,null,null); + if(jobs!=null) { + for (SQLDataObject ob : jobs) { + TimingJobEntity job = (TimingJobEntity) ob; + if (job != null) { + mJobsMap.put(job.getNumber(), job); + } + } + } + scanservice = new Thread(){ + public void run(){ + while(true){ + try { + ScanJob(); + }catch (Exception e){ + + } + try{ + Thread.sleep(1000); + }catch (Exception e){ + + } + } + } + }; + + scanservice.start(); + + } + + private void ScanJob(){ + long curtime = System.currentTimeMillis(); + synchronized (locker) { + ArrayList remote = new ArrayList(); + for(Map.Entry entry: mJobsMap.entrySet()){ + TimingJobEntity job = entry.getValue(); + if(job!=null){ + long timing = job.getTriggertime().getTime(); + if(curtime>=timing) + { + ExeJob(job); + remote.add(job); + } + } + } + + TimingJobEntity del = new TimingJobEntity(); + for(TimingJobEntity job:remote){ + if(job!=null){ + mJobsMap.remove(job.getNumber()); + del.setNumber(job.getNumber()); + del.setStatus("done"); + del.Update(dataSource); + } + } + + } + } + + public boolean AddJob(TimingJobEntity job){ + if(job==null) + return false; + if(job.getNumber()==null||job.getTriggertime()==null) + return false; + if(TimingJobEntity.QueryTimingJob(dataSource,job.getNumber())!=null) + return false; + + synchronized (locker) { + if (mJobsMap.get(job.getNumber()) != null) + return false; + job.setStatus("active"); + mJobsMap.put(job.getNumber(), job); + } + return job.Insert(dataSource); + } + + public boolean deleteJob(TimingJobEntity job){ + if(job==null) + return false; + if(job.getNumber()==null) + return false; + try { + job.Delete(dataSource); + }catch (Exception e){ + + } + synchronized (locker) { + if (mJobsMap.get(job.getNumber()) == null) + return false; + mJobsMap.remove(job.getNumber()); + } + return true; + } + + public List queryTimejobList(String username){ + try { + TimingJobEntity job = new TimingJobEntity(); + job.setUsername(username); + return job.queryList(dataSource,null,null); + }catch (Exception e){ + + } + return null; + } + + private void ExeJob(TimingJobEntity job){ + + long cuttime = System.currentTimeMillis(); + try { + + FireStationRollCallEntity rollcall = new FireStationRollCallEntity(); + rollcall.setNumber(""+cuttime); + rollcall.setScope(job.getScope()); + rollcall.setStarttime(new Date()); + rollcall.setUsername(job.getUsername()); + stationServices.addRollCall(rollcall); + + }catch (Exception e){ + + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/analyze/StatisticsMessage.java b/src/main/java/com/jingyi/iotserver/firestationport/services/analyze/StatisticsMessage.java new file mode 100644 index 0000000..930b1c0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/analyze/StatisticsMessage.java @@ -0,0 +1,87 @@ +package com.jingyi.iotserver.firestationport.services.analyze; + +public class StatisticsMessage { + + public static final String All_Summary_Code = "all.summary"; + public static final String School_Day_Summary_Code = "station.day.summary"; + public static final String School_Month_Summary_Code = "station.month.summary"; + public static final String Borough_Day_Summary_Code = "borough.day.summary"; + public static final String Borough_Month_Summary_Code = "borough.month.summary"; + + public static final String School_Volunteer_Sign = "school.sign.volunteer"; + public static final String School_Policeman_Sign = "school.sign.policeman"; + public static final String School_Guard_Sign = "school.sign.guard"; + public static final String School_Manager_Sign = "school.sign.manager"; + + private String code; + private String station; + private String detachment; + private String borough; + private String brigade; + private int year; + private int month; + private int day; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/eyeapp/SensorEventPusher.java b/src/main/java/com/jingyi/iotserver/firestationport/services/eyeapp/SensorEventPusher.java new file mode 100644 index 0000000..9385d79 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/eyeapp/SensorEventPusher.java @@ -0,0 +1,131 @@ +package com.jingyi.iotserver.firestationport.services.eyeapp; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.firestationport.websocket.message.EarthInductorBuzEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.SensorEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.SmokingBuzEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotify; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; + +@Service +public class SensorEventPusher { + private boolean blInited = false; + private Thread dispatcher = null; + + private HashMap mEventTypeDescriptMap = new HashMap(); + private ConcurrentHashMap> mEventListMap = new ConcurrentHashMap>(); + + public void init(){ + if(blInited) + return; + inittable(); + blInited = true; + dispatcher = new Thread(){ + public void run(){ + while(true){ + try { + DispatchEvent(); + }catch (Exception e){ + + } + try{ + Thread.sleep(3000); + + }catch (Exception e){ + + } + } + } + }; + + dispatcher.start(); + } + + private void inittable(){ + SensorEventTypeDescript type = new SensorEventTypeDescript(); + type.setMsgname("SmokingEvent"); + mEventTypeDescriptMap.put(SmokingBuzEventNotify.class.getName(),type); + type = new SensorEventTypeDescript(); + type.setMsgname("EarthInductorEvent"); + mEventTypeDescriptMap.put(EarthInductorBuzEventNotify.class.getName(),type); + + + ConcurrentLinkedQueue list = new ConcurrentLinkedQueue(); + mEventListMap.put(SmokingBuzEventNotify.class.getName(),list); + + list = new ConcurrentLinkedQueue(); + mEventListMap.put(EarthInductorBuzEventNotify.class.getName(),list); + } + + private void DispatchEvent(){ + for(Map.Entry> entry: mEventListMap.entrySet()) { + ConcurrentLinkedQueue queue = entry.getValue(); + + if (queue == null || queue.size() <= 0) + continue; + SensorEventTypeDescript des = mEventTypeDescriptMap.get(entry.getKey()); + if(des==null) + continue; + + HashMap> sendmap= new HashMap>(); + while(queue.size()>0){ + WebNotify notify = queue.poll(); + String houseowner = notify.obtainProperty().getNotifyflag(); + if(houseowner==null) + continue; + + ArrayList list = sendmap.get(houseowner); + if(list==null) { + list = new ArrayList(); + sendmap.put(houseowner, list); + } + list.add(notify); + } + + for(Map.Entry> notifyentry:sendmap.entrySet()){ + ArrayList list = notifyentry.getValue(); + String houseowner = notifyentry.getKey(); + if(list==null||list.size()<=0||houseowner==null||houseowner.length()<=0) + continue; + try{ + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(list); + JpushClientUtil.sendMessageToDevice("eye",houseowner,des.getMsgname(),json,0); + + try { + SmokingBuzEventNotify ny = (SmokingBuzEventNotify)list.get(0); + JpushClientUtil.sendMessageToGroup("gtalk",ny.getStation(),des.getMsgname(),json,0); + if(ny.getStatus().equals("stop")) + { + JpushClientUtil.sendNotifyToDevice("eye", houseowner, "智慧烟感", "警报解除!", 0); + JpushClientUtil.sendMessageToGroup("gtalk",ny.getStation(),"智慧烟感", "警报解除!",0); + } + else + { + JpushClientUtil.sendNotifyToDevice("eye", houseowner, "智慧烟感", "收到新的警报!", 0); + JpushClientUtil.sendMessageToGroup("gtalk",ny.getStation(),"智慧烟感", "收到新的警报!",0); + } + }catch (Exception e){ + + } + }catch (Exception e){ + } + } + } + + } + + public void PushSensorEvent(WebNotify event){ + ConcurrentLinkedQueue list = mEventListMap.get(event.getClass().getName()); + if(list==null) + return; + list.add(event); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/eyeapp/SensorEventTypeDescript.java b/src/main/java/com/jingyi/iotserver/firestationport/services/eyeapp/SensorEventTypeDescript.java new file mode 100644 index 0000000..7710f3a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/eyeapp/SensorEventTypeDescript.java @@ -0,0 +1,13 @@ +package com.jingyi.iotserver.firestationport.services.eyeapp; + +public class SensorEventTypeDescript { + private String msgname; + + public void setMsgname(String msgname) { + this.msgname = msgname; + } + + public String getMsgname() { + return msgname; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/netease/CheckSumBuilder.java b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/CheckSumBuilder.java new file mode 100644 index 0000000..7e698c4 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/CheckSumBuilder.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.services.netease; + +import java.security.MessageDigest; + +public class CheckSumBuilder { + public static String getCheckSum(String appSecret, String nonce, String curTime) { + return encode("sha1", appSecret + nonce + curTime); + } + private static String encode(String algorithm, String value) { + if (value == null) { + return null; + } + try { + MessageDigest messageDigest = MessageDigest.getInstance(algorithm); + messageDigest.update(value.getBytes()); + return getFormattedText(messageDigest.digest()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private static String getFormattedText(byte[] bytes) { + int len = bytes.length; + StringBuilder buf = new StringBuilder(len * 2); + for (int j = 0; j < len; j++) { + buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]); + buf.append(HEX_DIGITS[bytes[j] & 0x0f]); + } + return buf.toString(); + } + private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseResp.java b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseResp.java new file mode 100644 index 0000000..e47168e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseResp.java @@ -0,0 +1,26 @@ +package com.jingyi.iotserver.firestationport.services.netease; + +public class NeteaseResp { + private int code; + private String msg; + public NeteaseResp(NeteaseRespCode respCode) { + this.code = respCode.getCode(); + this.msg = respCode.getMsg(); + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getMsg() { + return msg; + } + + public void setCode(int code) { + this.code = code; + } + + public int getCode() { + return code; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseRespCode.java b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseRespCode.java new file mode 100644 index 0000000..d8d500b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseRespCode.java @@ -0,0 +1,62 @@ +package com.jingyi.iotserver.firestationport.services.netease; + +public enum NeteaseRespCode { + SUCCESS(200, "操作成功"), + LOGIN_AUTHOR_FAIL(409,"用户登录认证失败"), + CREATE_CHANNEL_FAIL(604, "频道添加失败"), + USER_INFO_NOTEXIST(607,"用户信息不存在"), + CHANNEL_NAME_EMPTY(610,"频道名称为空"), + CHANNEL_NAME_EXIST(611,"频道名称已经存在"), + CHANNEL_TYPE_ERROR(612,"频道类型错误"), + CHECKSUM_EMPTY(613,"CheckSum为空"), + APP_KEY_EMPTY(614,"AppKey为空"), + CUR_TIME_EMPTY(615,"CurTime为空"), + NOT_IN_SERVICE(635,"服务未开通,请联系商务申请开通!"), + VISIT_TOO_OFTEN(638,"访问频率超限,每个应用对该接口限制为80次/秒。"), + UNKNOWN_ERROR(800,"未知错误"); + + private int code; + private String msg; + + NeteaseRespCode(int code, String msg) { + this.msg = msg; + this.code = code; + } + + public int getCode() { + return code; + } + public String getMsg() { + return msg; + } + + public static NeteaseRespCode getRespCode(int code){ + switch(code){ + case 200: + return SUCCESS; + case 409: + return LOGIN_AUTHOR_FAIL; + case 604: + return CREATE_CHANNEL_FAIL; + case 607: + return USER_INFO_NOTEXIST; + case 610: + return CHANNEL_NAME_EMPTY; + case 611: + return CHANNEL_NAME_EXIST; + case 612: + return CHANNEL_TYPE_ERROR; + case 613: + return CHECKSUM_EMPTY; + case 614: + return APP_KEY_EMPTY; + case 615: + return CUR_TIME_EMPTY; + case 635: + return NOT_IN_SERVICE; + case 638: + return VISIT_TOO_OFTEN; + } + return UNKNOWN_ERROR; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseVideoManager.java b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseVideoManager.java new file mode 100644 index 0000000..b6db8be --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseVideoManager.java @@ -0,0 +1,137 @@ +package com.jingyi.iotserver.firestationport.services.netease; + +import com.jingyi.iotserver.firestationport.model.station.FireStationVideoConfigEntity; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import org.apache.http.Consts; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Service +public class NeteaseVideoManager { + + @Autowired + private DataSource dataSource; + + @Autowired + private NeteaseVideoService neteaseVideoService; + + @Autowired + private FireStationLiveManager fireStationLiveManager; + + private boolean blInited = false; + private Thread scanThread = null; + private ConcurrentHashMap mStationsMap = new ConcurrentHashMap(); + public void Init(){ + if(blInited) + return; + blInited = true; + + scanThread = new Thread(){ + public void run(){ + while(true){ + try { + PerformTick(); + }catch (Exception e){ + e.printStackTrace(); + } + try{ + Thread.sleep(30*1000); + }catch (Exception e){ + + } + } + } + }; + + scanThread.start(); + } + + public void StationVideoStart(String name){ + StationVideoInfo info = mStationsMap.get(name); + + if(info==null){ + info = new StationVideoInfo(); + info.setStationname(name); + mStationsMap.put(name,info); + } + info.setLaststatetime(System.currentTimeMillis()); + info.setVideostate("start"); + } + + public void StationVideoStop(String name){ + StationVideoInfo info = mStationsMap.remove(name); + } + + private void PerformTick(){ + ArrayList rmlist = new ArrayList(); + for(Map.Entry entry: mStationsMap.entrySet()) { + StationVideoInfo info = entry.getValue(); + if (info != null) { + if(info.getCid()==null) { + + FireStationVideoConfigEntity vconfig = FireStationVideoConfigEntity.Query(dataSource,info.getStationname(), "netease"); + if(vconfig==null) + continue; + info.setCid(vconfig.getChannelID()); + } + + try{ + int status = neteaseVideoService.getVideoChannelStatus(info.getCid()); + if(status!=1&&status!=3){ + //close + rmlist.add(info.getStationname()); + }else { + //open + } + }catch (Exception e){ + + } + + } + } + + for(String name:rmlist){ + if(name!=null) + mStationsMap.remove(name); + } + + //notify + for(String station:rmlist){ + if(station!=null) { + // notifyWebpageVideoDrop(station); + fireStationLiveManager.setVideoState(station,"close"); + } + } + } + + private void notifyWebpageVideoDrop(String stationname){ + + DefaultHttpClient httpClient = new DefaultHttpClient(); + String url = "http://127.0.0.1/newStation/php/mfs.php";//http://127.0.0.1/newStation/php/mfs_station.php";//"http://127.0.0.1/newStation/php/mfs.php";// + long cuttime = System.currentTimeMillis(); + try { + HttpPost httpPost = new HttpPost(url); + + httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); + String str = "{\"UserName\":\"" + stationname+ "\",\"CID\":\"3017\"}"; + StringEntity params = new StringEntity(str, Consts.UTF_8); + httpPost.setEntity(params); + + HttpResponse response = httpClient.execute(httpPost); + int code = response.getStatusLine().getStatusCode(); + if(code!=200) + System.out.println("result:"+response.toString()); + }catch (Exception e){ + + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseVideoService.java b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseVideoService.java new file mode 100644 index 0000000..5773ce0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/netease/NeteaseVideoService.java @@ -0,0 +1,380 @@ +package com.jingyi.iotserver.firestationport.services.netease; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.common.service.EnvConfigService; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationVideoConfigEntity; +import com.jingyi.iotserver.utils.HttpTools; +import org.apache.http.Consts; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +//https://dev.yunxin.163.com/docs/product/直播/服务端API文档 + +@Service +public class NeteaseVideoService { + private String appKey = "4dab891379b0e76c6d2f1400a35d0ecc"; + private String appSecret = "52bdaca23dbb"; + + + @Autowired + private DataSource dataSource; + + @Autowired + private EnvConfigService envConfigService; + + + public RespEntity createVideoChannel(FireStationBaseInfoEntity station)throws IOException, ClientProtocolException { + + DefaultHttpClient httpClient = new DefaultHttpClient(); + String url = "https://vcloud.163.com/app/channel/create"; + HttpPost httpPost = new HttpPost(url); + + + String nonce = "52"; + String curTime = String.valueOf((new Date()).getTime() / 1000L); + String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码 + + // 设置请求的header + httpPost.addHeader("AppKey", appKey); + httpPost.addHeader("Nonce", nonce); + httpPost.addHeader("CurTime", curTime); + httpPost.addHeader("CheckSum", checkSum); + httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); + + // 设置请求的参数 + StringEntity params = new StringEntity("{\"name\":\""+station.getName()+"\", \"type\":0}", Consts.UTF_8); + httpPost.setEntity(params); + + // 执行请求 + HttpResponse response = httpClient.execute(httpPost); + String json = HttpTools.getBodyFromRespone(response); + + // 打印执行结果 + // System.out.println(EntityUtils.toString(response.getEntity(), "utf-8")); + + ObjectMapper mapper = new ObjectMapper(); + RespEntity rel=null; + try { + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null) + return new RespEntity(RespCode.FAIL, null); + JsonNode m = rootnode.findValue("code"); + if (m == null||!m.isInt()) + return new RespEntity(RespCode.FAIL, null); + int code = m.asInt(); + if (code==200) { + FireStationVideoConfigEntity videoentity = new FireStationVideoConfigEntity(); + videoentity.setStationName(station.getName()); + JsonNode ret = rootnode.findValue("ret"); + videoentity.setHttpAddress(ret.findValue("httpPullUrl").asText()); + videoentity.setHlsAddress(ret.findValue("hlsPullUrl").asText()); + videoentity.setRtmpAddress(ret.findValue("rtmpPullUrl").asText()); + videoentity.setPushAddress(ret.findValue("pushUrl").asText()); + videoentity.setChannelName(ret.findValue("name").asText()); + videoentity.setChannelID(ret.findValue("cid").asText()); + videoentity.setCreateTime(new Date(ret.findValue("ctime").asLong())); + videoentity.setPlatform("netease"); + if(FireStationVideoConfigEntity.Query(dataSource,videoentity.getStationName(),videoentity.getPlatform())!=null) + videoentity.Update(dataSource); + else + videoentity.Insert(dataSource); + rel = new RespEntity(RespCode.SUCCESS,videoentity); + + }else{ + rel = new RespEntity(RespCode.FAIL,new NeteaseResp(NeteaseRespCode.getRespCode(code))); + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + public RespEntity deleteVideoChannel(FireStationBaseInfoEntity station)throws IOException, ClientProtocolException { + + FireStationVideoConfigEntity vconfig = FireStationVideoConfigEntity.Query(dataSource,station.getName(),"netease"); + if(vconfig==null) + return new RespEntity(RespCode.NOTEXIST); + DefaultHttpClient httpClient = new DefaultHttpClient(); + String url = "https://vcloud.163.com/app/channel/delete"; + HttpPost httpPost = new HttpPost(url); + + + String nonce = "52"; + String curTime = String.valueOf((new Date()).getTime() / 1000L); + String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码 + + // 设置请求的header + httpPost.addHeader("AppKey", appKey); + httpPost.addHeader("Nonce", nonce); + httpPost.addHeader("CurTime", curTime); + httpPost.addHeader("CheckSum", checkSum); + httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); + + // 设置请求的参数 + StringEntity params = new StringEntity("{\"cid\":\""+vconfig.getChannelID()+"\"}", Consts.UTF_8); + httpPost.setEntity(params); + + // 执行请求 + HttpResponse response = httpClient.execute(httpPost); + String json = HttpTools.getBodyFromRespone(response); + + // 打印执行结果 + // System.out.println(EntityUtils.toString(response.getEntity(), "utf-8")); + + ObjectMapper mapper = new ObjectMapper(); + RespEntity rel=null; + try { + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null) + return new RespEntity(RespCode.FAIL, null); + JsonNode m = rootnode.findValue("code"); + if (m == null||!m.isInt()) + return new RespEntity(RespCode.FAIL, null); + int code = m.asInt(); + if (code==200) { + FireStationVideoConfigEntity videoConfigEntity = new FireStationVideoConfigEntity(); + videoConfigEntity.setStationName(station.getName()); + videoConfigEntity.setPlatform("netease"); + videoConfigEntity.Delete(dataSource); + rel = new RespEntity(RespCode.SUCCESS); + + }else{ + rel = new RespEntity(RespCode.FAIL,new NeteaseResp(NeteaseRespCode.getRespCode(code))); + } + }catch (Exception e){ + rel = new RespEntity(RespCode.EXCEPTION); + } + return rel; + } + + public void syncVideoConfigList(){ + int index = 0; + List list; + FireStationVideoConfigEntity.DeleteAll(dataSource); + while(true){ + try { + list = getVideoChannelList(index); + if(list==null) + break; + for(FireStationVideoConfigEntity info:list){ + try{ + updateChannelInfo(info); + }catch(Exception e){ + + } + } + }catch (Exception e){ + break; + } + + if(list==null||list.size()<50) + break; + index++; + } + } + + public List getVideoChannelList(int pageindex)throws IOException, ClientProtocolException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + String url = "https://vcloud.163.com/app/channellist"; + HttpPost httpPost = new HttpPost(url); + + + String nonce = "52"; + String curTime = String.valueOf((new Date()).getTime() / 1000L); + String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码 + + // 设置请求的header + httpPost.addHeader("AppKey", appKey); + httpPost.addHeader("Nonce", nonce); + httpPost.addHeader("CurTime", curTime); + httpPost.addHeader("CheckSum", checkSum); + httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); + + // 设置请求的参数 + StringEntity params = new StringEntity("{\"records\":"+50+",\"pnum\":"+pageindex+", \"ofield\":"+"\"ctime\""+",\"sort\":0}", Consts.UTF_8); + httpPost.setEntity(params); + + // 执行请求 + HttpResponse response = httpClient.execute(httpPost); + String json = HttpTools.getBodyFromRespone(response); + + ObjectMapper mapper = new ObjectMapper(); + RespEntity rel=null; + ArrayList cidlist= new ArrayList(); + try { + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null) + return null; + JsonNode m = rootnode.findValue("code"); + if (m == null||!m.isInt()) + return null; + int code = m.asInt(); + if (code==200) { + + JsonNode ret = rootnode.findValue("ret"); + if(ret==null) + return null; + JsonNode list = ret.findValue("list"); + if(list==null||!list.isArray()) + return null; + for(int i=0;i paramlist = new ArrayList(); + //paramlist.add(new ParameterPair("method","GET_BOXES")); + paramlist.add(new ParameterPair("client_id","O000006789")); + paramlist.add(new ParameterPair("access_token",accessToken)); + paramlist.add(new ParameterPair("timestamp",new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()))); + + Iterator iter = rootnode.fieldNames(); + while(iter.hasNext()){ + String name = iter.next(); + JsonNode node = rootnode.get(name); + if(node!=null){ + paramlist.add(new ParameterPair(name,node.asText())); + } + } + + Collections.sort(paramlist, new Comparator() { + @Override + public int compare(ParameterPair param1, ParameterPair param2) { + return param1.key.compareTo(param2.key); + } + }); + StringBuffer sbuilder = new StringBuffer(); + + for(ParameterPair p:paramlist){ + sbuilder.append(p.value); + } + sbuilder.append(appSecret); + paramlist.add(new ParameterPair("sign",MD5Tools.md5(sbuilder.toString()))); + + ObjectMapper mapper = new ObjectMapper(); + try { + ObjectNode node = mapper.createObjectNode(); + for(ParameterPair p:paramlist){ + JsonNode jnode = rootnode.get(p.key); + if(jnode!=null){ + if(jnode.isInt()) { + node.put(p.key, jnode.intValue()); + }else if(jnode.isFloat()){ + node.put(p.key,jnode.floatValue()); + }else if(jnode.isBigInteger()){ + node.put(p.key,jnode.longValue()); + }else if(jnode.isLong()){ + node.put(p.key,jnode.longValue()); + }else if(jnode.isBoolean()){ + node.put(p.key,jnode.booleanValue()); + }else if(jnode.isDouble()){ + node.put(p.key,jnode.doubleValue()); + }else + node.put(p.key, p.value); + }else + node.put(p.key, p.value); + } + + json = mapper.writeValueAsString(node); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + + try { + + URL uri = new URL("https://open.snd02.com:443/invoke/router.as"); + HttpURLConnection connection = (HttpURLConnection) uri.openConnection(); + + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(false); + connection.setConnectTimeout(1000 * 10); + connection.setReadTimeout(1000 * 10); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Charset", "UTF-8"); + // connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connection.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); + writer.write(json); + writer.close(); + + int responseCode = connection.getResponseCode(); + if(responseCode == HttpURLConnection.HTTP_OK){ + json = HttpTools.getBodyFromRespone(connection); + }else{ + mblLogined = false; + lastLoginTime = 0; + + } + rootnode = JsonHelper.parseBodyLevel1(json); + if(rootnode!=null) { + int code = JsonHelper.getIntValue(rootnode, "code"); + if(code!=0){ + mblLogined = false; + lastLoginTime = 0; + } + } + return json; + }catch (Exception e){ + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/DeShanAnService.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/DeShanAnService.java new file mode 100644 index 0000000..1634f2a --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/DeShanAnService.java @@ -0,0 +1,294 @@ +package com.jingyi.iotserver.firestationport.services.sensor; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.sensor.DeShangAnData; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmSummaryEntity; +import com.jingyi.iotserver.firestationport.model.sensor.pushalarm.PushAlarmPointEntity; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.services.sensor.deshanan.client.DeShanAnNettyClient; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.SensorEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLTools; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; + +import io.netty.buffer.Unpooled; +import io.netty.channel.*; + +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.DelimiterBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.util.CharsetUtil; + +import java.net.InetSocketAddress; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; + +@Service +public class DeShanAnService { + @Autowired + private DataSource dataSource; + @Autowired + private MessagePublisher messagePublisher; + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + @Autowired + private IoTCtrlServer ioTCtrlServer; + + private boolean blInited = false; + private Thread scanservice = null; + Bootstrap clientBootstrap = null; + + private String host; + private int port; + ConcurrentLinkedQueue mFrameDataQueue = new ConcurrentLinkedQueue(); + + private static final String EndFrame ="]"; + private static final String StartFrame ="["; + private String cacheFrame = ""; + DeShanAnNettyClient client = null; + + public void Init(){ + if(blInited) + return; + client = new DeShanAnNettyClient(); + blInited = true; + scanservice = new Thread(){ + public void run(){ + //startConnect(); + + client.connect(); + } + }; + scanservice.start(); + } + + public void startServer(){ + host = "218.76.54.20"; + port = 20000; + System.out.println("DeShanAnService startServer "+host); + Init(); + } + + private void startConnect(){ + EventLoopGroup group = new NioEventLoopGroup(); + //创建一个client 的bootstrap实例 + clientBootstrap = new Bootstrap(); + try { + clientBootstrap.group(group) + //指定使用一个NIO传输Channel + .channel(NioSocketChannel.class) + //设置远端服务器的host和端口 + .remoteAddress(new InetSocketAddress(host, port)) + .option(ChannelOption.TCP_NODELAY, true) + .handler(new ChannelInitializer() { + @Override + protected void initChannel(SocketChannel channel) { + + channel.pipeline().addLast(new DelimiterBasedFrameDecoder(1024, Unpooled.buffer().writeBytes("]".getBytes()))); + channel.pipeline().addLast(new StringDecoder(CharsetUtil.UTF_8)); + channel.pipeline().addLast(new SimpleChannelInboundHandler() { + + @Override + protected void channelRead0(ChannelHandlerContext channelHandlerContext, String msg) throws Exception { + if (StrUtil.containsAny(msg, "ConnectOK", "DataTest")) { + // System.out.println("DeShanAnService rec: "+msg); + return; + } + System.out.println("DeShanAnService rec: "+msg); + String newFrame = new String(msg); + parseFrame(newFrame); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + cause.printStackTrace(); + ctx.close(); + } + }); + + } + + }); + //连接到远端,一直等到连接完成 + System.out.println("DeShanAnService connect begin"); + ChannelFuture channelFuture = clientBootstrap.connect().sync(); + if (channelFuture.isSuccess()) { + System.out.println("DeShanAnService connect ok "+channelFuture.channel().id()); + //一直阻塞到channel关闭 + channelFuture.channel().closeFuture().sync(); + System.out.println("DeShanAnService disconnect "); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } finally { + //关闭group,释放所有的资源 + try { + group.shutdownGracefully().sync(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + public void parseFrame(String frameData){ + //删除前缀 + frameData = StrUtil.removePrefix(frameData, "[Data:"); + //删除后面多余的 + frameData = StrUtil.removeSuffix(frameData, "|"); + + List split = StrUtil.split(frameData, "|"); + if (CollUtil.size(split) < 6) + return; + DeShangAnData deShangAnData = new DeShangAnData(); + deShangAnData.setCallerId(split.get(0)); + deShangAnData.setAccount(split.get(1)); + deShangAnData.setSubsystem(split.get(2)); + deShangAnData.setDefenceAreaNumber(split.get(3)); + deShangAnData.setTime(split.get(4) + " " + split.get(5)); + // System.out.println("DeShanAnService parseFrameList: "+frameData); + + if(StrUtil.isEmptyOrUndefined(deShangAnData.getAccount()) || StrUtil.isEmptyOrUndefined(deShangAnData.getDefenceAreaNumber())){ + return; + } + + PushAlarmPointEntity alarmPoint = new PushAlarmPointEntity(); + alarmPoint.setPointId(deShangAnData.getAccount() + "_" + deShangAnData.getDefenceAreaNumber()); + + alarmPoint = (PushAlarmPointEntity)alarmPoint.QueryIt(dataSource); + if(alarmPoint == null){ + return; + } + if(FireCtrlSystemInit.netMode == 1){ + System.out.println("DeShanAnService translateHttp2Skynet: "); + ioTCtrlServer.translateHttp2Skynet(UDPAgentPackage.TYPE_Http_Agent, JSON.toJSONString(deShangAnData), "/iotserver/sensor/pushbutton/de_shang_an"); + } + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date timestamp = null; + try { + timestamp = format.parse(deShangAnData.getTime()); + } catch (Exception e) { + timestamp = new Date(); + } + + String eventId = alarmPoint.getPointId() + "_" + timestamp.getTime(); + + SensorAlarmEventEntity alarmEvent = new SensorAlarmEventEntity(); + alarmEvent.setEventId(eventId); + alarmEvent.setDeviceId(alarmPoint.getPointId()); + alarmEvent.setDevicetype(alarmPoint.getDeviceType()); + alarmEvent.setAlarmSource(alarmPoint.getDwmc()); + alarmEvent.setAddress(alarmPoint.getDwdz()); + alarmEvent.setLatitude(alarmPoint.getLatitude()); + alarmEvent.setLongitude(alarmPoint.getLongitude()); + alarmEvent.setSubAddress(alarmPoint.getPointAddress()); + alarmEvent.setStation(alarmPoint.getStation()); + alarmEvent.setDetachment(alarmPoint.getDetachment()); + alarmEvent.setBorough(alarmPoint.getBorough()); + alarmEvent.setBrigade(alarmPoint.getBrigade()); + alarmEvent.setTimestamp(timestamp); + alarmEvent.setAlarmType(SensorAlarmEventEntity.Alarm_Type_SOS_PushBotton); + alarmEvent.setAlarmCode("一键报警"); + alarmEvent.setState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setReadState(SensorAlarmEventEntity.STATE_NEW); + alarmEvent.setEventData(""); + alarmEvent.setAlarmTarget(alarmPoint.getPointName()); + + SensorAlarmEventEntity oldEvent = (SensorAlarmEventEntity)alarmEvent.QueryIt(dataSource); + if(oldEvent != null){ + //System.out.println("DeShanAnService id 重复: "+eventId); + return; + } + alarmEvent.Insert(dataSource); + System.out.println("DeShanAnService 新报警: "+ JSON.toJSONString(alarmPoint)); + + alarmEvent.setUser1Name(alarmPoint.getUserName()); + alarmEvent.setUser2Name(alarmPoint.getUser2Name()); + alarmEvent.setUser3Name(alarmPoint.getUser3Name()); + alarmEvent.setUser1Phone(alarmPoint.getUserPhone()); + alarmEvent.setUser2Phone(alarmPoint.getUser2Phone()); + alarmEvent.setUser3Phone(alarmPoint.getUser3Phone()); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(timestamp); //放入Date类型数据 + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH)+1; //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); + String strY = String.valueOf(year); + String strM = String.valueOf(month); + String strD = String.valueOf(day); + String strWeek = String.valueOf(weekIndex); + + String strDay = SQLTools.formatDay(timestamp); + + SensorAlarmSummaryEntity alarmSummary = new SensorAlarmSummaryEntity(); + alarmSummary.setRecordId(alarmPoint.getBrigade() + "-" + strDay); + SensorAlarmSummaryEntity alarmSummaryDB = (SensorAlarmSummaryEntity)alarmSummary.QueryIt(dataSource); + if(alarmSummaryDB == null){ + alarmSummaryDB = new SensorAlarmSummaryEntity(); + alarmSummaryDB.setRecordId(alarmSummary.getRecordId()); + alarmSummaryDB.setBrigade(alarmPoint.getBrigade()); + alarmSummaryDB.setYear(strY); + alarmSummaryDB.setMonth(strM); + alarmSummaryDB.setWeek(strWeek); + alarmSummaryDB.setDay(strD); + alarmSummaryDB.setPushCount(1); + alarmSummaryDB.setAlarmTotal(1); + alarmSummaryDB.setAiCount(0); + alarmSummaryDB.setSkynetCount(0); + alarmSummaryDB.setMdevCount(0); + alarmSummaryDB.setTimestamp(new Date()); + alarmSummaryDB.Insert(dataSource); + }else{ + int oldPushCount = alarmSummaryDB.getPushCount(); + int oldTotalCount = alarmSummaryDB.getAlarmTotal(); + alarmSummaryDB.setPushCount(1+oldPushCount); + alarmSummaryDB.setAlarmTotal(1+oldTotalCount); + alarmSummaryDB.Update(dataSource); + } + + + + SensorEventNotify notify = new SensorEventNotify(alarmEvent); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(alarmPoint.getBrigade()); + pro.setBorough(alarmPoint.getBorough()); + pro.setDetachment(alarmPoint.getDetachment()); + pro.setStation(alarmPoint.getStation()); + pro.setDevice_id(notify.getDeviceId()); + pro.setDevice_type(alarmPoint.getDeviceType()); + notify.attachProperty(pro); + System.out.println("websocket send sensor event 一键报警: "+ JSON.toJSONString(pro)); + clientWebsocketManager.addWebNotify(notify); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("alarm_event"); + msg.setData(JSON.toJSONString(alarmEvent)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + messagePublisher.sendMessage(alarmPoint.getStation(),str); + + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/EarthInductorRunInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/EarthInductorRunInfo.java new file mode 100644 index 0000000..28f7b1e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/EarthInductorRunInfo.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.services.sensor; + +public class EarthInductorRunInfo { + private String deviceid; + private long occupystart; + private String owner; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setOccupystart(long occupystart) { + this.occupystart = occupystart; + } + + public long getOccupystart() { + return occupystart; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/SensorRunInfoManager.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/SensorRunInfoManager.java new file mode 100644 index 0000000..0b99ad2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/SensorRunInfoManager.java @@ -0,0 +1,394 @@ +package com.jingyi.iotserver.firestationport.services.sensor; + +import com.jingyi.iotserver.firestationport.model.sensor.EarthInductorBuzEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorLinkStateEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.services.station.StationRuningInfo; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.EarthInductorBuzEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.SensorLineLinkNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLDataObject; + +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Service +public class SensorRunInfoManager { + @Autowired + private DataSource dataSource; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + @Autowired + private FireStationLiveManager stationLiveManager; + + @Autowired + private MessagePublisher messagePublisher; + private ConcurrentHashMap mEarthInductorInfoMap = new ConcurrentHashMap(); + private ConcurrentHashMap sensorTypeConfig = new ConcurrentHashMap(); + private boolean blInited = false; + private Thread scanservice = null; + + public void Init(){ + if(blInited) + return; + blInited = true; + LoadDeviceType(); + scanservice = new Thread(){ + public void run(){ + while(true){ + try { + ScanEarthRunInfo(); + CheckSensorLink(); + }catch (Exception e){ + + } + try{ + Thread.sleep(5*1000); + }catch (Exception e){ + + } + } + } + }; + + scanservice.start(); + + } + + public void LoadDeviceType(){ + InputStream stream = null; + try { + stream = getClass().getClassLoader().getResourceAsStream("static/sensortypeconfig.xml"); + File targetFile = new File("devicetypeconfig.xml"); + // FileUtils.copyInputStreamToFile(stream, targetFile); + + // BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(targetFile))); + + SAXReader reader = new SAXReader(); + Document document = reader.read(new InputStreamReader(stream, "utf8")); + Element root = document.getRootElement(); + if ("sensortype".equals(root.getName())) { + List list = root.elements(); + for (Element el : list) { + if (el == null) + continue; + + String type = null; + try { + Attribute atr = el.attribute("name"); + type = atr.getStringValue(); + }catch (Exception e){ + + } + + int heartbeat = 0; + + try { + Attribute atr = el.attribute("heartbeat"); + heartbeat = Integer.parseInt(atr.getStringValue()); + }catch (Exception e){ + + } + SensorTypeDescriptor des = new SensorTypeDescriptor(); + des.setHeartbeat(heartbeat); + des.setType(type); + + sensorTypeConfig.put(type,des); + } + } + }catch (Exception e){ + + } + } + + public int getSensorHeartBeat(String devtype){//seconds + SensorTypeDescriptor des = sensorTypeConfig.get(devtype); + if(des==null){ + return 300; + } + + if(des.getHeartbeat()<30) + return 30; + return des.getHeartbeat(); + } + + public void CheckSensorLink(){ + long curtime = System.currentTimeMillis(); + for(Map.Entry entry: sensorTypeConfig.entrySet()) { + SensorTypeDescriptor des = entry.getValue(); + if(curtime>=des.getHeartbeat()*1000+des.getLastCheckTime()){ + des.setLastCheckTime(curtime); + List list = null; + int pageindex = 0; + do { + if((pageindex%2)>0) { + try{ + Thread.sleep(100); + }catch (Exception e) { + } + } + list = SensorLinkStateEntity.queryActiveSensorPageBefore(dataSource, des.getType(), des.getHeartbeat() * 1000 * 3,pageindex,500); + pageindex++; + if (list == null) + break; + for (SQLDataObject ob : list) { + SensorLinkStateEntity lk = (SensorLinkStateEntity) ob; + lk.setState("offline"); + lk.Update(dataSource); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource, lk.getDeviceid()); + if (sensor != null) { + if(!"offline".equalsIgnoreCase(sensor.getLineState())){ + sensor.setLineState("offline"); + sensor.Update(dataSource); + } + } + + //notify client + + SensorLineLinkNotify notify = new SensorLineLinkNotify(); + notify.setDeviceid(lk.getDeviceid()); + notify.setDevicetype(lk.getDevicetype()); + notify.setState("offline"); + notify.setStation(lk.getStation()); + notify.setLinktime(new Date()); + StationRuningInfo from = stationLiveManager.getStationInfo(lk.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.name); + pro.setDevice_id(lk.getDeviceid()); + pro.setDevice_type(lk.getDevicetype()); + notify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + + //send event to station + MessageToStation msg = new MessageToStation(); + msg.setMessage("sensor-offline"); + msg.setData(lk); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + + messagePublisher.sendMessage(lk.getStation(), str); + + } + }while(list!=null&&list.size()>=500); + } + } + } + + public void SetEarthInductorOccupy(String deviceid){ + EarthInductorRunInfo info = mEarthInductorInfoMap.get(deviceid); + if(info==null){ + info = new EarthInductorRunInfo(); + info.setDeviceid(deviceid); + info.setOccupystart(System.currentTimeMillis()); + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,deviceid); + if(sensor==null) + return; + info.setOwner(sensor.getOwner()); + mEarthInductorInfoMap.put(deviceid,info); + } + } + + public void SetEarthInductorIdle(String deviceid){ + EarthInductorRunInfo info = mEarthInductorInfoMap.remove(deviceid); + + try { + EarthInductorBuzEventEntity buzevent = EarthInductorBuzEventEntity.Query(dataSource,deviceid, "start"); + if (buzevent != null) { + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,deviceid); + if(sensor==null) + return; + + buzevent.Stop(dataSource); + EarthInductorBuzEventNotify buznotify = new EarthInductorBuzEventNotify(); + buznotify.setStation(sensor.getOwner()); + buznotify.setBrigade(sensor.getBrigade()); + buznotify.setBorough(sensor.getBorough()); + buzevent.setDetachment(sensor.getDetachment()); + buznotify.setBuztype(buzevent.getBuztype()); + buznotify.setDeviceid(buzevent.getDeviceid()); + buznotify.setDevicetype(buzevent.getDevicetype()); + buznotify.setStarttime(buzevent.getStarttime()); + buznotify.setEndtime(buzevent.getEndtime()); + buznotify.setStatus(buzevent.getStatus()); + buznotify.setEventid(buzevent.getEventid()); + + StationRuningInfo from = stationLiveManager.getStationInfo(buznotify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.name); + pro.setDevice_id(buznotify.getDeviceid()); + pro.setDevice_type(buznotify.getDevicetype()); + buznotify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(buznotify); + } + + + //send event to station + MessageToStation msg =new MessageToStation(); + + msg.setMessage("earthinductor-alarm-event"); + msg.setData(buzevent); + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + private void ScanEarthRunInfo(){ + long curtime = System.currentTimeMillis(); + for(Map.Entry entry: mEarthInductorInfoMap.entrySet()) { + EarthInductorRunInfo info = entry.getValue(); + if(curtime>info.getOccupystart()&&curtime-info.getOccupystart()>30*1000){ + mEarthInductorInfoMap.remove(info.getDeviceid()); + GenerateEarthInductorBuzEvent(info); + } + } + } + + private void GenerateEarthInductorBuzEvent(EarthInductorRunInfo info){ + try { + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,info.getOwner()); + EarthInductorBuzEventEntity buzevent = EarthInductorBuzEventEntity.Query(dataSource,info.getDeviceid(), "start"); + if (buzevent == null) { + buzevent = new EarthInductorBuzEventEntity(); + buzevent.setDeviceid(info.getDeviceid()); + buzevent.setBuztype("earthinductor-alarm"); + buzevent.setStarttime(new Date()); + buzevent.setStatus("start"); + buzevent.setDevicetype("earthinductor"); + buzevent.setOwner(info.getOwner()); + + buzevent.setBrigade(st.getBrigade()); + buzevent.setBorough(st.getBorough()); + buzevent.setDetachment(st.getDetachment()); + buzevent.Insert(dataSource); + + EarthInductorBuzEventNotify buznotify = new EarthInductorBuzEventNotify(); + buznotify.setStation(info.getOwner()); + buznotify.setBrigade(st.getBrigade()); + buznotify.setBorough(st.getBorough()); + buznotify.setDetachment(st.getDetachment()); + buznotify.setBuztype(buzevent.getBuztype()); + buznotify.setDeviceid(buzevent.getDeviceid()); + buznotify.setDevicetype(buzevent.getDevicetype()); + buznotify.setStarttime(buzevent.getStarttime()); + buznotify.setStatus(buzevent.getStatus()); + buznotify.setEventid(buzevent.getEventid()); + StationRuningInfo from = stationLiveManager.getStationInfo(buznotify.getStation()); + if(from!=null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.name); + pro.setDevice_id(buznotify.getDeviceid()); + pro.setDevice_type(buznotify.getDevicetype()); + buznotify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(buznotify); + } + + //send event to station + MessageToStation msg =new MessageToStation(); + msg.setMessage("earthinductor-alarm-event"); + msg.setData(buzevent); + JpushClientUtil.sendMessageToDevice("firectrl", info.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void setSensorActive(SensorDeviceEntity sensor){ + if(sensor==null||sensor.getDeviceid()==null) + return; + SensorLinkStateEntity link = new SensorLinkStateEntity(); + link.setDeviceid(sensor.getDeviceid()); + link.setDevicetype(sensor.getDevicetype()); + link.setBrigade(sensor.getBrigade()); + link.setBorough(sensor.getBorough()); + link.setDetachment(sensor.getDetachment()); + link.setStation(sensor.getOwner()); + link.setState("online"); + link.setTimestamp(System.currentTimeMillis()); + SensorLinkStateEntity nowlink = (SensorLinkStateEntity)link.QueryIt(dataSource); + + boolean notifyonline = false; + if(nowlink!=null){ + link.Update(dataSource); + if("offline".equals(nowlink.getState())) + notifyonline = true; + }else{ + link.Insert(dataSource); + notifyonline = true; + } + + try { + if (notifyonline) { + SensorLineLinkNotify notify = new SensorLineLinkNotify(); + notify.setDeviceid(link.getDeviceid()); + notify.setDevicetype(link.getDevicetype()); + notify.setState("online"); + notify.setStation(link.getStation()); + notify.setLinktime(new Date()); + StationRuningInfo from = stationLiveManager.getStationInfo(link.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.brigade); + pro.setBorough(from.borough); + pro.setDetachment(from.detachment); + pro.setStation(from.name); + pro.setDevice_id(link.getDeviceid()); + pro.setDevice_type(link.getDevicetype()); + notify.attachProperty(pro); + //send notify to client + clientWebsocketManager.addWebNotify(notify); + } + + //send event to station + MessageToStation msg = new MessageToStation(); + msg.setMessage("sensor-online"); + msg.setData(link); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + + messagePublisher.sendMessage(link.getStation(), str); + } + }catch (Exception e){ + + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/SensorTypeDescriptor.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/SensorTypeDescriptor.java new file mode 100644 index 0000000..ce7c632 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/SensorTypeDescriptor.java @@ -0,0 +1,35 @@ +package com.jingyi.iotserver.firestationport.services.sensor; + +import com.jingyi.iotserver.utils.*; + +public class SensorTypeDescriptor { + + private String type; + + private int heartbeat;//seconds + + private long lastCheckTime; + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setHeartbeat(int heartbeat) { + this.heartbeat = heartbeat; + } + + public int getHeartbeat() { + return heartbeat; + } + + public void setLastCheckTime(long lastCheckTime) { + this.lastCheckTime = lastCheckTime; + } + + public long getLastCheckTime() { + return lastCheckTime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/client/DeShanAnNettyClient.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/client/DeShanAnNettyClient.java new file mode 100644 index 0000000..f73007f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/client/DeShanAnNettyClient.java @@ -0,0 +1,69 @@ +package com.jingyi.iotserver.firestationport.services.sensor.deshanan.client; + + +import com.jingyi.iotserver.firestationport.services.sensor.deshanan.handler.ClientChannelInitializer; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; + + +import java.util.concurrent.TimeUnit; + +/** + * author: luozhun + * desc: NettyClient + * createTime: 2023/8/14 16:13 + */ + +public class DeShanAnNettyClient { + + private final String host = "218.76.54.20"; + private final Integer port = 20000; + + private final EventLoopGroup group; + private final Bootstrap bootstrap; + + public DeShanAnNettyClient() { + group = new NioEventLoopGroup(); + bootstrap = new Bootstrap(); + // 配置 bootstrap + bootstrap.group(group) + .channel(NioSocketChannel.class) + .option(ChannelOption.TCP_NODELAY, true) + .handler(new ClientChannelInitializer()); + } + + public ChannelFuture connect() { + // 创建新的连接 + ChannelFuture future = bootstrap.connect(host, port); + // 添加连接监听器,处理连接成功和失败的情况 + future.addListener((ChannelFutureListener) channelFuture -> { + if (channelFuture.isSuccess()) { + System.out.println("连接Netty服务端成功"); + } else { + System.out.println("连接Netty服务端失败,进行重连中......"); + // 连接失败后,进行重连操作 三秒后重连 + channelFuture.channel().eventLoop().schedule(this::connect, 3, TimeUnit.SECONDS); + } + }); + return future; + } + + public void shutdown() { + group.shutdownGracefully(); + } + + public static void main(String[] args) { + DeShanAnNettyClient client = new DeShanAnNettyClient(); + client.connect(); + /* + * 释放资源操作的代码注册到 JVM 的关闭钩子 + * 一旦关闭 EventLoopGroup,将无法再使用它来创建新的连接,因此无法直接重连 + */ + Runtime.getRuntime().addShutdownHook(new Thread(client::shutdown)); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/ClientChannelInitializer.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/ClientChannelInitializer.java new file mode 100644 index 0000000..b27738c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/ClientChannelInitializer.java @@ -0,0 +1,32 @@ +package com.jingyi.iotserver.firestationport.services.sensor.deshanan.handler; + +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.DelimiterBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.util.CharsetUtil; + + +/** + * author: luozhun + * desc: ClientChannelInitializer + * createTime: 2023/8/14 16:14 + */ + +public class ClientChannelInitializer extends ChannelInitializer { + + @Override + public void channelReadComplete(ChannelHandlerContext ctx) { + ctx.flush(); + } + + + @Override + protected void initChannel(SocketChannel channel) { + channel.pipeline().addLast(new DelimiterBasedFrameDecoder(1024, Unpooled.buffer().writeBytes("]".getBytes()))); + channel.pipeline().addLast(new StringDecoder(CharsetUtil.UTF_8)); + channel.pipeline().addLast(new ClientHandler()); + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/ClientHandler.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/ClientHandler.java new file mode 100644 index 0000000..12e6fb1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/ClientHandler.java @@ -0,0 +1,73 @@ +package com.jingyi.iotserver.firestationport.services.sensor.deshanan.handler; + + +import cn.hutool.core.util.StrUtil; +import com.jingyi.iotserver.firestationport.services.sensor.DeShanAnService; +import com.jingyi.iotserver.firestationport.services.sensor.deshanan.client.DeShanAnNettyClient; +import com.jingyi.iotserver.mqtt.MessagePublisher; +import com.jingyi.iotserver.utils.SpringContextUtil; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + + +import java.util.concurrent.TimeUnit; + +/** + * author: luozhun + * desc: ClientHandler + * createTime: 2023/8/14 16:15 + */ + +public class ClientHandler extends SimpleChannelInboundHandler { + + private DeShanAnService deShanAnService; + + public ClientHandler(){ + deShanAnService = (DeShanAnService) SpringContextUtil.getBean(DeShanAnService.class); + } + + /** + * 接收到消息时触发 + */ + @Override + protected void channelRead0(ChannelHandlerContext channelHandlerContext, String msg) throws Exception { + // System.out.println("netty接收到消息: " + msg); + + if (StrUtil.containsAny(msg, "ConnectOK", "DataTest")) { + // System.out.println("DeShanAnService rec: "+msg); + return; + } + + // System.out.println("DeShanAnService netty接收到消息: "+msg); + + if(deShanAnService != null){ + String newFrame = new String(msg); + deShanAnService.parseFrame(newFrame); + } + + } + + /** + * 断开连接时触发 + */ + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + System.out.println("netty客户端断开连接,准备重连......"); + //三秒后开始重连 + ctx.channel().eventLoop().schedule(() -> { + DeShanAnNettyClient client = new DeShanAnNettyClient(); + client.connect(); + }, 3L, TimeUnit.SECONDS); + super.channelInactive(ctx); + } + + /** + * 发生异常时触发 + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + System.out.println("netty客户端发生异常:" + cause.getMessage()); + ctx.close(); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/MessageToByteEncoderHandler.java b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/MessageToByteEncoderHandler.java new file mode 100644 index 0000000..29a980f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/sensor/deshanan/handler/MessageToByteEncoderHandler.java @@ -0,0 +1,19 @@ +package com.jingyi.iotserver.firestationport.services.sensor.deshanan.handler; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +/** + * author: luozhun + * desc: MessageToByteEncoderHandler + * createTime: 2023/8/14 16:04 + */ +public class MessageToByteEncoderHandler extends MessageToByteEncoder { + @Override + protected void encode(ChannelHandlerContext channelHandlerContext, String s, ByteBuf byteBuf) throws Exception { + byteBuf.writeBytes("[".getBytes()); + byteBuf.writeBytes(s.getBytes()); + byteBuf.writeBytes("]".getBytes()); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/station/FireStationLiveManager.java b/src/main/java/com/jingyi/iotserver/firestationport/services/station/FireStationLiveManager.java new file mode 100644 index 0000000..b95fc16 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/station/FireStationLiveManager.java @@ -0,0 +1,634 @@ +package com.jingyi.iotserver.firestationport.services.station; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationLineEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationSignEntity; +import com.jingyi.iotserver.firestationport.model.station.StationRunningInfoEntity; +import com.jingyi.iotserver.firestationport.model.todev.NoticeEntity; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.*; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SQLTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.Date; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Service +public class FireStationLiveManager { + + @Autowired + private DataSource dataSource; + + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + private boolean blInited = false; + private Object locker = new Object(); + private static final int STATION_GROUP_COUNT = 4; + private ConcurrentHashMap mStationsMap = new ConcurrentHashMap(); + private Thread scanservice = null; + + private ConcurrentHashMap mRollCallMonitors = new ConcurrentHashMap(); + + public void Init(){ + if(blInited) + return; + blInited = true; + + scanservice = new Thread(){ + public void run(){ + while(true){ + try { + PerformTick(); + PerformRollCallMonitor(); + }catch (Exception e){ + + } + try{ + Thread.sleep(30*1000); + }catch (Exception e){ + + } + } + } + }; + + scanservice.start(); + + } + + private void PerformTick(){ + long curtime = System.currentTimeMillis(); + for(Map.Entry entry: mStationsMap.entrySet()){ + StationRuningInfo info = entry.getValue(); + if(info!=null&&info.lineState){ + if(curtime-info.lastActiveTime>5*60*1000){ + + FireStationLineEntity line = new FireStationLineEntity(); + line.setStation_name(info.name); + line.setStation_number(info.number); + line.setId(info.lineid); + line.setOffline(new Date()); + System.out.println("station offline: "+info.name+" time:"+System.currentTimeMillis()/1000); + try { + line.extendName(""+info.number); + line.UpdateEndTime(dataSource); + }catch (Exception e){ + + } + SendLineStateNotify(info,"offline"); + info.detail.setState("offline"); + if(info.signid>0) { + SendSignStateNotify(info,"0"); + FireStationSignEntity sign = new FireStationSignEntity(); + sign.setStation_name(info.name); + sign.setStation_number(info.number); + sign.setSignout(new Date()); + sign.setId(info.signid); + try { + sign.extendName(""+info.number); + sign.SetSignOut(dataSource); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + info.lineState = false; + info.lineid = -1; + info.signstate = false; + info.signid = -1; + info.detail.setSignstate("outsign"); + info.detail.Update(dataSource); + System.out.println(info.name+" offline"); + }else{ + if(info.lastSaveTime!=info.lastActiveTime){ + FireStationLineEntity line = new FireStationLineEntity(); + line.setStation_name(info.name); + line.setStation_number(info.number); + line.setId(info.lineid); + line.setOffline(new Date(info.lastActiveTime)); + try { + line.extendName(""+info.number); + line.UpdateEndTime(dataSource); + }catch (Exception e){ + + } + info.lastSaveTime = info.lastActiveTime; + System.out.println("heartbeat signid:"+info.signid); + if(info.signid>0) { + FireStationSignEntity sign = new FireStationSignEntity(); + sign.setStation_name(info.name); + sign.setStation_number(info.number); + sign.setSignout(new Date()); + sign.setId(info.signid); + try { + sign.extendName(""+info.number); + sign.SetSignOut(dataSource); + } catch (Exception e) { + e.printStackTrace(); + } + if (System.currentTimeMillis() - info.signinTime >= 4 * 60 * 60 * 1000) { + info.signstate = false; + info.signid = -1; + info.detail.setSignstate("outsign"); + info.detail.Update(dataSource); + System.out.println(info.name+" timeout"); + SendSignStateNotify(info,"0"); + } + } + + + } + } + } + } + + + } + + private void PerformRollCallMonitor(){ + try{ + long curtime = System.currentTimeMillis(); + for(Map.Entry entry: mRollCallMonitors.entrySet()){ + RollCallMonitor monitor = entry.getValue(); + if(monitor!=null){ + if(monitor.getTimestamp()+3*0*1000<=curtime){ + ConcurrentHashMap table = monitor.getStationTable(); + if(table==null) + continue; + NoticeEntity notice = new NoticeEntity(); + notice.setNoticeid(""+System.currentTimeMillis()); + notice.setTitle("点名未响应!"); + notice.setSender("system"); + notice.setContent(SQLTools.formatDate(new Date(monitor.getTimestamp()))+"的点名未响应!"); + notice.setTimestamp(new Date()); + + mRollCallMonitors.remove(entry.getKey()); + for(Map.Entry se: table.entrySet()){ + String station = se.getKey(); + + String content = JsonHelper.convertObjectToStr(notice); + JpushClientUtil.sendMessageToDevice("firectrl", station, "notify", content, 0); + } + + } + } + } + }catch (Exception e){ + + } + } + + public boolean removeStation(String stationname){ + StationRuningInfo info = mStationsMap.get(stationname); + if(info!=null){ + try { + if (info.lineid >= 0) { + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + setStationSignState(station, "2"); + } + }catch (Exception e){ + + } + + mStationsMap.remove(stationname); + } + return true; + } + + public boolean setStationActive(FireStationBaseInfoEntity station,JsonNode attachinfo){ + StationRuningInfo info = null; + + info = mStationsMap.get(station.getName()); + if(info==null){ + info = new StationRuningInfo(); + info.name = station.getName(); + info.number = station.getNumber(); + info.lineid = -1; + info.signid = -1; + // System.out.println(info.name+" online"); + info.signstate = false; + info.lineState = true; + info.brigade = station.getBrigade(); + info.borough = station.getBorough(); + info.detachment = station.getDetachment(); + info.detail = StationRunningInfoEntity.Query(dataSource,station.getName()); + if(info.detail==null){ + info.detail = new StationRunningInfoEntity(); + info.detail.setStation(station.getName()); + + } + if(info.detail.videostate==null) + info.detail.setVideostate("close"); + mStationsMap.put(station.getName(),info); + } + + info.lineState = true; + info.lastActiveTime = System.currentTimeMillis(); + if(info.lineid<=0) { + FireStationLineEntity line = new FireStationLineEntity(); + line.setStation_name(station.getName()); + line.setStation_number(station.getNumber()); + line.setOnline(new Date()); + line.setOffline(new Date()); + try { + line.extendName(""+info.number); + line.Insert(dataSource); + }catch (Exception e){ + + } + + info.lineid = line.getId(); + info.lastSaveTime = info.lastActiveTime; + info.detail.setState("online"); + info.detail.setSignstate("outsign"); + if(info.detail.videostate==null) + info.detail.setVideostate("close"); + + info.detail.Update(dataSource); + + SendLineStateNotify(info,"online"); + + } + + if(attachinfo!=null){ + String appversion = JsonHelper.getStringValue(attachinfo,"appversion"); + String newquest = JsonHelper.getStringValue(attachinfo,"newquest"); + String runningquest = JsonHelper.getStringValue(attachinfo,"runningquest"); + double longitude = JsonHelper.getDoubleValue(attachinfo,"longitude"); + double latitude = JsonHelper.getDoubleValue(attachinfo,"latitude"); + boolean detailchange = false; + boolean change = false; + if(appversion!=null){ + if(info.detail.appversion==null||!info.detail.appversion.equals(appversion)) { + info.detail.appversion = appversion; + StationAppVersionChangeNotify notify = new StationAppVersionChangeNotify(); + notify.setStation(info.name); + notify.setAppversion(appversion); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(info.name); + pro.setBrigade(info.brigade); + pro.setBorough(info.borough); + pro.setDetachment(info.detachment); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + detailchange = true; + } + } + + if(newquest!=null){ + if(info.detail.newquest==null||!info.detail.newquest.equals(newquest)){ + info.detail.newquest = newquest; + change = true; + detailchange = true; + } + + } + + if(runningquest!=null){ + if(info.detail.runningquest==null||!info.detail.runningquest.equals(runningquest)){ + info.detail.runningquest = runningquest; + change = true; + detailchange = true; + } + + } + if(change){ + StationQuestChangeNotify notify = new StationQuestChangeNotify(); + notify.setStation(info.name); + notify.setNewquest(newquest); + notify.setRunningquest(runningquest); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(info.name); + pro.setBrigade(info.brigade); + pro.setBorough(info.borough); + pro.setDetachment(info.detachment); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + change = false; + if(longitude!=0.0&&info.detail.longitude!=longitude){ + info.detail.longitude = longitude; + change = true; + detailchange = true; + } + + if(latitude!=0.0&&info.detail.latitude!=latitude){ + info.detail.latitude = latitude; + change = true; + detailchange = true; + } + if(change){ + StationLocationChangeNotify notify = new StationLocationChangeNotify(); + notify.setStation(info.name); + notify.setLatitude(latitude); + notify.setLongitude(longitude); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(info.name); + pro.setBrigade(info.brigade); + pro.setBorough(info.borough); + pro.setDetachment(info.detachment); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + if(detailchange) { + info.detail.Update(dataSource); + } + } + return true; + } + + public boolean setStationSignState(FireStationBaseInfoEntity station,String state){ + StationRuningInfo info = null; + + info = mStationsMap.get(station.getName()); + if(info==null){ + info = new StationRuningInfo(); + info.name = station.getName(); + info.number = station.getNumber(); + info.lineid = -1; + info.lineState = false; + info.signid = -1; + info.signstate = false; + info.brigade = station.getBrigade(); + info.borough = station.getBorough(); + info.detachment = station.getDetachment(); + info.detail = StationRunningInfoEntity.Query(dataSource,station.getName()); + if(info.detail==null){ + info.detail = new StationRunningInfoEntity(); + info.detail.setStation(station.getName()); + + } + if(info.detail.videostate==null) + info.detail.setVideostate("close"); + mStationsMap.put(station.getName(),info); + } + + if(info.lineid<=0) { + FireStationLineEntity line = new FireStationLineEntity(); + line.setStation_name(station.getName()); + line.setStation_number(station.getNumber()); + line.setOnline(new Date()); + line.setOffline(new Date()); + line.extendName(""+station.getNumber()); + line.Insert(dataSource); + + info.lineid = line.getId(); + info.lastSaveTime = info.lastActiveTime; + SendLineStateNotify(info,"online"); + info.detail.setState("online"); + if(info.detail.videostate==null) + info.detail.setVideostate("close"); + + + } + + if(state.equals("1")) + { + + info.signinTime = System.currentTimeMillis(); + if(info.signid<=0) { + FireStationSignEntity sign = new FireStationSignEntity(); + sign.setStation_name(station.getName()); + sign.setStation_number(station.getNumber()); + sign.setSignin(new Date()); + sign.setSignout(new Date()); + sign.extendName(""+station.getNumber()); + sign.Insert(dataSource); + + info.signid = sign.getId(); + // System.out.println("new signid:"+info.signid); + SendSignStateNotify(info,"1"); + info.detail.setSignstate("insign"); + info.detail.setState("online"); + info.detail.Update(dataSource); + } + + + /**/ + }else{ + if(info.signid>0) { + FireStationSignEntity sign = new FireStationSignEntity(); + sign.setStation_name(station.getName()); + sign.setStation_number(station.getNumber()); + sign.setSignout(new Date()); + sign.setId(info.signid); + sign.extendName(""+info.number); + sign.SetSignOut(dataSource); + + info.signid = -1; + info.signstate = false; + System.out.println("sign out"); + + SendSignStateNotify(info,"0"); + info.detail.setSignstate("outsign"); + info.detail.setState("online"); + info.detail.Update(dataSource); + } + } + + + + return true; + } + + private void SendSignStateNotify(StationRuningInfo info ,String state){ + SignNotify signnotify = new SignNotify(); + signnotify.setStation(info.name); + signnotify.setSigntime(new Date()); + signnotify.setState(state); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(info.name); + pro.setBrigade(info.brigade); + pro.setBorough(info.borough); + pro.setDetachment(info.detachment); + signnotify.attachProperty(pro); + clientWebsocketManager.addWebNotify(signnotify); + } + + private void SendLineStateNotify(StationRuningInfo info ,String state) { + LineLinkNotify notify = new LineLinkNotify(); + notify.setStation(info.name); + notify.setState(state); + notify.setLinktime(new Date()); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setStation(info.name); + pro.setBrigade(info.brigade); + pro.setBorough(info.borough); + pro.setDetachment(info.detachment); + notify.attachProperty(pro); + clientWebsocketManager.addWebNotify(notify); + } + + + public StationRuningInfo getStationInfo(String stationname){ + StationRuningInfo info = mStationsMap.get(stationname); + return info; + } + + public OrganiztionUri getStationUri(String stationname){ + StationRuningInfo info = mStationsMap.get(stationname); + if(info!=null){ + OrganiztionUri uri = new OrganiztionUri(); + uri.setBorough(info.borough); + uri.setBrigade(info.brigade); + uri.setDetachment(info.detachment); + uri.setStation(info.name); + return uri; + }else{ + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + if(station==null) + return null; + OrganiztionUri uri = new OrganiztionUri(); + uri.setBorough(station.getBorough()); + uri.setBrigade(station.getBrigade()); + uri.setDetachment(station.getDetachment()); + uri.setStation(station.getName()); + return uri; + } + } + + public StationRunningInfoEntity queryStationRunningInfo(String station){ + StationRunningInfoEntity info = StationRunningInfoEntity.Query(dataSource,station); + return info; + } + + + public boolean matchScope(String stationname,String brigade,String borough,String detachment){ + StationRuningInfo info = null; + + info = mStationsMap.get(stationname); + if(info!=null){ + if(brigade!=null){ + if(!brigade.equals(info.brigade)) + return false; + } + + if(borough!=null){ + if(!borough.equals(info.borough)) + return false; + } + + if(detachment!=null){ + if(!detachment.equals(info.detachment)) + return false; + } + return true; + } + + FireStationBaseInfoEntity station = FireStationBaseInfoEntity.Query(dataSource,stationname); + if(station==null) + return false; + + if(brigade!=null){ + if(!brigade.equals(station.getBrigade())) + return false; + } + + if(borough!=null){ + if(!borough.equals(station.getBorough())) + return false; + } + + if(detachment!=null){ + if(!detachment.equals(station.getDetachment())) + return false; + } + return true; + } + + public String getStationAppVersion(String station){ + StationRuningInfo info = null; + try { + info = mStationsMap.get(station); + if (info != null) + return info.detail.appversion; + }catch (Exception e){ + + } + return null; + } + + public void setStationAlarm(String station){ + StationRuningInfo info = null; + try { + info = mStationsMap.get(station); + if (info != null) { + info.detail.setAlarmstate("alarm"); + info.detail.Update(dataSource); + } + }catch (Exception e){ + + } + } + + public void rmStationAlarm(String station){ + StationRuningInfo info = null; + try { + info = mStationsMap.get(station); + if (info != null) { + info.detail.setAlarmstate("noalarm"); + info.detail.Update(dataSource); + } + }catch (Exception e){ + + } + } + + public void setVideoState(String station,String state){ + StationRuningInfo info = null; + try { + info = mStationsMap.get(station); + if (info != null) { + if(info.detail.getVideostate()==null||!info.detail.getVideostate().equals(state)) { + info.detail.setVideostate(state); + info.detail.Update(dataSource); + + StationVideoEventNotify notify = new StationVideoEventNotify(); + notify.setStation(station); + notify.setState(state); + notify.setTimestamp(new Date()); + + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(info.brigade); + pro.setBorough(info.borough); + pro.setDetachment(info.detachment); + pro.setStation(info.name); + notify.attachProperty(pro); + + clientWebsocketManager.addWebNotify(notify); + } + } + }catch (Exception e){ + + } + } + + public void addRollCallMonitor(RollCallMonitor monitor){ + if(monitor!=null) + mRollCallMonitors.put(monitor.getNumber(),monitor); + } + + public void setStationAckRollCall(String station,String rollcall){ + RollCallMonitor monitor = mRollCallMonitors.get(rollcall); + if(monitor!=null) + monitor.removeStation(station); + } + + public boolean IsStaionOnline(String station){ + StationRuningInfo info = mStationsMap.get(station); + if(info!=null) + return info.lineState; + return false; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/station/RollCallMonitor.java b/src/main/java/com/jingyi/iotserver/firestationport/services/station/RollCallMonitor.java new file mode 100644 index 0000000..f3b336b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/station/RollCallMonitor.java @@ -0,0 +1,47 @@ +package com.jingyi.iotserver.firestationport.services.station; + + +import java.util.concurrent.ConcurrentHashMap; + +public class RollCallMonitor { + private String number; + private String scope; + private long timestamp; + private ConcurrentHashMap stationTable ; + + public void setNumber(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getScope() { + return scope; + } + + public void setStationTable(ConcurrentHashMap stationTable) { + this.stationTable = stationTable; + } + + public ConcurrentHashMap getStationTable() { + return stationTable; + } + + public void removeStation(String name){ + stationTable.remove(name); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/station/StationRuningInfo.java b/src/main/java/com/jingyi/iotserver/firestationport/services/station/StationRuningInfo.java new file mode 100644 index 0000000..863b344 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/station/StationRuningInfo.java @@ -0,0 +1,21 @@ +package com.jingyi.iotserver.firestationport.services.station; + +import com.jingyi.iotserver.firestationport.model.station.StationRunningInfoEntity; + +public class StationRuningInfo { + public int number; + public String name; + public boolean lineState;//true online, false offline + public long lastActiveTime; + public long lastSaveTime; + public int lineid; + + public boolean signstate; + public long signinTime; + public int signid; + public String brigade; + public String borough; + public String detachment; + + public StationRunningInfoEntity detail; +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/userman/HouseOwnerLoginResult.java b/src/main/java/com/jingyi/iotserver/firestationport/services/userman/HouseOwnerLoginResult.java new file mode 100644 index 0000000..c2d98ef --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/userman/HouseOwnerLoginResult.java @@ -0,0 +1,13 @@ +package com.jingyi.iotserver.firestationport.services.userman; + +public class HouseOwnerLoginResult { + private String session; + + public void setSession(String session) { + this.session = session; + } + + public String getSession() { + return session; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/services/userman/HouseOwnerManager.java b/src/main/java/com/jingyi/iotserver/firestationport/services/userman/HouseOwnerManager.java new file mode 100644 index 0000000..d9088c7 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/services/userman/HouseOwnerManager.java @@ -0,0 +1,69 @@ +package com.jingyi.iotserver.firestationport.services.userman; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Service +public class HouseOwnerManager { + + + private ConcurrentHashMap mHouseOwnerMap = new ConcurrentHashMap(); + + private Thread scanservice = null; + public void Init(){ + + scanservice = new Thread(){ + public void run(){ + while(true){ + try { + CheckSessionTimeOut(); + }catch (Exception e){ + + } + try{ + Thread.sleep(3*1000); + }catch (Exception e){ + + } + } + } + }; + + scanservice.start(); + } + + private void CheckSessionTimeOut(){ + long curtime = System.currentTimeMillis(); + for(Map.Entry entry: mHouseOwnerMap.entrySet()) { + HouseOwnerRunningInfo info = entry.getValue(); + if(info==null) + continue; + if(info.lastActiveTime+30*60*1000 sysRoleList = user.getSysRoleList(); + List sysPermissionList = user.getSysPermissionList(); + + SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); + for (SysRole sysRole:sysRoleList){ + simpleAuthorizationInfo.addRole(sysRole.getCode()); + } + for (SysPermission sysPermission:sysPermissionList){ + simpleAuthorizationInfo.addStringPermission(sysPermission.getPermission()); + } + return simpleAuthorizationInfo; + */ + return null; + } + + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) + throws AuthenticationException { + + UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) authenticationToken; + String userName = usernamePasswordToken.getUsername(); + if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(Arrays.toString(usernamePasswordToken.getPassword()))) { + + UserService userService = (UserService) SpringContextUtil.getBean(UserService.class); + UserInfoEntity user = userService.queryUserInfo(userName); + + + if (user != null) { + return new SimpleAuthenticationInfo(user, user.getPassword(), getName()); + } else { + throw new IncorrectCredentialsException(); + } + } else if (StringUtils.isEmpty(userName)) { + throw new IncorrectCredentialsException("用户名为空"); + } else { + throw new IncorrectCredentialsException("密码为空"); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/ClientWebsocketManager.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/ClientWebsocketManager.java new file mode 100644 index 0000000..deb6299 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/ClientWebsocketManager.java @@ -0,0 +1,360 @@ +package com.jingyi.iotserver.firestationport.websocket; + +import com.jingyi.iotserver.firestationport.websocket.message.*; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArraySet; + +@Service +public class ClientWebsocketManager { + + private boolean blInited = false; + private CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet(); + + private Thread dispatcher = null; + + private HashMap mWebMsgMap = new HashMap(); + private ConcurrentHashMap> mWebNotifyMap = new ConcurrentHashMap>(); + + private MessageToClient serverToClientHB = null; + + + public void init(){ + if(blInited) + return; + blInited = true; + initNotifyTable(); + dispatcher = new Thread(){ + public void run(){ + while(true){ + try { + DispachNotify(); + }catch (Exception e){ + } + try { + DispatchHeartBeatToClient(); + }catch (Exception e){ + } + + try{ + Thread.sleep(1000); + }catch (Exception e){ + } + } + } + }; + + dispatcher.start(); + } + + private void initNotifyTable() { + + if(serverToClientHB == null){ + serverToClientHB = new MessageToClient(); + serverToClientHB.setMsgcode(501); + serverToClientHB.setMsgname("server.hb"); + serverToClientHB.setMessage("live"); + } + + MessageToClient client = new MessageToClient(); + client.setMsgcode(1001); + client.setMsgname("sign"); + mWebMsgMap.put(SignNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1002); + client.setMsgname("linelink"); + mWebMsgMap.put(LineLinkNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1003); + client.setMsgname("stationalarm"); + mWebMsgMap.put(StationAlarmNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1004); + client.setMsgname("smoking"); + mWebMsgMap.put(SmokingSensorNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1005); + client.setMsgname("earthinductor"); + mWebMsgMap.put(EarthInductorNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1006); + client.setMsgname("smoking-buzevent"); + mWebMsgMap.put(SmokingBuzEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1007); + client.setMsgname("pipepressurestatus"); + mWebMsgMap.put(PipePressureSensorNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1008); + client.setMsgname("stationstatus"); + mWebMsgMap.put(StationStatusChangeNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1009); + client.setMsgname("videostatus"); + mWebMsgMap.put(StationVideoEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1010); + client.setMsgname("assignmentstatus"); + mWebMsgMap.put(AssignmentStatusNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1011); + client.setMsgname("stationlocation"); + mWebMsgMap.put(StationLocationChangeNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1012); + client.setMsgname("stationquest"); + mWebMsgMap.put(StationQuestChangeNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1013); + client.setMsgname("stationappversion"); + mWebMsgMap.put(StationAppVersionChangeNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1014); + client.setMsgname("stationinfochange"); + mWebMsgMap.put(StationInfoVerifyNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1015); + client.setMsgname("acbstatus"); + mWebMsgMap.put(ACBStatusNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1016); + client.setMsgname("liquidgagestatus"); + mWebMsgMap.put(LiquidGageSensorNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1017); + client.setMsgname("gasstatus"); + mWebMsgMap.put(GasSensorNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1018); + client.setMsgname("noticestatus"); + mWebMsgMap.put(NoticeStatusNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1019); + client.setMsgname("alerterhost"); + mWebMsgMap.put(AlarmHostEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1020); + client.setMsgname("kickout"); + mWebMsgMap.put(KickOutNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1021); + client.setMsgname("aicamera"); + mWebMsgMap.put(AICameraEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1022); + client.setMsgname("alarmprocessed"); + mWebMsgMap.put(StationAlarmProcessNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1023); + client.setMsgname("aiipcmatchface"); + mWebMsgMap.put(AIIPCMatchFaceEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1024); + client.setMsgname("aiipcmatchface"); + mWebMsgMap.put(AIIPCMatchCarPlateEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1025); + client.setMsgname("aiipcscene"); + mWebMsgMap.put(AIIPCSceneEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1026); + client.setMsgname("sensorline"); + mWebMsgMap.put(SensorLineLinkNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1027); + client.setMsgname("aiipcinvade"); + mWebMsgMap.put(AIIPCInvadeEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1028); + client.setMsgname("pushbutton"); + mWebMsgMap.put(PushButtonEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1029); + client.setMsgname("autolock"); + mWebMsgMap.put(DoorAutoLockEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1030); + client.setMsgname("mucktruckalarm"); + mWebMsgMap.put(MuckTruckEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1031); + client.setMsgname("rfidevent"); + mWebMsgMap.put(RfidEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1032); + client.setMsgname("citymgrtask"); + mWebMsgMap.put(CityMgrTaskNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1033); + client.setMsgname("citymgrcommon"); + mWebMsgMap.put(CityMgrCommonNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1034); + client.setMsgname("citymgrgathering"); + mWebMsgMap.put(CityTruckOrderNofity.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1035); + client.setMsgname("sensoralarm"); + mWebMsgMap.put(SensorEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1036); + client.setMsgname("statistics"); + mWebMsgMap.put(StatisticsDataChangeNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1037); + client.setMsgname("sensor_alarm_update"); + mWebMsgMap.put(SensorEventUpdateNotify.class.getName(), client); + + + client = new MessageToClient(); + client.setMsgcode(1038); + client.setMsgname("school_sign_event"); + mWebMsgMap.put(GuardSignEventNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1039); + client.setMsgname("ys_alarm_event"); + mWebMsgMap.put(YsAlarmNotify.class.getName(), client); + + /* + client = new MessageToClient(); + client.setMsgcode(1040); + client.setMsgname("scheme"); + mWebMsgMap.put(SchemeStartNotify.class.getName(), client); + + */ + + client = new MessageToClient(); + client.setMsgcode(1041); + client.setMsgname("hik_face_event"); + mWebMsgMap.put(HikFaceAlarmNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1042); + client.setMsgname("ai_behavioral_event"); + mWebMsgMap.put(AISophgoNotify.class.getName(), client); + + client = new MessageToClient(); + client.setMsgcode(1043); + client.setMsgname("house_charge_event"); + mWebMsgMap.put(EChargeAlarmNotify.class.getName(), client); + } + + + public void addClient(ClientWebsokectHandler client){ + webSocketSet.add(client); + } + + public void kickOutClient(String session,WebNotifyProperty pro){ + if(session==null) + return ; + for(ClientWebsokectHandler client : webSocketSet){ + if(client!=null){ + if(session.equals(client.getSessionid())){ + KickOutNotify kickout = new KickOutNotify(); + kickout.attachProperty(pro); + kickout.setCause("relogin"); + kickout.setSession(session); + addWebNotify(kickout); + return; + } + } + } + } + + public void removeClient(ClientWebsokectHandler client){ + webSocketSet.remove(client); + } + + + public void addWebNotify(WebNotify notify){ + ConcurrentLinkedQueue notitfylist = mWebNotifyMap.get( notify.getClass().getName()); + if(notitfylist==null){ + notitfylist = new ConcurrentLinkedQueue(); + mWebNotifyMap.put(notify.getClass().getName(),notitfylist); + } + notitfylist.offer(notify); + } + + private void DispachNotify(){ + for(Map.Entry> entry: mWebNotifyMap.entrySet()){ + ConcurrentLinkedQueue queue = entry.getValue(); + + if(queue==null||queue.size()<=0) + continue; + + String notifytype = entry.getKey(); + while(queue.size()>0){ + WebNotify notify = queue.poll(); + for(ClientWebsokectHandler client :webSocketSet){ + client.addNotify(notify); + } + } + + for(ClientWebsokectHandler client :webSocketSet){ + client.dispatchNotify(mWebMsgMap.get(notifytype)); + } + } + } + + private int heartBeatIndex = 0; + private void DispatchHeartBeatToClient(){ + if(serverToClientHB == null){ + serverToClientHB = new MessageToClient(); + serverToClientHB.setMsgcode(501); + serverToClientHB.setMsgname("server.hb"); + serverToClientHB.setMessage("live"); + } + + if(heartBeatIndex < 30){ + heartBeatIndex += 1; + return; + } + + heartBeatIndex = 0; + for(ClientWebsokectHandler client :webSocketSet){ + client.dispatchHeartBeat(serverToClientHB); + } + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/ClientWebsokectHandler.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/ClientWebsokectHandler.java new file mode 100644 index 0000000..5ba2dbd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/ClientWebsokectHandler.java @@ -0,0 +1,671 @@ +package com.jingyi.iotserver.firestationport.websocket; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jingyi.iotserver.clientmanage.ClientLoginController; +import com.jingyi.iotserver.clientmanage.model.OrganiztionUri; +import com.jingyi.iotserver.common.service.RespCode; +import com.jingyi.iotserver.common.service.RespEntity; +import com.jingyi.iotserver.firestationport.model.complexquery.ComplexMutilObject; +import com.jingyi.iotserver.firestationport.model.complexquery.MDevMediaInfo; +import com.jingyi.iotserver.firestationport.model.complexquery.StaionQueryCondition; +import com.jingyi.iotserver.firestationport.model.sensor.GasSensorEventEntity; +import com.jingyi.iotserver.firestationport.model.station.FireStationBaseInfoEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.station.StationRunningInfoEntity; +import com.jingyi.iotserver.firestationport.services.StationServices; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.services.station.StationRuningInfo; +import com.jingyi.iotserver.clientmanage.ClientRuningInfo; +import com.jingyi.iotserver.clientmanage.UserAuthorManager; +import com.jingyi.iotserver.firestationport.websocket.message.*; +import com.jingyi.iotserver.utils.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; +import javax.websocket.*; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + + +//https://blog.csdn.net/w_wensan/article/details/79961379 +//https://blog.csdn.net/zilaike/article/details/78227810 +//https://blog.csdn.net/ZWLJavaWeb/article/details/60126258 + +@ServerEndpoint("/ClientWebSocket") +@Component +public class ClientWebsokectHandler { + private long connectTime = 0; + private boolean checkPass = false; + private Session session; + private String sessionid = null; + @Autowired + UserAuthorManager userAuthorManager; + @Autowired + ClientWebsocketManager clientWebsocketManager; + + @Autowired + FireStationLiveManager fireStationLiveManager; + + @Autowired + StationServices stationServices; + + private DataSource dataSource; + + + + private Vector notifyList = new Vector(); + + public String getSessionid(){ + return sessionid; + } + + private final Logger logger = LoggerFactory.getLogger(ClientLoginController.class); + /** + * 新的WebSocket请求开启 + */ + @OnOpen + public void onOpen(Session session) { + this.session = session; + connectTime = System.currentTimeMillis(); + userAuthorManager = (UserAuthorManager)SpringContextUtil.getBean(UserAuthorManager.class); + dataSource = (DataSource)SpringContextUtil.getBean(DataSource.class); + clientWebsocketManager = (ClientWebsocketManager)SpringContextUtil.getBean(ClientWebsocketManager.class); + fireStationLiveManager = (FireStationLiveManager)SpringContextUtil.getBean(FireStationLiveManager.class); + stationServices = (StationServices)SpringContextUtil.getBean(StationServices.class); + + try { + clientWebsocketManager.addClient(this); + }catch (Exception e){ + e.printStackTrace(); + } + } + + @OnMessage + public void onMessage(String message, Session session) { + System.out.println(message); + try { + JsonNode rootnode = JsonHelper.parseBodyLevel1(message); + int msgcode = JsonHelper.getIntValue(rootnode,"msgcode"); + if(msgcode==100){ + String sessionid = JsonHelper.getStringValue(rootnode,"message"); + if(userAuthorManager.checkSessionActiveUpdate(sessionid)){ + checkPass = true; + this.sessionid = sessionid; + sendMessage("{\"msgcode\":101, \"msgname\":\"connect\",\"message\":\"ok\"}"); + + if(sessionid != null){ + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info != null ){ + logger.info("WebSocket: new client -->" + info.getName()); + } + } + SendStationStatus(); + }else { + sendMessage("{\"msgcode\":101, \"msgname\":\"connect\",\"message\":\"fail\"}"); + clientWebsocketManager.removeClient(this); + } + }else if(msgcode==102){ + getMultiStationSensor(rootnode); + }else if(msgcode==103){ + getMdev(rootnode); + }else if(msgcode==104){ + getStationSensorStatus(rootnode); + } + }catch (Exception e){ + + } + } + + private void getMultiStationSensor(JsonNode rootnode){ + JsonNode stationlist = JsonHelper.getLevel2(rootnode,"message"); + + if(stationlist.isArray()){ + for(int i=0;i 0) { + int index = 0; + List list = null; + do { + list = dev.queryPage(dataSource, null,null,index,500); + index++; + + InfoListMessage infolist = new InfoListMessage(); + infolist.setList(list); + infolist.setCategory(station); + infolist.setPageindex(index-1); + if(i==0&&index==1){ + if(i==stationlist.size()-1&&list.size()<500){ + infolist.setPagepro("start-end"); + }else + infolist.setPagepro("start"); + + }else if(i==stationlist.size()-1&&list.size()<500){ + infolist.setPagepro("end"); + } + + MessageToClient mtc = new MessageToClient (); + mtc.setMsgcode(103); + mtc.setMsgname("station-sensor-list"); + mtc.setMessage(infolist); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(mtc); + sendMessage(json); + + }while(list!=null&&list.size()>=500); + + } + }catch (Exception e){ + + } + } + } + } + + private void getMdev(JsonNode rootnode){ + JsonNode orgurinode = JsonHelper.getLevel2(rootnode,"scope"); + String startstr = JsonHelper.getStringValue(rootnode,"start"); + String endstr = JsonHelper.getStringValue(rootnode,"end"); + + if(orgurinode==null||startstr==null||endstr==null) + return; + + OrganiztionUri uri = (OrganiztionUri)SQLTools.getEntityFromJson(orgurinode, OrganiztionUri.class); + if(uri==null) + return ; + ArrayList stationlist = new ArrayList(); + if(uri.station!=null){ + stationlist.add(uri.getStation()); + }else if(uri.borough!=null){ + FireStationBaseInfoEntity base = new FireStationBaseInfoEntity(); + base.setBorough(uri.getBorough()); + List list = base.queryList(dataSource,null,null); + if(list!=null){ + for(SQLDataObject ob : list){ + FireStationBaseInfoEntity info = (FireStationBaseInfoEntity) ob; + if(info!=null){ + stationlist.add(info.getName()); + } + } + } + }else if(uri.brigade!=null){ + FireStationBaseInfoEntity base = new FireStationBaseInfoEntity(); + base.setBrigade(uri.getBrigade()); + List list = base.queryList(dataSource,null,null); + if(list!=null){ + for(SQLDataObject ob : list){ + FireStationBaseInfoEntity info = (FireStationBaseInfoEntity) ob; + if(info!=null){ + stationlist.add(info.getName()); + } + } + } + } + + ArrayList medialist = new ArrayList(); + for(String name:stationlist){ + if(name==null) + continue; + StaionQueryCondition condi = new StaionQueryCondition(); + condi.setStation(name); + condi.setStart(startstr); + condi.setEnd(endstr); + condi.setPagesize(500); + int index = 0; + + boolean more = true; + do { + more = false; + condi.setPageindex(index); + String rel = HttpTools.getRespFromHttpServer("https://127.0.0.1:8086/mdev/media/getlist", JsonHelper.convertObjectToStr(condi)); + if(rel!=null){ + JsonNode resnode = JsonHelper.parseBodyLevel1(rel); + + if(resnode==null) + break; + + int code = JsonHelper.getIntValue(resnode,"code"); + + JsonNode datanode = JsonHelper.getLevel2(resnode,"data"); + if(code!=0||datanode==null||!datanode.isArray()) + break; + + List list = SQLTools.getEntityListFromJsonArray(datanode,MDevMediaInfo.class); + if(list==null||list.size()<=0) + break; + if(list.size()>=500) + more = true; + + if(list!=null&&list.size()>0){ + medialist.addAll(list); + } + + if(medialist.size()>=500){ + + try { + MessageToClient mtc = new MessageToClient(); + mtc.setMsgcode(104); + mtc.setMsgname("mdev-media-list"); + mtc.setMessage(medialist); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(mtc); + sendMessage(json); + }catch (Exception e){ + + } + medialist.clear(); + } + } + index ++; + }while(more); + + } + + if(medialist.size()>0){ + try { + MessageToClient mtc = new MessageToClient(); + mtc.setMsgcode(104); + mtc.setMsgname("mdev-media-list"); + mtc.setMessage(medialist); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(mtc); + sendMessage(json); + }catch (Exception e){ + + } + medialist.clear(); + } + } + + private void SendStationStatus(){ + + FireStationBaseInfoEntity station = new FireStationBaseInfoEntity(); + + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info==null) + return ; + String scope = info.getScopelevel(); + if(scope==null){ + station = null; + }else if(scope.equals("brigade")){ + station.setBrigade(info.getLevelvalue()); + }else if(scope.equals("borough")){ + station.setBorough(info.getLevelvalue()); + }else if(scope.equals("detachment")){ + station.setDetachment(info.getLevelvalue()); + }else if(scope.equals("station")){ + station.setName(info.getLevelvalue()); + }else + station = null; + int count = stationServices.queryStationCount( station); + if(count<=0) + return; + for(int i=0;i<=count-1/500;i++){ + List stationlist = stationServices.queryStationList(station,500,i); + if(stationlist==null||stationlist.size()<=0) + break; + ArrayList notifys = new ArrayList(); + for(SQLDataObject ob:stationlist){ + FireStationBaseInfoEntity s = (FireStationBaseInfoEntity)ob; + StationRuningInfo srun = fireStationLiveManager.getStationInfo(s.getName()); + + StationStatusChangeNotify notify = new StationStatusChangeNotify(); + notify.setStation(s.getName()); + if(srun==null) { + StationRunningInfoEntity rinfo = fireStationLiveManager.queryStationRunningInfo(s.getName()); + if(rinfo==null) + continue; + + notify.setAppversion(rinfo.appversion); + notify.setState("offline"); + notify.setSignstate("outsign"); + notify.setAlarmstate("noalarm"); + notify.setVideostate("close"); + notify.setLongitude(rinfo.getLongitude()); + notify.setLatitude(rinfo.getLatitude()); + notify.setNewquest(rinfo.getNewquest()); + notify.setRunningquest(rinfo.runningquest); + }else{ + notify.setAppversion(srun.detail.appversion); + notify.setState(srun.detail.state); + notify.setSignstate(srun.detail.signstate); + notify.setAlarmstate(srun.detail.alarmstate); + notify.setVideostate(srun.detail.videostate); + notify.setLongitude(srun.detail.getLongitude()); + notify.setLatitude(srun.detail.getLatitude()); + notify.setNewquest(srun.detail.getNewquest()); + notify.setRunningquest(srun.detail.runningquest); + } + notifys.add(notify); + } + + if(notifys.size()>0){ + MessageToClient client = new MessageToClient(); + client.setMsgcode(1008); + client.setMsgname("stationstatus"); + try { + client.setMessage(notifys); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(client); + sendMessage(json); + client.setMessage(null); + } catch (Exception e) { + + } + } + } + + } + + private void getStationSensorStatus(JsonNode rootnode){ + JsonNode msg = JsonHelper.getLevel2(rootnode,"message"); + if(msg==null) + return; + String station = JsonHelper.getStringValue(msg,"station"); + String category = JsonHelper.getStringValue(msg,"category"); + if(station==null||category==null) + return; + + FireStationBaseInfoEntity st = FireStationBaseInfoEntity.Query(dataSource,station); + if(st==null) + return; + + if(category.equals("gas")){ + List sensors = SensorDeviceEntity.QueryByOwner(dataSource,station); + if(sensors==null) + return; + ArrayList statuslist = new ArrayList(); + GasSensorEventEntity gas = new GasSensorEventEntity(); + for(SensorDeviceEntity s:sensors){ + if(s==null) + continue; + if(s.getDevicetype()==null||!s.getDevicetype().startsWith("gas")) + continue; + gas.setDeviceid(s.getDeviceid()); + GasSensorEventEntity status = (GasSensorEventEntity)gas.QueryLast(dataSource); + if(status!=null) + statuslist.add(status); + + if(statuslist.size()>=500){ + MessageToClient client = new MessageToClient(); + client.setMsgcode(105); + client.setMsgname("station-sensor-last-status"); + SensorStatusListMessage statusmsg = new SensorStatusListMessage(); + statusmsg.setStation(station); + statusmsg.setCategory(category); + statusmsg.setList(statuslist); + try { + client.setMessage(statusmsg); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(client); + sendMessage(json); + client.setMessage(null); + } catch (Exception e) { + + } + statuslist.clear(); + } + } + + if(statuslist.size()>0){ + MessageToClient client = new MessageToClient(); + client.setMsgcode(105); + client.setMsgname("station-sensor-last-status"); + SensorStatusListMessage statusmsg = new SensorStatusListMessage(); + statusmsg.setStation(station); + statusmsg.setCategory(category); + statusmsg.setList(statuslist); + try { + client.setMessage(statusmsg); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(client); + sendMessage(json); + client.setMessage(null); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + /** + * WebSocket请求关闭 + */ + @OnClose + public void onClose() { + if(sessionid != null){ + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info != null ){ + logger.info("WebSocket: client close -->" + info.getName()); + } + } + clientWebsocketManager.removeClient(this); + } + + @OnError + public void onError(Session session, Throwable thr) { + logger.info("WebSocket: error"); + System.out.println("websocket error"); + } + + /* + private boolean checkScope(FireStationBaseInfoEntity station){ + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info==null||station==null) + return false; + + String scope = info.getScopelevel(); + String level = info.getLevelvalue(); + if(scope==null) + return false; + if(scope.equals("master")){ + return true; + } + + if(level==null||station==null) + return false; + if(scope.equals("brigade")){ + if(level.equals(station.getBrigade())) { + return true; + } + return false; + } + + if(scope.equals("borough")){ + if(level.equals(station.getBorough())) { + return true; + } + return false; + } + + if(scope.equals("detachment")){ + if(level.equals(station.getDetachment())) { + return true; + } + return false; + } + + if(scope.equals("station")){ + if(level.equals(station.getName())) { + return true; + } + return false; + } + return false; + } + + */ + + public void sendMessage(String message){ + try{ + session.getBasicRemote().sendText(message); + }catch (IOException ioe){ + + } + } + + public void dispatchMsg(MessageToClient msg,String station){ + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info==null||msg==null||msg.getMessage()==null) + return; + String scope = info.getScopelevel(); + String level = info.getLevelvalue(); + if(scope==null) + return; + String json = null; + try { + ObjectMapper mapper = new ObjectMapper(); + json = mapper.writeValueAsString(msg); + + }catch (Exception e) + { + + } + if(scope.equals("master")){ + sendMessage(json); + return; + } + + if(station==null) + return; + StationRuningInfo from = fireStationLiveManager.getStationInfo(station); + if(level==null||from==null) + return; + if(scope.equals("brigade")){ + if(level.equals(from.brigade)) { + sendMessage(json); + } + return; + } + + if(scope.equals("borough")){ + if(level.equals(from.borough)) { + sendMessage(json); + } + return; + } + + if(scope.equals("detachment")){ + if(level.equals(from.detachment)) { + sendMessage(json); + } + return; + } + if(scope.equals("station")){ + if(level.equals(from.name)) { + sendMessage(json); + } + return; + } + + } + + private boolean checkScope(WebNotify notify){ + WebNotifyProperty pro = notify.obtainProperty(); + if(sessionid==null) + return false; + if(notify instanceof KickOutNotify){ + KickOutNotify nty = (KickOutNotify)notify; + if(nty.getSession()!=null&&nty.getSession().equals(sessionid)) + return true; + else + return false; + } + + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info==null) + return false; + if(pro==null) + return false; + + String scope = info.getScopelevel(); + String level = info.getLevelvalue(); + if(scope==null) + return false; + if(scope.equals("master") || scope.equals("admin")){ + return true; + } + + if(level==null) + return false; + if(scope.equals("brigade")){ + if(level.equals(pro.getBrigade())) { + return true; + } + return false; + } + + if(scope.equals("borough")){ + if(level.equals(pro.getBorough())) { + return true; + } + return false; + } + + if(scope.equals("detachment")){ + if(level.equals(pro.getDetachment())) { + return true; + } + return false; + } + + if(scope.equals("station")){ + if(level.equals(pro.getStation())) { + return true; + } + return false; + } + return false; + } + + public void addNotify(WebNotify notify){ + if(notify.obtainProperty()==null){ + notifyList.add(notify); + return; + } + + if(checkScope(notify)) { + notifyList.add(notify); + } + } + + public void dispatchNotify(MessageToClient mtc){ + if(notifyList==null||notifyList.size()<=0) + return; + + try { + mtc.setMessage(notifyList); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(mtc); + ClientRuningInfo info = userAuthorManager.getUserInfo(sessionid); + if(info != null){ + logger.info("WebSocket: send to client -->" + info.getName()); + // logger.info("WebSocket: send msg -->" + json); + } + + sendMessage(json); + mtc.setMessage(null); + } catch (Exception e) { + + } + notifyList.clear(); + } + + public void dispatchHeartBeat(MessageToClient mtc){ + try { + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(mtc); + sendMessage(json); + } catch (Exception e) { + + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/MessageToClient.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/MessageToClient.java new file mode 100644 index 0000000..97c7568 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/MessageToClient.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.websocket; + +public class MessageToClient { + private int msgcode; + private String msgname; + private Object message; + + public void setMsgcode(int msgcode) { + this.msgcode = msgcode; + } + + public int getMsgcode() { + return msgcode; + } + + public void setMsgname(String msgname) { + this.msgname = msgname; + } + + public String getMsgname(){ + return msgname; + } + + public void setMessage(Object message) { + this.message = message; + } + + public Object getMessage() { + return message; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/WebSocketConfig.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/WebSocketConfig.java new file mode 100644 index 0000000..20e9328 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/WebSocketConfig.java @@ -0,0 +1,14 @@ +package com.jingyi.iotserver.firestationport.websocket; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@Configuration +public class WebSocketConfig { + @Bean + public ServerEndpointExporter serverEndpointExporter (){ + return new ServerEndpointExporter(); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/ACBStatusNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/ACBStatusNotify.java new file mode 100644 index 0000000..43d7ec2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/ACBStatusNotify.java @@ -0,0 +1,60 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class ACBStatusNotify extends WebNotify{ + private String station; + private String devicetype; + private String deviceid; + private String status; //heartbeat alarm + private String info; + private Date timestamp; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setInfo(String info) { + this.info = info; + } + + public String getInfo() { + return info; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AICameraEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AICameraEventNotify.java new file mode 100644 index 0000000..c15bf75 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AICameraEventNotify.java @@ -0,0 +1,145 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class AICameraEventNotify extends WebNotify{ + private String station; + private String devicetype; + private String deviceid; + + private Date reporttime; + + private String deviceip; + private String channelid; + private String channelip; + private int alarmtype; + private String alarmid; + private String alarmtarget; + private String alarmlevel; + private Date timestamp; + private String image; /*big image */ + private String thumbnail; /*small image */ + private String data; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDeviceip(String deviceip) { + this.deviceip = deviceip; + } + + public String getDeviceip() { + return deviceip; + } + + public void setChannelid(String channelid) { + this.channelid = channelid; + } + + public String getChannelid() { + return channelid; + } + + public void setChannelip(String channelip) { + this.channelip = channelip; + } + + public String getChannelip() { + return channelip; + } + + public void setAlarmtype(int alarmtype) { + this.alarmtype = alarmtype; + } + + public int getAlarmtype() { + return alarmtype; + } + + public void setAlarmid(String alarmid) { + this.alarmid = alarmid; + } + + public String getAlarmid() { + return alarmid; + } + + public void setAlarmtarget(String alarmtarget) { + this.alarmtarget = alarmtarget; + } + + public String getAlarmtarget() { + return alarmtarget; + } + + public void setAlarmlevel(String alarmlevel) { + this.alarmlevel = alarmlevel; + } + + public String getAlarmlevel() { + return alarmlevel; + } + + public void setReporttime(Date reporttime) { + this.reporttime = reporttime; + } + + public Date getReporttime() { + return reporttime; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setThumbnail(String thumbnail) { + this.thumbnail = thumbnail; + } + + public String getThumbnail() { + return thumbnail; + } + + public void setData(String data) { + this.data = data; + } + + public String getData() { + return data; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCInvadeEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCInvadeEventNotify.java new file mode 100644 index 0000000..8a97afd --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCInvadeEventNotify.java @@ -0,0 +1,64 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + + + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class AIIPCInvadeEventNotify extends WebNotify{ + private String station; + private String deviceid; + private String picture; + private Date timestamp; + private String type; + private int confidence; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setPicture(String picture) { + this.picture = picture; + } + + public String getPicture() { + return picture; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setConfidence(int confidence) { + this.confidence = confidence; + } + + public int getConfidence() { + return confidence; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCMatchCarPlateEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCMatchCarPlateEventNotify.java new file mode 100644 index 0000000..5236301 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCMatchCarPlateEventNotify.java @@ -0,0 +1,140 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class AIIPCMatchCarPlateEventNotify extends WebNotify{ + + private String deviceid; + + private String devicetype; + private String channel; + + + private long timestamp; + private Date msgtime; + private String event;//match | mismatch | recognize + private String eventid; + private String image; + private int imagestatus; // =0 not upload, =1 uploaded, =2 missed + private String carplate; + + private String brigade; + private String borough; + private String detachment; + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImagestatus(int imagestatus) { + this.imagestatus = imagestatus; + } + + public int getImagestatus() { + return imagestatus; + } + + public void setCarplate(String carplate) { + this.carplate = carplate; + } + + public String getCarplate() { + return carplate; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCMatchFaceEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCMatchFaceEventNotify.java new file mode 100644 index 0000000..6cfef0d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCMatchFaceEventNotify.java @@ -0,0 +1,147 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + + +import java.util.Date; + +public class AIIPCMatchFaceEventNotify extends WebNotify{ + + private String deviceid; + private String devicetype; + private String channel; + + private long timestamp; + + private Date msgtime; + + private String event;//match | mismatch | no-helmet | no-chaf-hat | smoke | calling | no-clothes + + private String eventid; + private String image; + private int imagestatus; // =0 not upload, =1 uploaded, =2 missed + private String staffid; + private String staffname; + private String brigade; + private String borough; + private String detachment; + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImagestatus(int imagestatus) { + this.imagestatus = imagestatus; + } + + public int getImagestatus() { + return imagestatus; + } + + public void setStaffid(String staffid) { + this.staffid = staffid; + } + + public String getStaffid() { + return staffid; + } + + public void setStaffname(String staffname) { + this.staffname = staffname; + } + + public String getStaffname() { + return staffname; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCSceneEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCSceneEventNotify.java new file mode 100644 index 0000000..1612e16 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AIIPCSceneEventNotify.java @@ -0,0 +1,129 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class AIIPCSceneEventNotify extends WebNotify{ + private String deviceid; + + private String devicetype; + private String channel; + + + private long timestamp; + private Date msgtime; + private String event;//fire + private String eventid; + private String image; + private int imagestatus; // =0 not upload, =1 uploaded, =2 missed + + + private String brigade; + private String borough; + private String detachment; + private String station; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getChannel() { + return channel; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setMsgtime(Date msgtime) { + this.msgtime = msgtime; + } + + public Date getMsgtime() { + return msgtime; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventid(String eventid) { + this.eventid = eventid; + } + + public String getEventid() { + return eventid; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setImagestatus(int imagestatus) { + this.imagestatus = imagestatus; + } + + public int getImagestatus() { + return imagestatus; + } + + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AISophgoNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AISophgoNotify.java new file mode 100644 index 0000000..9dfe9ae --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AISophgoNotify.java @@ -0,0 +1,240 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.SophgoMetaData; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.SophgoWarn; +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class AISophgoNotify extends WebNotify{ + + private String warnId; + + private String deviceId; + + private String warnDesc; + + private String warnInfo; + + private String warnName; + + private int warnType; + + private String channelName; + + private int channelNo; + + private long timestamp; + + private Date receiveTime; + + private String personId; + + private String personName; + + private String station; + + private String brigade; + + private String detachment; + + private String borough; + + private double latitude; + + private double longitude; + + private String imageUrl; + + private String imageData; + + + public String getWarnDesc() { + return warnDesc; + } + + public void setWarnDesc(String warnDesc) { + this.warnDesc = warnDesc; + } + + public String getWarnInfo() { + return warnInfo; + } + + public void setWarnInfo(String warnInfo) { + this.warnInfo = warnInfo; + } + + public String getWarnName() { + return warnName; + } + + public void setWarnName(String warnName) { + this.warnName = warnName; + } + + public int getWarnType() { + return warnType; + } + + public void setWarnType(int warnType) { + this.warnType = warnType; + } + + public String getWarnId() { + return warnId; + } + + public void setWarnId(String warnId) { + this.warnId = warnId; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getChannelName() { + return channelName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public int getChannelNo() { + return channelNo; + } + + public void setChannelNo(int channelNo) { + this.channelNo = channelNo; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public Date getReceiveTime() { + return receiveTime; + } + + public void setReceiveTime(Date receiveTime) { + this.receiveTime = receiveTime; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public String getImageData() { + return imageData; + } + + public void setImageData(String imageData) { + this.imageData = imageData; + } + + public boolean setWarnData(SophgoWarn warnData, SophgoMetaData metaData){ + if(warnData != null){ + warnId = warnData.getWarnId(); + deviceId = warnData.getDeviceId(); + warnDesc = warnData.getWarnDesc(); + warnInfo = warnData.getWarnInfo(); + warnName = warnData.getWarnName(); + warnType = warnData.getWarnType(); + channelName = warnData.getChannelName(); + channelNo = warnData.getChannelNo(); + timestamp = warnData.getTimestamp(); + receiveTime = warnData.getReceiveTime(); + personId = warnData.getPersonId(); + personName = warnData.getPersonName(); + station = warnData.getStation(); + brigade = warnData.getBrigade(); + detachment = warnData.getDetachment(); + borough = warnData.getBorough(); + latitude = warnData.getLatitude(); + longitude = warnData.getLongitude(); + imageUrl = warnData.getImageUrl(); + } + + if(metaData != null){ + imageData = metaData.getImage(); + } + return true; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AlarmHostEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AlarmHostEventNotify.java new file mode 100644 index 0000000..d24bad1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AlarmHostEventNotify.java @@ -0,0 +1,284 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class AlarmHostEventNotify extends WebNotify{ + private String station; + private String devicetype; + private String deviceid; + + protected Date timestamp; + + private String id; // alarm id + private String source;// source address--vbox id + private int type; // 1:system; 2:device; 128:device-ex + + private int systemtype; + private int systemaddress; + private int lineaddress; + private int deviceaddress; + private String description; + private int mode; + private int alarm; + private int breakdown; + private int block; + private int supervise; + private int status; + private int response; + private int delay; + private int masterpowerbreak; + private int standbypowerbreak; + private int busbreak; + private int auto; + private int configchanged; + private int reset; + private int devtype; + private String alarmstate; + private String reporttime; + private String acktime; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setSource(String source) { + this.source = source; + } + + public String getSource() { + return source; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public void setSystemtype(int systemtype) { + this.systemtype = systemtype; + } + + public int getSystemtype() { + return systemtype; + } + + public void setSystemaddress(int systemaddress) { + this.systemaddress = systemaddress; + } + + public int getSystemaddress() { + return systemaddress; + } + + public void setLineaddress(int lineaddress) { + this.lineaddress = lineaddress; + } + + public int getLineaddress() { + return lineaddress; + } + + public void setDeviceaddress(int deviceaddress) { + this.deviceaddress = deviceaddress; + } + + public int getDeviceaddress() { + return deviceaddress; + } + + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setMode(int mode) { + this.mode = mode; + } + + public int getMode() { + return mode; + } + + public void setAlarm(int alarm) { + this.alarm = alarm; + } + + public int getAlarm() { + return alarm; + } + + public void setBreakdown(int breakdown) { + this.breakdown = breakdown; + } + + public int getBreakdown() { + return breakdown; + } + + public void setBlock(int block) { + this.block = block; + } + + public int getBlock() { + return block; + } + + public void setSupervise(int supervise) { + this.supervise = supervise; + } + + public int getSupervise() { + return supervise; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getStatus() { + return status; + } + + public void setResponse(int response) { + this.response = response; + } + + public int getResponse() { + return response; + } + + public void setDelay(int delay) { + this.delay = delay; + } + + public int getDelay() { + return delay; + } + + public void setMasterpowerbreak(int masterpowerbreak) { + this.masterpowerbreak = masterpowerbreak; + } + + public int getMasterpowerbreak() { + return masterpowerbreak; + } + + public void setStandbypowerbreak(int standbypowerbreak) { + this.standbypowerbreak = standbypowerbreak; + } + + public int getStandbypowerbreak() { + return standbypowerbreak; + } + + public void setBusbreak(int busbreak) { + this.busbreak = busbreak; + } + + public int getBusbreak() { + return busbreak; + } + + public void setAuto(int auto) { + this.auto = auto; + } + + public int getAuto() { + return auto; + } + + public void setConfigchanged(int configchanged) { + this.configchanged = configchanged; + } + + public int getConfigchanged() { + return configchanged; + } + + public void setReset(int reset) { + this.reset = reset; + } + + public int getReset() { + return reset; + } + + public void setAlarmstate(String alarmstate) { + this.alarmstate = alarmstate; + } + + public String getAlarmstate() { + return alarmstate; + } + + public void setReporttime(String reporttime) { + this.reporttime = reporttime; + } + + public String getReporttime() { + return reporttime; + } + + public void setAcktime(String acktime) { + this.acktime = acktime; + } + + public String getAcktime() { + return acktime; + } + + public void setDevtype(int devtype) { + this.devtype = devtype; + } + + public int getDevtype() { + return devtype; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AssignmentStatusNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AssignmentStatusNotify.java new file mode 100644 index 0000000..9059cc5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/AssignmentStatusNotify.java @@ -0,0 +1,88 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + + +import java.util.Date; + +public class AssignmentStatusNotify extends WebNotify{ + private String assignmentid; + private String brigade; + private String borough; + private String detachment; + private String station; + private Date receivetime; + private Date processtime; + private Date completetime; + private String state;//received processed completed + + public void setAssignmentid(String assignmentid) { + this.assignmentid = assignmentid; + } + + public String getAssignmentid() { + return assignmentid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setReceivetime(Date receivetime) { + this.receivetime = receivetime; + } + + public Date getReceivetime() { + return receivetime; + } + + public void setProcesstime(Date processtime) { + this.processtime = processtime; + } + + public Date getProcesstime() { + return processtime; + } + + public void setCompletetime(Date completetime) { + this.completetime = completetime; + } + + public Date getCompletetime() { + return completetime; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityMgrCommonNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityMgrCommonNotify.java new file mode 100644 index 0000000..60607c5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityMgrCommonNotify.java @@ -0,0 +1,106 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.CityMgrCommonEntity; +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class CityMgrCommonNotify extends WebNotify{ + private String id; + private String type; + private String deviceid; + private String townid; + private String townname; + private String source; + private Date timestamp; + private String data; + private String state; + + public CityMgrCommonNotify(){ + + } + + public CityMgrCommonNotify(CityMgrCommonEntity ccEntity){ + id = ccEntity.getId(); + type = ccEntity.getType(); + deviceid = ccEntity.getDeviceid(); + townid = ccEntity.getTownid(); + townname = ccEntity.getTownname(); + source = ccEntity.getSource(); + timestamp = ccEntity.getTimestamp(); + data = ccEntity.getData(); + state = ccEntity.getState(); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public String getTownid() { + return townid; + } + + public void setTownid(String townid) { + this.townid = townid; + } + + public String getTownname() { + return townname; + } + + public void setTownname(String townname) { + this.townname = townname; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityMgrTaskNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityMgrTaskNotify.java new file mode 100644 index 0000000..44b2509 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityMgrTaskNotify.java @@ -0,0 +1,104 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class CityMgrTaskNotify extends WebNotify{ + private String station; + private String deviceid; + private String taskid; + private String taskname; + private String taskaddress; + private double longitude; + private double latitude; + private Date pushtime; + private Date endtime; + private String taskdescribe; + private String state; // unprocessed | processed + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public String getTaskid() { + return taskid; + } + + public void setTaskname(String taskname) { + this.taskname = taskname; + } + + public String getTaskname() { + return taskname; + } + + public void setTaskaddress(String taskaddress) { + this.taskaddress = taskaddress; + } + + public String getTaskaddress() { + return taskaddress; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setPushtime(Date pushtime) { + this.pushtime = pushtime; + } + + public Date getPushtime() { + return pushtime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + public Date getEndtime() { + return endtime; + } + + public void setTaskdescribe(String taskdescribe) { + this.taskdescribe = taskdescribe; + } + + public String getTaskdescribe() { + return taskdescribe; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityTruckOrderNofity.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityTruckOrderNofity.java new file mode 100644 index 0000000..c51eb6d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/CityTruckOrderNofity.java @@ -0,0 +1,236 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.partner.CityTruckOrderEntity; +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class CityTruckOrderNofity extends WebNotify{ + private String taskid; + private String gatheringaddress; + private int vehiclecount; + private int vehicletimes; + private String alarmtype; + private double longitude; + private double latitude; + private String street; + private String address; + private Date pushtime; + private String source; + private String processor; + private String vehicles; + private Date processtime; + private String status; + private String sceneimage; + private String plateiamge; + private String vehicleimage; + private String description; + private String establish; + private String readstate; + private String deviceid; + + public CityTruckOrderNofity(){ + + } + + public CityTruckOrderNofity(CityTruckOrderEntity truckOrder){ + taskid = truckOrder.getTaskid(); + gatheringaddress = truckOrder.getGatheringaddress(); + vehiclecount = truckOrder.getVehiclecount(); + vehicletimes = truckOrder.getVehicletimes(); + alarmtype = truckOrder.getAlarmtype(); + longitude = truckOrder.getLongitude(); + latitude = truckOrder.getLatitude(); + street = truckOrder.getStreet(); + address = truckOrder.getAddress(); + pushtime = truckOrder.getPushtime(); + source = truckOrder.getSource(); + processor = truckOrder.getProcessor(); + vehicles = truckOrder.getVehicles(); + processtime = truckOrder.getProcesstime(); + status = truckOrder.getStatus(); + sceneimage = truckOrder.getSceneimage(); + plateiamge = truckOrder.getPlateiamge(); + vehicleimage = truckOrder.getVehicleimage(); + description = truckOrder.getDescription(); + establish = truckOrder.getEstablish(); + readstate = truckOrder.getReadstate(); + deviceid = truckOrder.getDeviceid(); + } + + public String getTaskid() { + return taskid; + } + + public void setTaskid(String taskid) { + this.taskid = taskid; + } + + public int getVehiclecount() { + return vehiclecount; + } + + public void setVehiclecount(int vehiclecount) { + this.vehiclecount = vehiclecount; + } + + public int getVehicletimes() { + return vehicletimes; + } + + public void setVehicletimes(int vehicletimes) { + this.vehicletimes = vehicletimes; + } + + public String getGatheringaddress() { + return gatheringaddress; + } + + public void setGatheringaddress(String gatheringaddress) { + this.gatheringaddress = gatheringaddress; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Date getPushtime() { + return pushtime; + } + + public void setPushtime(Date pushtime) { + this.pushtime = pushtime; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getProcessor() { + return processor; + } + + public void setProcessor(String processor) { + this.processor = processor; + } + + public String getVehicles() { + return vehicles; + } + + public void setVehicles(String vehicles) { + this.vehicles = vehicles; + } + + public Date getProcesstime() { + return processtime; + } + + public void setProcesstime(Date processtime) { + this.processtime = processtime; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getSceneimage() { + return sceneimage; + } + + public void setSceneimage(String sceneimage) { + this.sceneimage = sceneimage; + } + + public String getPlateiamge() { + return plateiamge; + } + + public void setPlateiamge(String plateiamge) { + this.plateiamge = plateiamge; + } + + public String getVehicleimage() { + return vehicleimage; + } + + public void setVehicleimage(String vehicleimage) { + this.vehicleimage = vehicleimage; + } + + public String getDescription() { + return description; + } + + public String getEstablish() { + return establish; + } + + public void setEstablish(String establish) { + this.establish = establish; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getReadstate() { + return readstate; + } + + public void setReadstate(String readstate) { + this.readstate = readstate; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/DoorAutoLockEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/DoorAutoLockEventNotify.java new file mode 100644 index 0000000..418168e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/DoorAutoLockEventNotify.java @@ -0,0 +1,51 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class DoorAutoLockEventNotify extends WebNotify{ + private String station; + private String deviceid; + private String devicetype; + protected Date timestamp; + private String sate; //lock | unlock + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setSate(String sate) { + this.sate = sate; + } + + public String getSate() { + return sate; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EChargeAlarmNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EChargeAlarmNotify.java new file mode 100644 index 0000000..853a6b4 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EChargeAlarmNotify.java @@ -0,0 +1,54 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.echarge.EChargeAlarmEntity; +import com.jingyi.iotserver.utils.JPos; +import lombok.Data; + +import java.util.Date; + +@Data +public class EChargeAlarmNotify extends WebNotify{ + private String alarmId; + private String sensorId; + private String alarm; + private Date timestamp; + private String brigade; + private String detachment; + private String borough; + private String station; + private double longitude; + private double latitude; + private double attitude; + private String roomId; + private String roomName; + private String buildingId; + private String buildingName; + private String communityId; + private String communityName; + private String roomUserName; + private String roomUserPhone; + private String roomInfo; + + public EChargeAlarmNotify(EChargeAlarmEntity ysAlarm){ + alarmId = ysAlarm.getAlarmId(); + sensorId = ysAlarm.getSensorId(); + alarm = ysAlarm.getAlarm(); + timestamp = ysAlarm.getTimestamp(); + brigade = ysAlarm.getBrigade(); + detachment = ysAlarm.getDetachment(); + borough = ysAlarm.getBorough(); + station = ysAlarm.getStation(); + longitude = ysAlarm.getLongitude(); + latitude = ysAlarm.getLatitude(); + attitude = ysAlarm.getAttitude(); + roomId = ysAlarm.getRoomId(); + roomName = ysAlarm.getRoomName(); + buildingId = ysAlarm.getBuildingId(); + buildingName = ysAlarm.getBuildingName(); + communityId = ysAlarm.getCommunityId(); + communityName = ysAlarm.getCommunityName(); + roomUserName = ysAlarm.getRoomUserName(); + roomUserPhone = ysAlarm.getRoomUserPhone(); + roomInfo = ysAlarm.getRoomInfo(); + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EarthInductorBuzEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EarthInductorBuzEventNotify.java new file mode 100644 index 0000000..303101f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EarthInductorBuzEventNotify.java @@ -0,0 +1,106 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class EarthInductorBuzEventNotify extends WebNotify{ + private String station; + private int eventid; + private String devicetype; + private String deviceid; + private String buztype; + private Date starttime; + private Date endtime; + private String status; + private String brigade; + private String borough; + private String detachment; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setEventid(int eventid) { + this.eventid = eventid; + } + + public int getEventid() { + return eventid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setBuztype(String buztype) { + this.buztype = buztype; + } + + public String getBuztype() { + return buztype; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + public Date getEndtime() { + return endtime; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EarthInductorNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EarthInductorNotify.java new file mode 100644 index 0000000..ec10e17 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/EarthInductorNotify.java @@ -0,0 +1,60 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class EarthInductorNotify extends WebNotify{ + private String station; + private String devicetype; + private String deviceid; + private String status; //unknown, idle, occupy + private int power; //power + private Date timestamp; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/GasSensorNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/GasSensorNotify.java new file mode 100644 index 0000000..940b3d0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/GasSensorNotify.java @@ -0,0 +1,290 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class GasSensorNotify extends WebNotify{ + + private String station; + private String deviceid; + private String devicetype; + protected Date timestamp; + private String event; + private String status;// + private String alarmtype; // + + private int power; + private double temperature; + private double humidity; + private double tvoc; + private double ch2o;//formaldehyde; + private double co; + private double co2; + private double oxygen; + private double ammonia; + private double hepatic;//h2s + private double chlorine; + private double ex; + private double pm25; + private double pm10; + private int radiosignal; + private double oxygen3; + private int ch4; + private double oilfume; + private double arg0; + private String arg0name; + private double arg1; + private String arg1name; + private double arg2; + private String arg2name; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setTemperature(double temperature) { + this.temperature = temperature; + } + + public double getTemperature() { + return temperature; + } + + public void setHumidity(double humidity) { + this.humidity = humidity; + } + + public double getHumidity() { + return humidity; + } + + public void setTvoc(double tvoc) { + this.tvoc = tvoc; + } + + public double getTvoc() { + return tvoc; + } + + public void setCh2o(double ch2o) { + this.ch2o = ch2o; + } + + public double getCh2o() { + return ch2o; + } + + public void setCo(double co) { + this.co = co; + } + + public double getCo() { + return co; + } + + public void setCo2(double co2) { + this.co2 = co2; + } + + public double getCo2() { + return co2; + } + + public void setOxygen(double oxygen) { + this.oxygen = oxygen; + } + + public double getOxygen() { + return oxygen; + } + + public void setAmmonia(double ammonia) { + this.ammonia = ammonia; + } + + public double getAmmonia() { + return ammonia; + } + + public void setHepatic(double hepatic) { + this.hepatic = hepatic; + } + + public double getHepatic() { + return hepatic; + } + + public void setChlorine(double chlorine) { + this.chlorine = chlorine; + } + + public double getChlorine() { + return chlorine; + } + + public void setEx(double ex) { + this.ex = ex; + } + + public double getEx() { + return ex; + } + + public void setPm25(double pm25) { + this.pm25 = pm25; + } + + public double getPm25() { + return pm25; + } + + public void setPm10(double pm10) { + this.pm10 = pm10; + } + + public double getPm10() { + return pm10; + } + + public void setRadiosignal(int radiosignal) { + this.radiosignal = radiosignal; + } + + public int getRadiosignal() { + return radiosignal; + } + + public void setOxygen3(double oxygen3) { + this.oxygen3 = oxygen3; + } + + public double getOxygen3() { + return oxygen3; + } + + public void setCh4(int ch4) { + this.ch4 = ch4; + } + + public int getCh4() { + return ch4; + } + + public void setOilfume(double oilfume) { + this.oilfume = oilfume; + } + + public double getOilfume() { + return oilfume; + } + + + public void setArg0(double arg0) { + this.arg0 = arg0; + } + + public double getArg0() { + return arg0; + } + + public void setArg0name(String arg0name) { + this.arg0name = arg0name; + } + + public String getArg0name() { + return arg0name; + } + + public void setArg1(double arg1) { + this.arg1 = arg1; + } + + public double getArg1() { + return arg1; + } + + public void setArg1name(String arg1name) { + this.arg1name = arg1name; + } + + public String getArg1name() { + return arg1name; + } + + public void setArg2(double arg2) { + this.arg2 = arg2; + } + + public double getArg2() { + return arg2; + } + + public void setArg2name(String arg2name) { + this.arg2name = arg2name; + } + + public String getArg2name() { + return arg2name; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/GuardSignEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/GuardSignEventNotify.java new file mode 100644 index 0000000..23c4613 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/GuardSignEventNotify.java @@ -0,0 +1,139 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.school.GuardSignEventEntity; +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class GuardSignEventNotify extends WebNotify{ + private String signId; + private String tagId; + private String personId; + private String personName; + private String personType; + private Date signTimestamp; + private String taskId; + private String targetId; + private String station; + private String detachment; + private String borough; + private String brigade; + + public GuardSignEventNotify() { + } + + public GuardSignEventNotify(GuardSignEventEntity signEvent) { + if(signEvent == null){ + return; + } + + signId = signEvent.getSignId(); + tagId = signEvent.getTagId(); + personId = signEvent.getPersonId(); + personName = signEvent.getPersonName(); + personType = signEvent.getPersonType(); + signTimestamp = signEvent.getSignTimestamp(); + taskId = signEvent.getTaskId(); + targetId = signEvent.getTargetId(); + station = signEvent.getStation(); + detachment = signEvent.getDetachment(); + borough = signEvent.getBorough(); + brigade = signEvent.getBrigade(); + } + + public String getTagId() { + return tagId; + } + + public void setTagId(String tagId) { + this.tagId = tagId; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public String getPersonType() { + return personType; + } + + public void setPersonType(String personType) { + this.personType = personType; + } + + public Date getSignTimestamp() { + return signTimestamp; + } + + public void setSignTimestamp(Date signTimestamp) { + this.signTimestamp = signTimestamp; + } + + public String getSignId() { + return signId; + } + + public void setSignId(String signId) { + this.signId = signId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getTargetId() { + return targetId; + } + + public void setTargetId(String targetId) { + this.targetId = targetId; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/HikFaceAlarmNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/HikFaceAlarmNotify.java new file mode 100644 index 0000000..bb78f66 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/HikFaceAlarmNotify.java @@ -0,0 +1,314 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.HikFaceAlarmRecordEntity; +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class HikFaceAlarmNotify extends WebNotify{ + private String alarmId; + private String name; + private String taskId; + private String alarmTime; + private String cameraName; + private String cameraIndexCode; + private double latitude; + private double longitude; + private String snappedPicUrl; + private String bkgPicUrl; + private String bkgPicUrlBak; + private String refrencePicUrl; + private String similarity; + private String personLibId; + private String personLibName; + private String personId; + private String personName; + private int certificateType; + private String certificateTypeName; + private String certificateNumber; + private String registerGender; + private String registerGenderName; + private String station; + private String brigade; + private String detachment; + private String borough; + private Date timestamp; + private String readState; + private String pointCode; + private String schools; + + + public HikFaceAlarmNotify(HikFaceAlarmRecordEntity alarmEntity) { + this.alarmId = alarmEntity.getAlarmId(); + this.name = alarmEntity.getName(); + this.taskId = alarmEntity.getTaskId(); + this.alarmTime = alarmEntity.getAlarmTime(); + this.cameraName = alarmEntity.getCameraName(); + this.cameraIndexCode = alarmEntity.getCameraIndexCode(); + this.latitude = alarmEntity.getLatitude(); + this.longitude = alarmEntity.getLongitude(); + this.snappedPicUrl = alarmEntity.getSnappedPicUrl(); + this.bkgPicUrl = alarmEntity.getBkgPicUrl(); + this.bkgPicUrlBak = alarmEntity.getBkgPicUrlBak(); + this.refrencePicUrl = alarmEntity.getRefrencePicUrl(); + this.similarity = alarmEntity.getSimilarity(); + this.personLibId = alarmEntity.getPersonLibId(); + this.personLibName = alarmEntity.getPersonLibName(); + this.personId = alarmEntity.getPersonId(); + this.personName = alarmEntity.getPersonName(); + this.certificateType = alarmEntity.getCertificateType(); + this.certificateTypeName = alarmEntity.getCertificateTypeName(); + this.certificateNumber = alarmEntity.getCertificateNumber(); + this.registerGender = alarmEntity.getRegisterGender(); + this.registerGenderName = alarmEntity.getRegisterGenderName(); + this.station = alarmEntity.getStation(); + this.brigade = alarmEntity.getBrigade(); + this.detachment = alarmEntity.getDetachment(); + this.borough = alarmEntity.getBorough(); + this.timestamp = alarmEntity.getTimestamp(); + this.readState = alarmEntity.getReadState(); + this.pointCode = alarmEntity.getPointCode(); + this.schools = alarmEntity.getSchools(); + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getAlarmId() { + return alarmId; + } + + public void setAlarmId(String alarmId) { + this.alarmId = alarmId; + } + + public String getAlarmTime() { + return alarmTime; + } + + public void setAlarmTime(String alarmTime) { + this.alarmTime = alarmTime; + } + + public String getCameraName() { + return cameraName; + } + + public void setCameraName(String cameraName) { + this.cameraName = cameraName; + } + + public String getCameraIndexCode() { + return cameraIndexCode; + } + + public void setCameraIndexCode(String cameraIndexCode) { + this.cameraIndexCode = cameraIndexCode; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getSnappedPicUrl() { + return snappedPicUrl; + } + + public void setSnappedPicUrl(String snappedPicUrl) { + this.snappedPicUrl = snappedPicUrl; + } + + public String getBkgPicUrl() { + return bkgPicUrl; + } + + public void setBkgPicUrl(String bkgPicUrl) { + this.bkgPicUrl = bkgPicUrl; + } + + public String getBkgPicUrlBak() { + return bkgPicUrlBak; + } + + public void setBkgPicUrlBak(String bkgPicUrlBak) { + this.bkgPicUrlBak = bkgPicUrlBak; + } + + public String getRefrencePicUrl() { + return refrencePicUrl; + } + + public void setRefrencePicUrl(String refrencePicUrl) { + this.refrencePicUrl = refrencePicUrl; + } + + public String getSimilarity() { + return similarity; + } + + public void setSimilarity(String similarity) { + this.similarity = similarity; + } + + public String getPersonLibId() { + return personLibId; + } + + public void setPersonLibId(String personLibId) { + this.personLibId = personLibId; + } + + public String getPersonLibName() { + return personLibName; + } + + public void setPersonLibName(String personLibName) { + this.personLibName = personLibName; + } + + public String getPersonId() { + return personId; + } + + public void setPersonId(String personId) { + this.personId = personId; + } + + public String getPersonName() { + return personName; + } + + public void setPersonName(String personName) { + this.personName = personName; + } + + public int getCertificateType() { + return certificateType; + } + + public void setCertificateType(int certificateType) { + this.certificateType = certificateType; + } + + public String getCertificateTypeName() { + return certificateTypeName; + } + + public void setCertificateTypeName(String certificateTypeName) { + this.certificateTypeName = certificateTypeName; + } + + public String getCertificateNumber() { + return certificateNumber; + } + + public void setCertificateNumber(String certificateNumber) { + this.certificateNumber = certificateNumber; + } + + public String getRegisterGender() { + return registerGender; + } + + public void setRegisterGender(String registerGender) { + this.registerGender = registerGender; + } + + public String getRegisterGenderName() { + return registerGenderName; + } + + public void setRegisterGenderName(String registerGenderName) { + this.registerGenderName = registerGenderName; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getReadState() { + return readState; + } + + public void setReadState(String readState) { + this.readState = readState; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getPointCode() { + return pointCode; + } + + public void setPointCode(String pointCode) { + this.pointCode = pointCode; + } + + public String getSchools() { + return schools; + } + + public void setSchools(String schools) { + this.schools = schools; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/InfoListMessage.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/InfoListMessage.java new file mode 100644 index 0000000..346b3b3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/InfoListMessage.java @@ -0,0 +1,42 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.List; + +public class InfoListMessage { + public List list; + public String category; + public int pageindex; + public String pagepro; // start end + + public void setList(List list) { + this.list = list; + } + + public List getList() { + return list; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getCategory() { + return category; + } + + public void setPageindex(int pageindex) { + this.pageindex = pageindex; + } + + public int getPageindex() { + return pageindex; + } + + public void setPagepro(String pagepro) { + this.pagepro = pagepro; + } + + public String getPagepro() { + return pagepro; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/KickOutNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/KickOutNotify.java new file mode 100644 index 0000000..2a2dc93 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/KickOutNotify.java @@ -0,0 +1,21 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class KickOutNotify extends WebNotify{ + private String cause; + private String session; + public void setCause(String cause) { + this.cause = cause; + } + + public String getCause() { + return cause; + } + + public void setSession(String session) { + this.session = session; + } + + public String getSession() { + return session; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/LineLinkNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/LineLinkNotify.java new file mode 100644 index 0000000..0437dd8 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/LineLinkNotify.java @@ -0,0 +1,33 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class LineLinkNotify extends WebNotify{ + private String station; + private String state;//online or offline + private Date linktime; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setLinktime(Date linktime) { + this.linktime = linktime; + } + + public Date getLinktime() { + return linktime; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/LiquidGageSensorNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/LiquidGageSensorNotify.java new file mode 100644 index 0000000..ce5cb41 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/LiquidGageSensorNotify.java @@ -0,0 +1,105 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class LiquidGageSensorNotify extends WebNotify{ + private String station; + private String deviceid; + private String devicetype; + protected Date timestamp; + private String status;//normal | alarm; + private String alarmtype; //out1high | out1low | low power | outrange | out2high | out2low + private double gage; + private String unit;//mH2O cmH2O mmH2O mHg cmHg mmHg inchHg + private double vantage;//v + private int power; //percent % + private int radiosignal; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setGage(double gage) { + this.gage = gage; + } + + public double getGage() { + return gage; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getUnit() { + return unit; + } + + public void setVantage(double vantage) { + this.vantage = vantage; + } + + public double getVantage() { + return vantage; + } + + public void setRadiosignal(int radiosignal) { + this.radiosignal = radiosignal; + } + + public int getRadiosignal() { + return radiosignal; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/MuckTruckEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/MuckTruckEventNotify.java new file mode 100644 index 0000000..1723683 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/MuckTruckEventNotify.java @@ -0,0 +1,124 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class MuckTruckEventNotify extends WebNotify{ + private String station; + private String deviceid; + private String devicetype; + protected Date timestamp; + + private String event;//heartbeat | alarm; + private String eventname; + private String platenumber; + private String companyname; + private String bidarea; + private Date geoindata; + private Date geoinfencedata; + private String fencetype; + private Date geooutfencedata; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getEvent() { + return event; + } + + public void setEventname(String eventname) { + this.eventname = eventname; + } + + public String getEventname() { + return eventname; + } + + public void setPlatenumber(String platenumber) { + this.platenumber = platenumber; + } + + public String getPlatenumber() { + return platenumber; + } + + public void setCompanyname(String companyname) { + this.companyname = companyname; + } + + public String getCompanyname() { + return companyname; + } + + public void setBidarea(String bidarea) { + this.bidarea = bidarea; + } + + public String getBidarea() { + return bidarea; + } + + public void setGeoindata(Date geoindata) { + this.geoindata = geoindata; + } + + public Date getGeoindata() { + return geoindata; + } + + public void setGeoinfencedata(Date geoinfencedata) { + this.geoinfencedata = geoinfencedata; + } + + public Date getGeoinfencedata() { + return geoinfencedata; + } + + public void setFencetype(String fencetype) { + this.fencetype = fencetype; + } + + public String getFencetype() { + return fencetype; + } + + public void setGeooutfencedata(Date geooutfencedata) { + this.geooutfencedata = geooutfencedata; + } + + public Date getGeooutfencedata() { + return geooutfencedata; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/NoticeStatusNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/NoticeStatusNotify.java new file mode 100644 index 0000000..e82efae --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/NoticeStatusNotify.java @@ -0,0 +1,44 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class NoticeStatusNotify extends WebNotify{ + + private String noticeid; + private String station; + private Date readtime; + private String state;//sent read + + + public void setNoticeid(String noticeid) { + this.noticeid = noticeid; + } + + public String getNoticeid() { + return noticeid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setReadtime(Date readtime) { + this.readtime = readtime; + } + + public Date getReadtime() { + return readtime; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/PipePressureSensorNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/PipePressureSensorNotify.java new file mode 100644 index 0000000..1ef7a0e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/PipePressureSensorNotify.java @@ -0,0 +1,105 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class PipePressureSensorNotify extends WebNotify{ + private String station; + private String deviceid; + private String devicetype; + protected Date timestamp; + private String status;//normal | alarm; + private String alarmtype; //out1high | out1low | low power | outrange | out2high | out2low + private double pressure; + private String unit;//Pa | hPa | kPa | MPa | bar | mbar | PSI | Torr | ATM | mmHg + private double vantage;//v + private int power; //percent % + private int radiosignal; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setAlarmtype(String alarmtype) { + this.alarmtype = alarmtype; + } + + public String getAlarmtype() { + return alarmtype; + } + + public void setPressure(double pressure) { + this.pressure = pressure; + } + + public double getPressure() { + return pressure; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getUnit() { + return unit; + } + + public void setVantage(double vantage) { + this.vantage = vantage; + } + + public double getVantage() { + return vantage; + } + + public void setRadiosignal(int radiosignal) { + this.radiosignal = radiosignal; + } + + public int getRadiosignal() { + return radiosignal; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/PushButtonEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/PushButtonEventNotify.java new file mode 100644 index 0000000..cf449c6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/PushButtonEventNotify.java @@ -0,0 +1,78 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class PushButtonEventNotify extends WebNotify{ + private String station; + private String deviceid; + private String devicetype; + protected Date timestamp; + private String alarmstate; + private String readstate; + protected Date readtime; + + private String alarmPointData; + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setAlarmstate(String alarmstate) { + this.alarmstate = alarmstate; + } + + public String getAlarmstate() { + return alarmstate; + } + + public void setReadstate(String readstate) { + this.readstate = readstate; + } + + public String getReadstate() { + return readstate; + } + public void setReadtime(Date readtime) { + this.readtime = readtime; + } + + public Date getReadtime() { + return readtime; + } + + public String getAlarmPointData() { + return alarmPointData; + } + + public void setAlarmPointData(String alarmPointData) { + this.alarmPointData = alarmPointData; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/RfidEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/RfidEventNotify.java new file mode 100644 index 0000000..62b8f15 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/RfidEventNotify.java @@ -0,0 +1,94 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + + + +import java.util.Date; + +public class RfidEventNotify extends WebNotify{ + private String rfdid; + private String owner; + private String station; + + protected Date firsttimestamp; + private String rfidreader; + private int antid; + private String status; + private String alarm; + private String community; + + public void setRfdid(String rfdid) { + this.rfdid = rfdid; + } + + public String getRfdid() { + return rfdid; + } + + + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOwner() { + return owner; + } + + + public void setRfidreader(String rfidreader) { + this.rfidreader = rfidreader; + } + + public String getRfidreader() { + return rfidreader; + } + + public int getAntid() { + return antid; + } + + public void setAntid(int antid) { + this.antid = antid; + } + + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setFirsttimestamp(Date firsttimestamp) { + this.firsttimestamp = firsttimestamp; + } + + public Date getFirsttimestamp() { + return firsttimestamp; + } + + public void setAlarm(String alarm) { + this.alarm = alarm; + } + + public String getAlarm() { + return alarm; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setCommunity(String community) { + this.community = community; + } + + public String getCommunity() { + return community; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorEventNotify.java new file mode 100644 index 0000000..4970874 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorEventNotify.java @@ -0,0 +1,190 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorAlarmEventEntity; + +import java.text.SimpleDateFormat; + +public class SensorEventNotify extends WebNotify{ + + private String eventId; + private String deviceId; + private String devicetype; + private String state; + private String timestamp; + private String alarmSource; + private String alarmType; + private String alarmCode; + private String eventData; + private String address; + private double longitude; + private double latitude; + private String subAddress; + private String brigade; + private String borough; + private String detachment; + private String station; + + public SensorEventNotify(){ + + } + + public SensorEventNotify(SensorAlarmEventEntity alarmEvent){ + eventId = alarmEvent.getEventId(); + deviceId = alarmEvent.getDeviceId(); + devicetype = alarmEvent.getDevicetype(); + alarmSource = alarmEvent.getAlarmSource(); + address = alarmEvent.getAddress(); + latitude = alarmEvent.getLatitude(); + longitude = alarmEvent.getLongitude(); + subAddress = alarmEvent.getSubAddress(); + if(alarmEvent.getTimestamp() != null){ + SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + timestamp = formater.format(alarmEvent.getTimestamp()); + } + + alarmType = alarmEvent.getAlarmType(); + alarmCode = alarmEvent.getAlarmCode(); + state = alarmEvent.getState(); + eventData = alarmEvent.getEventData(); + station = alarmEvent.getStation(); + brigade = alarmEvent.getBrigade(); + borough = alarmEvent.getBorough(); + detachment = alarmEvent.getDetachment(); + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getEventId() { + return eventId; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getTimestamp() { + return timestamp; + } + + public String getAlarmSource() { + return alarmSource; + } + + public void setAlarmSource(String alarmSource) { + this.alarmSource = alarmSource; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public String getAlarmCode() { + return alarmCode; + } + + public void setAlarmCode(String alarmCode) { + this.alarmCode = alarmCode; + } + + public String getEventData() { + return eventData; + } + + public void setEventData(String eventData) { + this.eventData = eventData; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public String getSubAddress() { + return subAddress; + } + + public void setSubAddress(String subAddress) { + this.subAddress = subAddress; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorEventUpdateNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorEventUpdateNotify.java new file mode 100644 index 0000000..f4b3f85 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorEventUpdateNotify.java @@ -0,0 +1,193 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.event.ProcessAlarmEventOpRecord; + +import java.util.Date; + +public class SensorEventUpdateNotify extends WebNotify{ + + private String recordId; + private String eventId; + private String operation; + private String operator; + private String operatortype; + private String operatordevice; + private String operatordevicetype; + private String previousState; + private Date timestamp; + private String receiver; + private double longitude; + private double latitude; + private String comment; + private String newState; + private String brigade; + private String borough; + private String detachment; + private String station; + + public SensorEventUpdateNotify(){ + + } + + public SensorEventUpdateNotify(ProcessAlarmEventOpRecord opRecord){ + recordId = opRecord.getRecordId(); + eventId = opRecord.getEventId(); + operation = opRecord.getOperation(); + operator = opRecord.getOperator(); + operatortype = opRecord.getOperatortype(); + operatordevice = opRecord.getOperatordevice(); + operatordevicetype = opRecord.getOperatordevicetype(); + previousState = opRecord.getPreviousState(); + timestamp = opRecord.getTimestamp(); + receiver = opRecord.getReceiver(); + longitude = opRecord.getLongitude(); + latitude = opRecord.getLatitude(); + comment = opRecord.getComment(); + newState = opRecord.getNewState(); + + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getEventId() { + return eventId; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getOperation() { + return operation; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setOperatortype(String operatortype) { + this.operatortype = operatortype; + } + + public String getOperatortype() { + return operatortype; + } + + public void setOperatordevice(String operatordevice) { + this.operatordevice = operatordevice; + } + + public String getOperatordevice() { + return operatordevice; + } + + public void setOperatordevicetype(String operatordevicetype) { + this.operatordevicetype = operatordevicetype; + } + + public String getOperatordevicetype() { + return operatordevicetype; + } + + public void setPreviousState(String previousState) { + this.previousState = previousState; + } + + public String getPreviousState() { + return previousState; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getReceiver() { + return receiver; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public String getNewState() { + return newState; + } + + public void setNewState(String newState) { + this.newState = newState; + } + + public String getRecordId() { + return recordId; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorLineLinkNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorLineLinkNotify.java new file mode 100644 index 0000000..142304e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorLineLinkNotify.java @@ -0,0 +1,52 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class SensorLineLinkNotify extends WebNotify{ + private String devicetype; + private String deviceid; + private String station; + private String state;//online or offline + private Date linktime; + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setLinktime(Date linktime) { + this.linktime = linktime; + } + + public Date getLinktime() { + return linktime; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorStatusListMessage.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorStatusListMessage.java new file mode 100644 index 0000000..cc18108 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SensorStatusListMessage.java @@ -0,0 +1,33 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.List; + +public class SensorStatusListMessage { + private String station; + private String category; + private List list; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getCategory() { + return category; + } + + public void setList(List list) { + this.list = list; + } + + public List getList() { + return list; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SignNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SignNotify.java new file mode 100644 index 0000000..36778ba --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SignNotify.java @@ -0,0 +1,33 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class SignNotify extends WebNotify{ + private String station; + private Date signtime; + private String state; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setSigntime(Date signtime) { + this.signtime = signtime; + } + + public Date getSigntime() { + return signtime; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SmokingBuzEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SmokingBuzEventNotify.java new file mode 100644 index 0000000..660fc5d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SmokingBuzEventNotify.java @@ -0,0 +1,103 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class SmokingBuzEventNotify extends WebNotify{ + private String station; + private int eventid; + private String devicetype; + private String deviceid; + private String buztype; + private Date starttime; + private Date endtime; + private String status; + private String brigade; + private String borough; + private String detachment; + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setEventid(int eventid) { + this.eventid = eventid; + } + + public int getEventid() { + return eventid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setBuztype(String buztype) { + this.buztype = buztype; + } + + public String getBuztype() { + return buztype; + } + + public void setStarttime(Date starttime) { + this.starttime = starttime; + } + + public Date getStarttime() { + return starttime; + } + + public void setEndtime(Date endtime) { + this.endtime = endtime; + } + + public Date getEndtime() { + return endtime; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SmokingSensorNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SmokingSensorNotify.java new file mode 100644 index 0000000..4d0f86c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/SmokingSensorNotify.java @@ -0,0 +1,60 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class SmokingSensorNotify extends WebNotify{ + private String station; + private String devicetype; + private String deviceid; + private String status; //unknown, normal, alarm, broken + private int power; //power + private Date timestamp; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setPower(int power) { + this.power = power; + } + + public int getPower() { + return power; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAlarmNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAlarmNotify.java new file mode 100644 index 0000000..e98ebf2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAlarmNotify.java @@ -0,0 +1,89 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.utils.JPos; + +import java.util.Date; + +public class StationAlarmNotify extends WebNotify{ + private String station; + private String alarmid ; + private Date timestamp; + private double longitude ; + private double latitude ; + private String address; + private String sender; + private String phone; + private String type; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setAlarmid(String alarmid) { + this.alarmid = alarmid; + } + + public String getAlarmid() { + return alarmid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAddress() { + return address; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getPhone() { + return phone; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAlarmProcessNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAlarmProcessNotify.java new file mode 100644 index 0000000..4a2b7a2 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAlarmProcessNotify.java @@ -0,0 +1,32 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class StationAlarmProcessNotify extends WebNotify{ + private String station; + private String alarmid ; + private Date timestamp; + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setAlarmid(String alarmid) { + this.alarmid = alarmid; + } + + public String getAlarmid() { + return alarmid; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAppVersionChangeNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAppVersionChangeNotify.java new file mode 100644 index 0000000..5d52f18 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationAppVersionChangeNotify.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class StationAppVersionChangeNotify extends WebNotify{ + public String station; + public String appversion; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setAppversion(String appversion) { + this.appversion = appversion; + } + + public String getAppversion() { + return appversion; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationInfoVerifyNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationInfoVerifyNotify.java new file mode 100644 index 0000000..be4509b --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationInfoVerifyNotify.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class StationInfoVerifyNotify extends WebNotify{ + private String station; + private String infotype; //equipment | staff | external + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setInfotype(String infotype) { + this.infotype = infotype; + } + + public String getInfotype() { + return infotype; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationLocationChangeNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationLocationChangeNotify.java new file mode 100644 index 0000000..0d1243d --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationLocationChangeNotify.java @@ -0,0 +1,30 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class StationLocationChangeNotify extends WebNotify{ + private String station; + private double longitude ; + private double latitude ; + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationQuestChangeNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationQuestChangeNotify.java new file mode 100644 index 0000000..1946783 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationQuestChangeNotify.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class StationQuestChangeNotify extends WebNotify{ + public String station; + public String newquest; + public String runningquest; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setRunningquest(String runningquest) { + this.runningquest = runningquest; + } + + public String getRunningquest() { + return runningquest; + } + + public void setNewquest(String newquest) { + this.newquest = newquest; + } + + public String getNewquest() { + return newquest; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationStatusChangeNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationStatusChangeNotify.java new file mode 100644 index 0000000..e3a38b9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationStatusChangeNotify.java @@ -0,0 +1,96 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class StationStatusChangeNotify extends WebNotify{ + public String station; + public String state;//online or offline + public String signstate; + public String alarmstate; + public String videostate; + + public String appversion; + public String newquest; + public String runningquest; + + private double longitude ; + private double latitude ; + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setSignstate(String signstate) { + this.signstate = signstate; + } + + public String getSignstate() { + return signstate; + } + + public void setAlarmstate(String alarmstate) { + this.alarmstate = alarmstate; + } + + public String getAlarmstate() { + return alarmstate; + } + + public void setVideostate(String videostate) { + this.videostate = videostate; + } + + public String getVideostate() { + return videostate; + } + + public void setAppversion(String appversion) { + this.appversion = appversion; + } + + public String getAppversion() { + return appversion; + } + + public void setNewquest(String newquest) { + this.newquest = newquest; + } + + public String getNewquest() { + return newquest; + } + + public void setRunningquest(String runningquest) { + this.runningquest = runningquest; + } + + public String getRunningquest() { + return runningquest; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationVideoEventNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationVideoEventNotify.java new file mode 100644 index 0000000..e2066cf --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StationVideoEventNotify.java @@ -0,0 +1,32 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import java.util.Date; + +public class StationVideoEventNotify extends WebNotify{ + private String station; + private String state; + private Date timestamp; + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setState(String state) { + this.state = state; + } + + public String getState() { + return state; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public Date getTimestamp() { + return timestamp; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StatisticsDataChangeNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StatisticsDataChangeNotify.java new file mode 100644 index 0000000..bc12860 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/StatisticsDataChangeNotify.java @@ -0,0 +1,71 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.utils.JPos; + +public class StatisticsDataChangeNotify extends WebNotify{ + + private String station; + private String detachment; + private String borough; + private String brigade; + + private String stationData; + private String boroughData; + private String brigadeData; + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getDetachment() { + return detachment; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getBorough() { + return borough; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBrigade() { + return brigade; + } + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getStationData() { + return stationData; + } + + public void setStationData(String stationData) { + this.stationData = stationData; + } + + public String getBoroughData() { + return boroughData; + } + + public void setBoroughData(String boroughData) { + this.boroughData = boroughData; + } + + public String getBrigadeData() { + return brigadeData; + } + + public void setBrigadeData(String brigadeData) { + this.brigadeData = brigadeData; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/WebNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/WebNotify.java new file mode 100644 index 0000000..b0b5f3c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/WebNotify.java @@ -0,0 +1,14 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +public class WebNotify { + + private WebNotifyProperty property; + + public void attachProperty(WebNotifyProperty pro){ + property = pro; + } + + public WebNotifyProperty obtainProperty(){ + return property; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/WebNotifyProperty.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/WebNotifyProperty.java new file mode 100644 index 0000000..55333f6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/WebNotifyProperty.java @@ -0,0 +1,67 @@ +package com.jingyi.iotserver.firestationport.websocket.message;; + +public class WebNotifyProperty { + private String brigade; + private String borough; + private String detachment; + private String station; + private String device_id; + private String device_type; + private String notifyflag; + + public void setBrigade(String brigade) { + this.brigade = brigade; + } + + public String getBrigade() { + return brigade; + } + + public void setBorough(String borough) { + this.borough = borough; + } + + public String getBorough() { + return borough; + } + + public void setDetachment(String detachment) { + this.detachment = detachment; + } + + public String getDetachment() { + return detachment; + } + + public void setStation(String station) { + this.station = station; + } + + public String getStation() { + return station; + } + + public void setDevice_id(String device_id) { + this.device_id = device_id; + } + + public String getDevice_id() { + return device_id; + } + + public void setDevice_type(String device_type) { + this.device_type = device_type; + } + + public String getDevice_type() { + return device_type; + } + + public void setNotifyflag(String notifyflag) { + this.notifyflag = notifyflag; + } + + public String getNotifyflag() { + return notifyflag; + } +} diff --git a/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/YsAlarmNotify.java b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/YsAlarmNotify.java new file mode 100644 index 0000000..b864046 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/firestationport/websocket/message/YsAlarmNotify.java @@ -0,0 +1,89 @@ +package com.jingyi.iotserver.firestationport.websocket.message; + +import com.jingyi.iotserver.firestationport.model.sensor.ys.YsAlarmEntity; +import com.jingyi.iotserver.utils.JPos; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class YsAlarmNotify extends WebNotify{ + private String messageId; + private String messageType; + private String deviceId; + private String receiveTime; + private String alarmType; + private String channelName; + private String pictureUrl; + + public YsAlarmNotify(){ + + } + public YsAlarmNotify(YsAlarmEntity ysAlarm){ + messageId = ysAlarm.getMessageId(); + messageType = ysAlarm.getMessageType(); + deviceId = ysAlarm.getDeviceId(); + + String format = "yyyy-MM-dd HH:mm:ss"; + receiveTime = new SimpleDateFormat(format).format(ysAlarm.getReceiveTime()); + alarmType = ysAlarm.getAlarmType(); + channelName = ysAlarm.getChannelName(); + pictureUrl = ysAlarm.getPictureUrl(); + } + + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getReceiveTime() { + return receiveTime; + } + + public void setReceiveTime(String receiveTime) { + this.receiveTime = receiveTime; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public String getChannelName() { + return channelName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public String getPictureUrl() { + return pictureUrl; + } + + public void setPictureUrl(String pictureUrl) { + this.pictureUrl = pictureUrl; + } +} diff --git a/src/main/java/com/jingyi/iotserver/iotctrl/AIIPCPackParser.java b/src/main/java/com/jingyi/iotserver/iotctrl/AIIPCPackParser.java new file mode 100644 index 0000000..86a46b6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/iotctrl/AIIPCPackParser.java @@ -0,0 +1,358 @@ +package com.jingyi.iotserver.iotctrl; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.firestationport.model.sensor.SensorDeviceEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCMatchCarPlateEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCMatchFaceEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCSceneEventEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.AIIPCStatusEntity; +import com.jingyi.iotserver.firestationport.model.sensor.event.SensorEventEntity; +import com.jingyi.iotserver.firestationport.model.station.MessageToStation; +import com.jingyi.iotserver.firestationport.services.sensor.SensorRunInfoManager; +import com.jingyi.iotserver.firestationport.services.station.FireStationLiveManager; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.firestationport.websocket.message.AIIPCMatchCarPlateEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.AIIPCMatchFaceEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.AIIPCSceneEventNotify; +import com.jingyi.iotserver.firestationport.websocket.message.WebNotifyProperty; +import com.jingyi.iotserver.jpush.JpushClientUtil; +import com.jingyi.iotserver.utils.GUIDUtil; +import com.jingyi.iotserver.utils.JsonHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.Date; + +@Service +public class AIIPCPackParser { + @Autowired + private DataSource dataSource; + @Autowired + IoTCtrlServer mServer; + @Autowired + SensorRunInfoManager sensorRunInfoManager; + @Autowired + private FireStationLiveManager fireStationLiveManager; + @Autowired + private FireStationLiveManager stationLiveManager; + @Autowired + private ClientWebsocketManager clientWebsocketManager; + + public void Parse(JsonNode root){ + String msgname = JsonHelper.getStringValue(root,"msgname"); + String msgtype = JsonHelper.getStringValue(root,"msgtype"); + String deviceid = JsonHelper.getStringValue(root,"id"); + String devicetype = JsonHelper.getStringValue(root,"devicetype"); + long timestamp = JsonHelper.getLongValue(root,"timestamp"); + /* + if(msgtype!=null&&!msgtype.equals("response")) { + IoTCtrlMessage iotmsg = new IoTCtrlMessage(); + iotmsg.setDeviceid("123456"); + iotmsg.setDevicetype("jygas3"); + iotmsg.setTimestamp(System.currentTimeMillis() / 1000); + iotmsg.setMsgname("config"); + iotmsg.setMsgtype("response"); + iotmsg.setMessage("config ok"); + iotmsg.setTimestamp(timestamp); + String cmd = JsonHelper.convertObjectToStr(iotmsg); + byte[] str = cmd.getBytes(); + mServer.SendDataToIotCtrl(str); + } +*/ + SensorDeviceEntity sensor = SensorDeviceEntity.Query(dataSource,deviceid); + if(sensor!=null){ + sensorRunInfoManager.setSensorActive(sensor); + }else + return; + if(msgtype.equals("notify")||msgtype.equals("noify")){ + if(msgname.equals("heartbeat")){ + + }else if(msgname.equals("status")){ + JsonNode data = JsonHelper.getLevel2(root,"data"); + if(data==null) + return; + String channel = JsonHelper.getStringValue(data,"channel"); + int personcount = JsonHelper.getIntValue(data,"personcount"); + if(channel==null||channel.length()<=0) + return; + AIIPCStatusEntity status = new AIIPCStatusEntity(); + status.setDeviceid(deviceid); + status.setChannel(channel); + status.setMsgtime(new Date(timestamp)); + status.setTimestamp(timestamp); + status.setBrigade(sensor.getBrigade()); + status.setBorough(sensor.getBorough()); + status.setDetachment(sensor.getDetachment()); + status.setStation(sensor.getOwner()); + status.setPersoncount(personcount); + + if(status.QueryIt(dataSource)==null){ + status.Insert(dataSource); + } + + }else if(msgname.equals("match-face-event")){ + JsonNode data = JsonHelper.getLevel2(root,"data"); + if(data==null) + return; + String channel = JsonHelper.getStringValue(data,"channel"); + String ev = JsonHelper.getStringValue(data,"event"); + String evid = JsonHelper.getStringValue(data,"eventid"); + String image = JsonHelper.getStringValue(data,"image"); + String staffid = JsonHelper.getStringValue(data,"staffid"); + String staffname = JsonHelper.getStringValue(data,"staffname"); + if(channel==null||channel.length()<=0|| + ev==null||ev.length()<=0) + return; + AIIPCMatchFaceEventEntity event = new AIIPCMatchFaceEventEntity(); + event.setDeviceid(deviceid); + event.setChannel(channel); + event.setMsgtime(new Date(timestamp)); + event.setTimestamp(timestamp); + event.setBrigade(sensor.getBrigade()); + event.setBorough(sensor.getBorough()); + event.setDetachment(sensor.getDetachment()); + event.setStation(sensor.getOwner()); + event.setEvent(ev); + event.setEventid(evid); + event.setStaffid(staffid); + event.setStaffname(staffname); + event.setImage(image); + + if(event.QueryIt(dataSource)==null){ + event.Insert(dataSource); + } + + SensorEventEntity se = null; + se = new SensorEventEntity(); + if(ev.equals("match")) + se.setEvent("ai.face.facematch"); + else if(ev.equals("mismatch")) + se.setEvent("ai.face.facenotmatch"); + else + se.setEvent("ai.unknown"); + generateSensorEvent(se,event.getMsgtime(),sensor); + + AIIPCMatchFaceEventNotify notify = new AIIPCMatchFaceEventNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(devicetype); + + notify.setChannel(channel); + notify.setMsgtime(event.getMsgtime()); + notify.setTimestamp(timestamp); + notify.setBrigade(sensor.getBrigade()); + notify.setBorough(sensor.getBorough()); + notify.setDetachment(sensor.getDetachment()); + notify.setStation(sensor.getOwner()); + notify.setEvent(ev); + notify.setEventid(evid); + notify.setStaffid(staffid); + notify.setStaffname(staffname); + notify.setImage(image); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(event.getBrigade()); + pro.setBorough(event.getBorough()); + pro.setDetachment(event.getDetachment()); + pro.setStation(event.getStation()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + + //send notify to client + clientWebsocketManager.addWebNotify(notify); + try { + // if(status.equals("alarm")) + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("aiipcmatchface"); + msg.setData(event); + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + } + }catch (Exception e){ + + } + }else if(msgname.equals("match-carplate-event")){ + JsonNode data = JsonHelper.getLevel2(root,"data"); + if(data==null) + return; + String channel = JsonHelper.getStringValue(data,"channel"); + String ev = JsonHelper.getStringValue(data,"event"); + String evid = JsonHelper.getStringValue(data,"eventid"); + String image = JsonHelper.getStringValue(data,"image"); + String carplate = JsonHelper.getStringValue(data,"carplate"); + + if(channel==null||channel.length()<=0|| + ev==null||ev.length()<=0) + return; + AIIPCMatchCarPlateEventEntity event = new AIIPCMatchCarPlateEventEntity(); + event.setDeviceid(deviceid); + event.setChannel(channel); + event.setMsgtime(new Date(timestamp)); + event.setTimestamp(timestamp); + event.setBrigade(sensor.getBrigade()); + event.setBorough(sensor.getBorough()); + event.setDetachment(sensor.getDetachment()); + event.setStation(sensor.getOwner()); + event.setEvent(ev); + event.setEventid(evid); + event.setCarplate(carplate); + event.setImage(image); + + if(event.QueryIt(dataSource)==null){ + event.Insert(dataSource); + } + SensorEventEntity se = null; + se = new SensorEventEntity(); + if(ev.equals("recognize-match")) + se.setEvent("ai.vehicle.recognize.match"); + else if(ev.equals("recognize-mismatch")) + se.setEvent("ai.vehicle.recognize.mismatch"); + else + se.setEvent("ai.unknown"); + generateSensorEvent(se,event.getMsgtime(),sensor); + + + AIIPCMatchCarPlateEventNotify notify = new AIIPCMatchCarPlateEventNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(devicetype); + + notify.setChannel(channel); + notify.setMsgtime(event.getMsgtime()); + notify.setTimestamp(timestamp); + notify.setBrigade(sensor.getBrigade()); + notify.setBorough(sensor.getBorough()); + notify.setDetachment(sensor.getDetachment()); + notify.setStation(sensor.getOwner()); + notify.setEvent(ev); + notify.setEventid(evid); + notify.setCarplate(event.getCarplate()); + notify.setImage(image); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(event.getBrigade()); + pro.setBorough(event.getBorough()); + pro.setDetachment(event.getDetachment()); + pro.setStation(event.getStation()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + + //send notify to client + clientWebsocketManager.addWebNotify(notify); + try { + // if(status.equals("alarm")) + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("aiipcmatchcarplate"); + msg.setData(event); + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + } + }catch (Exception e){ + + } + + }else if(msgname.equals("scene-event")){ + JsonNode data = JsonHelper.getLevel2(root,"data"); + if(data==null) + return; + String channel = JsonHelper.getStringValue(data,"channel"); + String ev = JsonHelper.getStringValue(data,"event"); + String evid = JsonHelper.getStringValue(data,"eventid"); + String image = JsonHelper.getStringValue(data,"image"); + + if(channel==null||channel.length()<=0|| + ev==null||ev.length()<=0) + return; + AIIPCSceneEventEntity event = new AIIPCSceneEventEntity(); + event.setDeviceid(deviceid); + event.setChannel(channel); + event.setMsgtime(new Date(timestamp)); + event.setTimestamp(timestamp); + event.setBrigade(sensor.getBrigade()); + event.setBorough(sensor.getBorough()); + event.setDetachment(sensor.getDetachment()); + event.setStation(sensor.getOwner()); + event.setEvent(ev); + event.setEventid(evid); + + event.setImage(image); + + if(event.QueryIt(dataSource)==null){ + event.Insert(dataSource); + } + + SensorEventEntity se = null; + se = new SensorEventEntity(); + if(ev.equals("fire")) + se.setEvent("ai.fire"); + else + se.setEvent("ai.unknown"); + generateSensorEvent(se,event.getMsgtime(),sensor); + + AIIPCSceneEventNotify notify = new AIIPCSceneEventNotify(); + notify.setDeviceid(event.getDeviceid()); + notify.setDevicetype(devicetype); + + notify.setChannel(channel); + notify.setMsgtime(event.getMsgtime()); + notify.setTimestamp(timestamp); + notify.setBrigade(sensor.getBrigade()); + notify.setBorough(sensor.getBorough()); + notify.setDetachment(sensor.getDetachment()); + notify.setStation(sensor.getOwner()); + notify.setEvent(ev); + notify.setEventid(evid); + notify.setImage(image); + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(event.getBrigade()); + pro.setBorough(event.getBorough()); + pro.setDetachment(event.getDetachment()); + pro.setStation(event.getStation()); + pro.setDevice_id(notify.getDeviceid()); + pro.setDevice_type(notify.getDevicetype()); + notify.attachProperty(pro); + + //send notify to client + clientWebsocketManager.addWebNotify(notify); + try { + // if(status.equals("alarm")) + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("aiipcscene"); + msg.setData(event); + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + } + }catch (Exception e){ + + } + } + }else if(msgtype.equals("response")){ + if(msgname.equals("upload-image")){ + + } + } + } + + private void generateSensorEvent(SensorEventEntity se, Date timestamp, SensorDeviceEntity sensor){ + if(se!=null){ + se.setDeviceid(sensor.getDeviceid()); + se.setDevicetype(sensor.getDevicetype()); + se.setBrigade(sensor.getBrigade()); + se.setBorough(sensor.getBorough()); + se.setDetachment(sensor.getDetachment()); + se.setStation(sensor.getOwner()); + se.setState("created"); + se.setTimestamp(timestamp); + se.setEventid(GUIDUtil.GenreralScerect(se.getDeviceid()+se.getDevicetype()+se.getTimestamp().getTime())); + + se.Insert(dataSource); + + if(fireStationLiveManager.IsStaionOnline( sensor.getOwner())) { + MessageToStation msg = new MessageToStation(); + msg.setMessage("sensor-event-notify"); + msg.setData(se); + JpushClientUtil.sendMessageToDevice("firectrl", sensor.getOwner(), "iot", JsonHelper.convertObjectToStr(msg), 0); + + } + } + } +} diff --git a/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlMessage.java b/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlMessage.java new file mode 100644 index 0000000..c860c7f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlMessage.java @@ -0,0 +1,63 @@ +package com.jingyi.iotserver.iotctrl; + +public class IoTCtrlMessage { + private long timestamp; + + private String deviceid; + + private String devicetype; + + private String msgname; + + private String msgtype;// request | response | noify + + private Object message; + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getTimestamp() { + return timestamp; + } + + public void setDeviceid(String deviceid) { + this.deviceid = deviceid; + } + + public String getDeviceid() { + return deviceid; + } + + public void setDevicetype(String devicetype) { + this.devicetype = devicetype; + } + + public String getDevicetype() { + return devicetype; + } + + public void setMsgname(String msgname) { + this.msgname = msgname; + } + + public String getMsgname() { + return msgname; + } + + public void setMsgtype(String msgtype) { + this.msgtype = msgtype; + } + + public String getMsgtype() { + return msgtype; + } + + public void setMessage(Object message) { + this.message = message; + } + + public Object getMessage() { + return message; + } +} diff --git a/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlOnUDPHandle.java b/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlOnUDPHandle.java new file mode 100644 index 0000000..7a6068f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlOnUDPHandle.java @@ -0,0 +1,46 @@ +package com.jingyi.iotserver.iotctrl; + +import com.fasterxml.jackson.databind.JsonNode; +import com.jingyi.iotserver.utils.JsonHelper; +import com.jingyi.iotserver.utils.SpringContextUtil; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.socket.DatagramPacket; + +import java.net.InetSocketAddress; + +public class IoTCtrlOnUDPHandle extends SimpleChannelInboundHandler { + IoTCtrlServer mServer; + AIIPCPackParser aiipcPackParser = null; + public IoTCtrlOnUDPHandle(IoTCtrlServer server){ + mServer = server; + aiipcPackParser = (AIIPCPackParser) SpringContextUtil.getBean(AIIPCPackParser.class); + } + @Override + protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception{ + ByteBuf buf = (ByteBuf) packet.copy().content(); + byte[] data = new byte[buf.readableBytes()]; + buf.readBytes(data); + InetSocketAddress addr = packet.sender(); + + System.out.println("rcv microstation data length:"+data.length+" ip:"+addr.getHostString()); + + try{ + String msg = new String(data,"UTF-8"); + JsonNode root = JsonHelper.parseBodyLevel1(msg); + + String devicetype = JsonHelper.getStringValue(root,"devicetype"); + + if(devicetype.equals("aicamera")||devicetype.equals("aiipc")||devicetype.equals("aismartbox")){ + aiipcPackParser.Parse(root); + } + }catch (Exception e){ + + } + + buf.release(); + + } + +} diff --git a/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlServer.java b/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlServer.java new file mode 100644 index 0000000..b15117f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/iotctrl/IoTCtrlServer.java @@ -0,0 +1,146 @@ +package com.jingyi.iotserver.iotctrl; + +import com.alibaba.fastjson2.JSON; +import com.jingyi.iotserver.utils.HttpTools; +import io.netty.bootstrap.Bootstrap; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.DatagramPacket; +import io.netty.channel.socket.nio.NioDatagramChannel; +import org.springframework.stereotype.Service; + +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; + +@Service +public class IoTCtrlServer { + + Channel udpChannel = null; + final int iotPort = 6014; + Bootstrap boot = null; + public void startServer(int port)throws InterruptedException{ + + boot = new Bootstrap(); + EventLoopGroup group = new NioEventLoopGroup(); + IoTCtrlOnUDPHandle handler = new IoTCtrlOnUDPHandle(this); + + boot.group(group).channel(NioDatagramChannel.class).handler(handler); + udpChannel = boot.bind(port).sync().channel(); + } + + public boolean SendData(byte[] data, String ip,int port){ + InetSocketAddress address = new InetSocketAddress(ip, port); + + if(udpChannel==null) + return false; + + if(udpChannel==null||data==null||ip==null) + return true; + System.out.println("IoTCtrlServer send udp data: "+ ip + ":" + port); + udpChannel.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(data),address)); + return true; + } + + public boolean SendDataToIotCtrl(byte [] data){ + return SendData(data,"127.0.0.1",iotPort); + } + + public void translateHttp2Skynet(int nType, String sPayload, String sUrl){ + try { + httpAgentIntoSkynet(sUrl,sPayload ); + }catch (Exception e){ + } + } + + public void translateHttp2Internet(int nType, String sPayload, String sUrl){ + try { + httpAgentIntoInternet(sUrl,sPayload ); + }catch (Exception e){ + } + } + + public void translateHttp2InternetUdp(int nType, String sPayload){ + UDPAgentPackage agentPackage = new UDPAgentPackage(); + agentPackage.setType(nType); + agentPackage.setPayload(sPayload); + try { + String strAgent = JSON.toJSONString(agentPackage); + byte[] bytes = strAgent.getBytes("utf-8"); + //SendData( bytes, "43.15.207.65", 8090); + SendData( bytes, "43.15.50.9", 8090); + }catch (Exception e){ + + } + } + + private void httpAgentIntoSkynet(String agentUrl, String payload){ + new Thread(){ + public void run(){ + HttpURLConnection connLogin; + try { + // String agentUrlLong = "http://192.168.10.241:8083" + agentUrl ; + String agentUrlLong = "http://10.8.0.2:8083" + agentUrl ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(payload); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("httpAgentIntoSkynet: fail = " + responseCode); + }else{ + System.out.println("httpAgentIntoSkynet: ok = " + responseCode); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("httpAgentIntoSkynet: fail = " + e.getMessage()); + }finally { + + } + } + }.start(); + } + + private void httpAgentIntoInternet(String agentUrl, String payload){ + new Thread(){ + public void run(){ + HttpURLConnection connLogin; + try { + //String agentUrlLong = "http://43.15.207.65:8083" + agentUrl ; + String agentUrlLong = "http://43.15.50.9:8083" + agentUrl ; + System.out.println("process http into inner: url = " + agentUrlLong); + connLogin = HttpTools.createHttpConnection(agentUrlLong); + connLogin.setRequestMethod("POST"); + connLogin.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connLogin.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connLogin.getOutputStream(), "UTF-8")); + writer.write(payload); + writer.close(); + + int responseCode = connLogin.getResponseCode(); + if(responseCode != HttpURLConnection.HTTP_OK){ + System.out.println("httpAgentIntoSkynet: fail = " + responseCode); + }else{ + System.out.println("httpAgentIntoSkynet: ok = " + responseCode); + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println("httpAgentIntoSkynet: fail = " + e.getMessage()); + }finally { + + } + } + }.start(); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/iotctrl/UDPAgentMQTTMessage.java b/src/main/java/com/jingyi/iotserver/iotctrl/UDPAgentMQTTMessage.java new file mode 100644 index 0000000..b0f3099 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/iotctrl/UDPAgentMQTTMessage.java @@ -0,0 +1,23 @@ +package com.jingyi.iotserver.iotctrl; + +public class UDPAgentMQTTMessage { + private String topic; + private String message; + + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/jingyi/iotserver/iotctrl/UDPAgentPackage.java b/src/main/java/com/jingyi/iotserver/iotctrl/UDPAgentPackage.java new file mode 100644 index 0000000..ed98d9c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/iotctrl/UDPAgentPackage.java @@ -0,0 +1,44 @@ +package com.jingyi.iotserver.iotctrl; + +public class UDPAgentPackage { + + public static final int TYPE_ACK = 999; + public static final int TYPE_MDEV_HB = 1; + public static final int TYPE_MDEV_Alarm = 2; + public static final int TYPE_MDEV_MQTT = 3; + public static final int TYPE_School_Check = 4; + public static final int TYPE_School_StarDetail = 5; + public static final int TYPE_School_ColorDetail = 6; + public static final int TYPE_Http_Agent = 7; + public static final int TYPE_IOT_Agent = 8; + + private int type; + private String payload; + + private String agentUrl; + + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public String getAgentUrl() { + return agentUrl; + } + + public void setAgentUrl(String agentUrl) { + this.agentUrl = agentUrl; + } +} diff --git a/src/main/java/com/jingyi/iotserver/jpush/JpushClientUtil.java b/src/main/java/com/jingyi/iotserver/jpush/JpushClientUtil.java new file mode 100644 index 0000000..80eecd3 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/jpush/JpushClientUtil.java @@ -0,0 +1,154 @@ +package com.jingyi.iotserver.jpush; + +import cn.jpush.api.JPushClient; +import cn.jpush.api.push.PushResult; +import cn.jpush.api.push.model.Message; +import cn.jpush.api.push.model.Platform; +import cn.jpush.api.push.model.PushPayload; +import cn.jpush.api.push.model.audience.Audience; +import cn.jpush.api.push.model.notification.Notification; + +public class JpushClientUtil { + static final String vehicle_appKey = "180f088ac94144f14511c717"; + static final String vehicle_masterSecret = "310335065070d4fac14581ea"; + + static final String firectrl_appKey = "c6ea93f0c100bc9987c52b72"; + static final String firectrl_masterSecret = "955ab7da5f771a09cda5be6a"; + + static final String eye_appKey = "df127960da45d9a977f0f5a9"; + static final String eye_masterSecret = "6d6646c643a2a6ac4a0ebe3d"; + + static final String gtalk_appKey = "86caf7b502dac8e491afbfdb"; + static final String gtalk_masterSecret = "ffe7b83dbea6415b53b075dc"; + + private final static String appKey = firectrl_appKey; + private final static String masterSecret = firectrl_masterSecret; + + private static String getAppKey(String app){ + if(app==null) + return appKey; + + if(app.equals("vehicle")){ + return vehicle_appKey; + }else if(app.equals("firectrl")){ + return firectrl_appKey; + }else if(app.equals("eye")){ + return eye_appKey; + }else if(app.equals("gtalk")){ + return gtalk_appKey; + }else + return appKey; + } + + private static String getMasterSecret(String app){ + if(app==null) + return masterSecret; + + if(app.equals("vehicle")){ + return vehicle_masterSecret; + }else if(app.equals("firectrl")){ + return firectrl_masterSecret; + }else if(app.equals("eye")){ + return eye_masterSecret; + }else if(app.equals("gtalk")){ + return eye_masterSecret; + }else + return masterSecret; + } + + public static void sendNotifyToDevice(String app,String alias,String title,String content,int timeToLive){ + JPushClient jpush = new JPushClient(getMasterSecret(app), getAppKey(app), timeToLive); + PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all()) + .setAudience(Audience.alias(alias))//向指定的组推送 + .setNotification(Notification.android(content, title, null)).build(); + try { + jpush.sendPush(payload); + }catch (Exception e){ + e.printStackTrace(); + } + } + + public static void sendNotifyToGroup(String app,String tag,String title,String content,int timeToLive){ + JPushClient jpush = new JPushClient(getMasterSecret(app), getAppKey(app), timeToLive); + PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all()) + .setAudience(Audience.tag(tag))//向指定的组推送 + .setNotification(Notification.android(content, title, null)).build(); + try { + jpush.sendPush(payload); + }catch (Exception e){ + e.printStackTrace(); + } + } + + public static void sendNotifyToAll(String app,String title,String content,int timeToLive){ + JPushClient jpush = new JPushClient(getMasterSecret(app), getAppKey(app), timeToLive); + PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all()) + .setAudience(Audience.all())//向指定的组推送 + .setNotification(Notification.android(content, title, null)).build(); + try { + PushResult rel = jpush.sendPush(payload); + System.out.println(rel.toString()); + }catch (Exception e){ + e.printStackTrace(); + } + } + + public static void sendMessageToDevice(String app,String alias,String title,String content,int timeToLive){ + + /* + JPushClient jpush = new JPushClient(getMasterSecret(app), getAppKey(app),false, timeToLive); + PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all()) + .setAudience(Audience.alias(alias))//向指定的组推送 + .setMessage(Message.newBuilder() + .setMsgContent(content) + .setTitle(title).build()).build(); + long cur = System.currentTimeMillis(); + try { + + jpush.sendPush(payload); + + }catch (Exception e){ + // e.printStackTrace(); + } + System.out.println("jpush send msg usetine: "+((System.currentTimeMillis()-cur)/1000)); + + */ + } + + public static void sendMessageToGroup(String app,String tag,String title,String content,int timeToLive){ + /* + JPushClient jpush = new JPushClient(getMasterSecret(app), getAppKey(app),false, timeToLive); + PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all()) + .setAudience(Audience.tag(tag))//向指定的组推送 + .setMessage(Message.newBuilder() + .setMsgContent(content) + .setTitle(title).build()).build(); + long cur = System.currentTimeMillis(); + try { + jpush.sendPush(payload); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("jpush send msg usetine: "+((System.currentTimeMillis()-cur)/1000)); + + */ + } + + public static void sendMessageToAll(String app,String title,String content,int timeToLive){ + /* + JPushClient jpush = new JPushClient(getMasterSecret(app), getAppKey(app), timeToLive); + PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all()) + .setAudience(Audience.all())//向指定的组推送 + .setMessage(Message.newBuilder() + .setMsgContent(content) + .setTitle(title).build()).build(); + try { + PushResult rel = jpush.sendPush(payload); + System.out.println(rel.toString()); + }catch (Exception e){ + e.printStackTrace(); + } + + */ + } +} diff --git a/src/main/java/com/jingyi/iotserver/mqtt/MQTTMessage.java b/src/main/java/com/jingyi/iotserver/mqtt/MQTTMessage.java new file mode 100644 index 0000000..7393835 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/mqtt/MQTTMessage.java @@ -0,0 +1,22 @@ +package com.jingyi.iotserver.mqtt; + +public class MQTTMessage { + public String topic; + public byte[] message; + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getTopic(){ + return topic; + } + + public void setMessage(byte[] message) { + this.message = message; + } + + public byte[] getMessage() { + return message; + } +} diff --git a/src/main/java/com/jingyi/iotserver/mqtt/MessagePublisher.java b/src/main/java/com/jingyi/iotserver/mqtt/MessagePublisher.java new file mode 100644 index 0000000..cf889b1 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/mqtt/MessagePublisher.java @@ -0,0 +1,233 @@ +package com.jingyi.iotserver.mqtt; + +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.services.SensorService; +import com.jingyi.iotserver.iotctrl.UDPAgentPackage; +import org.eclipse.paho.client.mqttv3.*; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.*; +import java.net.InetAddress; +import java.util.Enumeration; +import java.util.Properties; +import java.util.concurrent.ConcurrentLinkedQueue; + +@Service +public class MessagePublisher { + //String HOST = "tcp://139.196.241.53:1883"; + String HOST = "tcp://101.89.199.154:1883"; + private boolean blConnected = false; + + @Autowired + private SensorService sensorService; + + private MqttClient client = null; + private MqttConnectOptions options; + private Thread scanservice = null; + ConcurrentLinkedQueue mMsgQueue = new ConcurrentLinkedQueue(); + public void init() + { + readHostAddress(); + scanservice = new Thread(){ + public void run(){ + while(true){ + if(client == null){ + createClient(); + } + if(!blConnected) { + tryConnectServer(); + } + if(!blConnected) { + try{ + Thread.sleep(60*1000); + }catch (Exception e){ + } + continue; + } + + try { + if(blConnected&&mMsgQueue.size()>0){ + publish(); + } + }catch (Exception e){ + } + + try{ + Thread.sleep(1*1000); + }catch (Exception e){ + + } + } + } + }; + + scanservice.start(); + } + + public String getMqttAddress(){ + return HOST; + } + + public void readHostAddress() { + File file = new File("config.properties"); + System.out.println(file.exists()); + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + //实例化Properties类 + Properties p = new Properties(); + // 读取列表 + p.load(fis); + + //枚举器(Hashtable Vector) 迭代器 + /*Enumeration keys = p.keys(); + while (keys.hasMoreElements()){ + String key = (String) keys.nextElement(); + System.out.println(key + " = " + p.getProperty(key) ); + }*/ + String hostAddress = p.getProperty("mqtt",""); + if(hostAddress.length() > 0){ + HOST = hostAddress; + System.out.println("配置MQTT服务器地址成功: " + HOST); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void createClient(){ + try { + client = new MqttClient(HOST, "firectrl"+getLocalIp(), new MemoryPersistence()); + // MQTT的连接设置 + options = new MqttConnectOptions(); + // 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接 + options.setCleanSession(true); + // 设置连接的用户名 + options.setUserName(null); + // 设置连接的密码 + options.setPassword(null);//passWord.toCharArray() + // 设置超时时间 单位为秒 + options.setConnectionTimeout(10); + // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送个消息判断客户端是否在线,但这个方法并没有重连的机制 + options.setKeepAliveInterval(20); + // 设置回调 + client.setCallback(new MqttCallbackExtended(){ + @Override + public void connectComplete(boolean b, String s) { + System.out.println("连接成功"); + // subscribeTopic(); + } + + public void connectionLost(Throwable cause) { + // 连接丢失后,一般在这里面进行重连 + System.out.println("连接断开,做重连*********************************"); + blConnected = false; + } + + public void deliveryComplete(IMqttDeliveryToken token) { + System.out.println("deliveryComplete---------" + token.isComplete()); + } + + public void messageArrived(String topic, MqttMessage message) throws Exception { + // subscribe后得到的消息会执行到这里面 + System.out.println("接收消息主题 : " + topic); + System.out.println("接收消息Qos : " + message.getQos()); + System.out.println("接收消息内容 : " + new String(message.getPayload())); + } + }); + return ; + }catch (Exception e){ + } + } + + public void subscribeTopic(){ + try { + client.subscribe("jingyou/face/#", new IMqttMessageListener() { + @Override + public void messageArrived(String topic, MqttMessage message) throws Exception { + System.out.println("2接收消息主题 : " + topic); + //System.out.println("2接收消息Qos : " + message.getQos()); + String payloadFace = new String(message.getPayload(), "UTF-8"); + //System.out.println("2接收消息内容 : " + payloadFace); + sensorService.addEntranceAIFaceMessage(payloadFace); + } + }); + } catch (MqttException e) { + e.printStackTrace(); + } + } + + public void tryConnectServer(){ + try { + client.connect(options); + blConnected = true; + System.out.println("连接成功" + HOST); + return ; + }catch (Exception e){ + } + blConnected = false; + System.out.println("连接失败,做重连*********************************"); + } + + private void publish(){ + MQTTMessage msg = null; + int count = 0; + do { + msg = mMsgQueue.poll(); + if(msg==null) + return; + MqttMessage message = new MqttMessage(); + + message.setQos(0); + message.setRetained(false); + message.setPayload(msg.getMessage()); + try { + client.publish(msg.topic, message); + count++; + }catch (Exception e){ + e.printStackTrace(); + } + }while(msg!=null&&count<50); + } + + public void sendMessage(String receiver,String msg) + { + + MQTTMessage m = new MQTTMessage(); + try { + m.topic = receiver; + m.message = msg.getBytes();//("UTF-8"); + mMsgQueue.add(m); + }catch (Exception e){ + + } + } + + public void sendMessage(String receiver,byte[] msg) + { + MQTTMessage m = new MQTTMessage(); + try { + m.topic = receiver; + m.message = msg;//("UTF-8"); + mMsgQueue.add(m); + }catch (Exception e){ + + } + } + + public String getLocalIp(){ + try { + InetAddress inetAddress = InetAddress.getLocalHost(); + String ip = inetAddress.getHostAddress().toString();//获得本机Ip + + return ip; + }catch (Exception e){ + + } + return ""+Math.random(); + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/AESUtil.java b/src/main/java/com/jingyi/iotserver/utils/AESUtil.java new file mode 100644 index 0000000..59de1fe --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/AESUtil.java @@ -0,0 +1,61 @@ +package com.jingyi.iotserver.utils; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +public class AESUtil { + private static final String IV_STRING = "2020dgfsfDf60422";//"sdf4ddfsFD86Vdf2"; + private static final String encoding = "UTF-8"; + + public static String encryptAES(String content, String key) + throws InvalidKeyException, NoSuchAlgorithmException, + NoSuchPaddingException, UnsupportedEncodingException, + InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { + byte[] byteContent = content.getBytes(encoding); + // 注意,为了能与 iOS 统一 + // 这里的 key 不可以使用 KeyGenerator、SecureRandom、SecretKey 生成 + byte[] enCodeFormat = key.getBytes(encoding); + SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES"); + byte[] initParam = IV_STRING.getBytes(encoding); + IvParameterSpec ivParameterSpec = new IvParameterSpec(initParam); + // 指定加密的算法、工作模式和填充方式 + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); + byte[] encryptedBytes = cipher.doFinal(byteContent); + // 同样对加密后数据进行 base64 编码 + String base64 = Base64.getEncoder().encodeToString(encryptedBytes); + //进行url编码 去掉= ? & + + return base64;//URLEncoder.encode(base64,encoding); + } + + public static String decryptAES(String content, String key) + throws InvalidKeyException, NoSuchAlgorithmException, + NoSuchPaddingException, InvalidAlgorithmParameterException, + IllegalBlockSizeException, BadPaddingException, IOException { + //URL解码 + // content = URLDecoder.decode(content,encoding); + + // base64 解码 + byte[] encryptedBytes = Base64.getDecoder().decode(content); + byte[] enCodeFormat = key.getBytes(encoding); + SecretKeySpec secretKey = new SecretKeySpec(enCodeFormat, "AES"); + byte[] initParam = IV_STRING.getBytes(encoding); + IvParameterSpec ivParameterSpec = new IvParameterSpec(initParam); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec); + byte[] result = cipher.doFinal(encryptedBytes); + return new String(result, encoding); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/GUIDUtil.java b/src/main/java/com/jingyi/iotserver/utils/GUIDUtil.java new file mode 100644 index 0000000..1f78a47 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/GUIDUtil.java @@ -0,0 +1,18 @@ +package com.jingyi.iotserver.utils; + + +import java.util.UUID; + +public class GUIDUtil { + static public String GeneralAppkey(){ + UUID uuid = UUID.randomUUID(); + String appkey = uuid.toString(); + return appkey; + } + + static public String GenreralScerect(String appkey){ + String mw = "firectrl" + appkey ; + String app_sign = MD5Tools.md5(mw);// 得到以后还要用MD5加密。 + return app_sign; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/Gps.java b/src/main/java/com/jingyi/iotserver/utils/Gps.java new file mode 100644 index 0000000..2208c19 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/Gps.java @@ -0,0 +1,31 @@ +package com.jingyi.iotserver.utils; + +public class Gps { + private double wgLat; + private double wgLon; + + public Gps(){ + + } + + public Gps(double wgLat, double wgLon) { + this.wgLat = wgLat; + this.wgLon = wgLon; + } + + public double getWgLat() { + return wgLat; + } + + public void setWgLat(double wgLat) { + this.wgLat = wgLat; + } + + public double getWgLon() { + return wgLon; + } + + public void setWgLon(double wgLon) { + this.wgLon = wgLon; + } +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/utils/HikvisionAPI.java b/src/main/java/com/jingyi/iotserver/utils/HikvisionAPI.java new file mode 100644 index 0000000..f9a1b42 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/HikvisionAPI.java @@ -0,0 +1,179 @@ +package com.jingyi.iotserver.utils; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.hikvision.artemis.sdk.ArtemisHttpUtil; +import com.hikvision.artemis.sdk.config.ArtemisConfig; +import com.jingyi.iotserver.firestationport.FireCtrlSystemInit; +import com.jingyi.iotserver.firestationport.model.sensor.ys.HikvisionIPCEntity; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class HikvisionAPI { + + /** + * STEP2:设置OpenAPI接口的上下文 + */ + public static final String ARTEMIS_PATH = "/artemis"; + + public static final String ARTEMIS_PATH_Real = "218.76.54.6:2443"; + + public static void initHK(){ + /** + * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数. + */ + if(FireCtrlSystemInit.netMode == 1){ + // ArtemisConfig.host = "218.76.54.20:2443"; // artemis网关服务器ip端口 + // ArtemisConfig.appKey = "21021818"; // 秘钥appkey + // ArtemisConfig.appSecret = "5HPoUuuH4h9PND73gyD3";// 秘钥appSecret + ArtemisConfig.host = "192.168.15.240:443"; + // ArtemisConfig.host = "218.76.54.6:2443"; + + ArtemisConfig.appKey = "22516879"; // 秘钥appkey + ArtemisConfig.appSecret = "AVAgLtiq3v3AT0e9A6yD";// 秘钥appSecret + }else if(FireCtrlSystemInit.netMode == 0){ + ArtemisConfig.host = "43.15.198.62:443"; // artemis网关服务器ip端口 + ArtemisConfig.appKey = "21021818"; // 秘钥appkey + ArtemisConfig.appSecret = "5HPoUuuH4h9PND73gyD3";// 秘钥appSecret + } + + // ArtemisConfig.host = "10.242.135.150:8443"; // artemis网关服务器ip端口 + // ArtemisConfig.appKey = "27323523"; // 秘钥appkey + // ArtemisConfig.appSecret = "MK1XRnO89TuVIE8dHDrH";// 秘钥appSecret + + } + + public static String GetCameraPreviewURL(String cameraCode) { + initHK(); + /** + * STEP3:设置接口的URI地址 + */ + final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + /** + * STEP4:设置参数提交方式 + */ + String contentType = "application/json"; + + /** + * STEP5:组装请求参数 + */ + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode", cameraCode); + jsonBody.put("streamType", 0); + jsonBody.put("protocol", "ws"); + // jsonBody.put("transmode", 1); + // jsonBody.put("expand", "streamform=ps"); + String body = jsonBody.toJSONString(); + /** + * STEP6:调用接口 + */ + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数 + System.out.println("HikvisionAPI: GetCameraPreviewURL = " + result); + + if(FireCtrlSystemInit.netMode == 1){ + return result.replace("192.168.15.240", "218.76.54.6"); + } + + return result; + } + + + public static String GetDeviceList(DataSource dataSource) { + initHK(); + /** + * STEP3:设置接口的URI地址 + */ + final String getDeviceListApi = ARTEMIS_PATH + "/api/resource/v1/camera/advance/cameraList"; + Map path = new HashMap(2) { + { + put("https://", getDeviceListApi);//根据现场环境部署确认是http还是https + } + }; + + /** + * STEP4:设置参数提交方式 + */ + String contentType = "application/json"; + + /** + * STEP5:组装请求参数 + */ + JSONObject jsonBody = new JSONObject(); + + jsonBody.put("pageSize", 1000); + jsonBody.put("pageNo", 1); + + String resStr= ""; + System.out.println("HikvisionAPI: GetDeviceList " + getDeviceListApi); + String body = jsonBody.toJSONString(); + /** + * STEP6:调用接口 + */ + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数 + + // System.out.println("HikvisionAPI: GetDeviceList = " + result); + + try { + JSONObject rootJs = JSON.parseObject(result); + if(!rootJs.containsKey("code")){ + return "error"; + } + String strCode = rootJs.getString("code"); + if(strCode == null){ + return "error"; + } + if(!strCode.equalsIgnoreCase("0")){ + return "error"; + } + + if(!rootJs.containsKey("data")){ + return "no data"; + } + + String data1 = rootJs.getString("data"); + resStr = data1; + + JSONObject dataJs1 = JSON.parseObject(data1); + + + int ipcTotal = dataJs1.getIntValue("total"); + + System.out.println("HikvisionAPI: GetDeviceList = " + ipcTotal); + JSONArray jsonArray = dataJs1.getJSONArray("list"); + List ipcEntityList = jsonArray.toJavaList(HikvisionIPCEntity.class); + + if(ipcEntityList != null){ + for(HikvisionIPCEntity ipcEntity:ipcEntityList){ + HikvisionIPCEntity oldIPC = new HikvisionIPCEntity(ipcEntity.getCameraIndexCode()); + + if(oldIPC.QueryIt(dataSource) != null){ + ipcEntity.setBrigade(oldIPC.getBrigade()); + ipcEntity.setBorough(oldIPC.getBorough()); + ipcEntity.setDetachment(oldIPC.getDetachment()); + ipcEntity.setStation(oldIPC.getStation()); + + ipcEntity.Update(dataSource); + }else{ + ipcEntity.Insert(dataSource); + } + } + + return "ipc " + ipcEntityList.size(); + } + }catch (Exception e){ + } + + return resStr; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/HttpTools.java b/src/main/java/com/jingyi/iotserver/utils/HttpTools.java new file mode 100644 index 0000000..32f9642 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/HttpTools.java @@ -0,0 +1,227 @@ +package com.jingyi.iotserver.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.Consts; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.net.ssl.HttpsURLConnection; +import javax.servlet.http.HttpServletRequest; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.Map; + +public class HttpTools { + + public static String getBodyFromRequest(HttpServletRequest request){ + String json = null; + try { + BufferedReader br = request.getReader(); + // BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream(), "utf-8")); + StringBuffer sb = new StringBuffer(""); + String temp; + while ((temp = br.readLine()) != null) { sb.append(temp); } + br.close(); + json = sb.toString(); + + // BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8")); + // json = IOUtils.read(reader); + + + }catch (Exception e){ + e.printStackTrace(); + } + return json; + } + + public static String getBodyFromRespone(HttpResponse response){ + String json = null; + try { + BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()), "utf-8")); + StringBuffer sb = new StringBuffer(""); + String temp; + while ((temp = br.readLine()) != null) { sb.append(temp); } + br.close(); + json = sb.toString(); + + // BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8")); + // json = IOUtils.read(reader); + + + }catch (Exception e){ + e.printStackTrace(); + } + return json; + } + + public static JsonNode getJsonFromRequest(HttpServletRequest request){ + JsonNode rootnode = null; + String json = getBodyFromRequest(request); + if (json == null) { + Object obj = request.getAttribute("req-json-obj"); + if (obj instanceof JsonNode) + rootnode = (JsonNode) obj; + else { + json = (String) request.getAttribute("req-json-str"); + rootnode = JsonHelper.parseBodyLevel1(json); + } + }else{ + request.setAttribute("req-json-str",json); + rootnode = JsonHelper.parseBodyLevel1(json); + } + return rootnode; + } + + public static double [] convertToGaoDePosition(double longitude, double latitude){ + String appkey = "d27f0a98dba2f18bc3e9975912d030ef"; + String url = "https://restapi.amap.com/v3/assistant/coordinate/convert?key="+appkey; + url += "&coordsys=gps&output=json&locations="+longitude+","+latitude; + + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpGet get = new HttpGet(url); + CloseableHttpResponse response = null; + try { + response = httpClient.execute(get); + if(response != null && response.getStatusLine().getStatusCode() == 200) + { + String json = HttpTools.getBodyFromRespone(response); + if(json!=null){ + JsonNode node = JsonHelper.parseBodyLevel1(json); + String str = JsonHelper.getStringValue(node,"locations"); + if(str!=null){ + String []lon = str.split(","); + if(lon!=null&&lon.length==2){ + double[] pos = new double[2]; + try { + pos[0] = Double.parseDouble(lon[0]); + pos[1] = Double.parseDouble(lon[1]); + return pos; + }catch (Exception e){ + + } + } + } + } + } + + } catch (IOException e) { + e.printStackTrace(); + }finally { + try { + httpClient.close(); + if(response != null) + { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + + public static String getRespFromHttpServer(String url,String body){ + try { + + HttpURLConnection connection = HttpTools.createHttpConnection(url); + + connection.setRequestMethod("POST"); + connection.connect(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); + writer.write(body); + writer.close(); + + int responseCode = connection.getResponseCode(); + if(responseCode == HttpURLConnection.HTTP_OK){ + return HttpTools.getBodyFromRespone(connection); + } + + }catch (Exception e){ + + } + return null; + } + + public static String getBodyFromRespone(HttpURLConnection respone){ + String json = null; + try { + BufferedReader br = new BufferedReader(new InputStreamReader((respone.getInputStream()), "utf-8")); + StringBuffer sb = new StringBuffer(""); + String temp; + while ((temp = br.readLine()) != null) { sb.append(temp); } + br.close(); + json = sb.toString(); + + }catch (Exception e){ + e.printStackTrace(); + } + return json; + } + + public static HttpURLConnection createHttpConnection(String uri){ + HttpURLConnection connection = null; + + try { + URL url = new URL(uri); + + connection = (HttpURLConnection) url.openConnection(); + if (uri.startsWith("https")) { + // ((HttpsURLConnection) connection).setHostnameVerifier(new IgnoreHostnameVerifier()); + } + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(false); + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + }catch (Exception e){ + + } + return connection; + } + + public static void allowAllSSL(){ + // TrustManager[] tm = { new JYX509TrustManager() }; + try { + /* SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); + sslContext.init(null, tm, new java.security.SecureRandom()); + // 从上述SSLContext对象中得到SSLSocketFactory对象 + SSLSocketFactory ssf = sslContext.getSocketFactory(); +*/ + javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; + javax.net.ssl.TrustManager tm = new JYX509TrustManager(); + trustAllCerts[0] = tm; + javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, null); + javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + }catch (Exception e){ + + } + + HttpsURLConnection.setDefaultHostnameVerifier(new IgnoreHostnameVerifier()); + } + + public static void sendRtmMessage(String receiver,String msgtype,String message){ + String json = "{\"receiver\":\""+receiver+"\",\"msgtype\":\""+msgtype+"\",\"message\":\""+message+"\"}"; + try { + json = AESUtil.encryptAES(json, "142!QAZ/.,mkoijh"); + }catch (Exception e){ + + } + getRespFromHttpServer("http://47.105.206.63:9090/rmttranfer/sendmessage",json); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/IgnoreHostnameVerifier.java b/src/main/java/com/jingyi/iotserver/utils/IgnoreHostnameVerifier.java new file mode 100644 index 0000000..fe645b5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/IgnoreHostnameVerifier.java @@ -0,0 +1,13 @@ +package com.jingyi.iotserver.utils; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; + +public class IgnoreHostnameVerifier implements HostnameVerifier { + @Override + public boolean verify(String arg0, SSLSession arg1) + { + //所有都正确 + return true; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/JPos.java b/src/main/java/com/jingyi/iotserver/utils/JPos.java new file mode 100644 index 0000000..e8b4d67 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/JPos.java @@ -0,0 +1,23 @@ +package com.jingyi.iotserver.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface JPos { + int index() default 0; + boolean primary() default false;//the keys used to locate unique record + boolean identify() default false; + boolean filter() default false; //query conditions + boolean timekey() default false; //while query page, time filter with the key + boolean orderkey() default false;// while query page, order by the key + boolean update() default true; //enable/disable update + boolean diffconf() default false;//enable/disable <> condition + int strlen() default 255; + int threshold() default -1; + double floatthreshold() default 0.0f; + boolean buildindex() default false; +} diff --git a/src/main/java/com/jingyi/iotserver/utils/JYDataIdentify.java b/src/main/java/com/jingyi/iotserver/utils/JYDataIdentify.java new file mode 100644 index 0000000..b88122e --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/JYDataIdentify.java @@ -0,0 +1,5 @@ +package com.jingyi.iotserver.utils; + +public @interface JYDataIdentify { + int id() default 1; +} diff --git a/src/main/java/com/jingyi/iotserver/utils/JYDataLongStr.java b/src/main/java/com/jingyi/iotserver/utils/JYDataLongStr.java new file mode 100644 index 0000000..ca724f0 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/JYDataLongStr.java @@ -0,0 +1,12 @@ +package com.jingyi.iotserver.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface JYDataLongStr { + int length() default 255; +} diff --git a/src/main/java/com/jingyi/iotserver/utils/JYX509TrustManager.java b/src/main/java/com/jingyi/iotserver/utils/JYX509TrustManager.java new file mode 100644 index 0000000..5812215 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/JYX509TrustManager.java @@ -0,0 +1,28 @@ +package com.jingyi.iotserver.utils; + +import javax.net.ssl.X509TrustManager; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +public class JYX509TrustManager implements javax.net.ssl.TrustManager, X509TrustManager { + // 检查客户端证书 + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + // 检查服务器端证书 + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + // 返回受信任的X509证书数组 + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) { + return true; + } + + public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) { + return true; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/JsonHelper.java b/src/main/java/com/jingyi/iotserver/utils/JsonHelper.java new file mode 100644 index 0000000..2e74579 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/JsonHelper.java @@ -0,0 +1,115 @@ +package com.jingyi.iotserver.utils; + +import com.alibaba.dubbo.common.json.JSON; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; + +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class JsonHelper { + private final static String DATE_TIME_FORMATTER = "yyyy-MM-dd HH:mm:ss"; + + public static JsonNode parseBodyLevel1(String json) { + JsonNode rootnode = null; + ObjectMapper mapper = new ObjectMapper(); + try { + rootnode = mapper.readTree(json); + if (rootnode == null) + return null; + } catch (Exception e) { + + } + return rootnode; + } + + public static String getStringValue(JsonNode rootnode, String key) { + try { + JsonNode m = rootnode.findValue(key); + return m.asText(); + } catch (Exception e) { + + } + return null; + } + + public static int getIntValue(JsonNode rootnode, String key) { + try { + JsonNode m = rootnode.findValue(key); + if (m.isInt()) { + return m.asInt(); + } + } catch (Exception e) { + + } + return -1; + } + + public static double getDoubleValue(JsonNode rootnode, String key) { + try { + JsonNode m = rootnode.findValue(key); + if (m.isDouble()) { + return m.asDouble(); + } else if (m.isFloat()) { + return m.asDouble(); + } + } catch (Exception e) { + + } + return -1; + } + + public static long getLongValue(JsonNode rootnode, String key) { + try { + JsonNode m = rootnode.findValue(key); + if (m.isLong()) { + return m.asLong(); + } else if (m.isInt()) { + return m.asInt(); + } + } catch (Exception e) { + + } + return -1; + } + + public static JsonNode getLevel2(JsonNode rootnode, String key) { + try { + JsonNode m = rootnode.findValue(key); + if (m.isObject() || m.isArray()) { + return m; + } + } catch (Exception e) { + + } + return null; + } + + public static String Object2JsonStr(Object obj) { + String json = null; + try { + json = JSON.json(obj); + } catch (Exception e) { + + } + return json; + } + + public static String convertObjectToStr(Object obj) { + try { + ObjectMapper mapper = new ObjectMapper(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + mapper.setDateFormat(sdf); + String json = mapper.writeValueAsString(obj); + return json; + } catch (Exception e) { + + } + return null; + } + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/MD5Tools.java b/src/main/java/com/jingyi/iotserver/utils/MD5Tools.java new file mode 100644 index 0000000..d00ac3c --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/MD5Tools.java @@ -0,0 +1,12 @@ +package com.jingyi.iotserver.utils; + +import org.apache.commons.codec.digest.DigestUtils; + + +//maven: commons-lang3 + +public class MD5Tools { + public static String md5(String key){ + return DigestUtils.md5Hex(key); + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/PositionUtil.java b/src/main/java/com/jingyi/iotserver/utils/PositionUtil.java new file mode 100644 index 0000000..3e0bcb9 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/PositionUtil.java @@ -0,0 +1,136 @@ +package com.jingyi.iotserver.utils; + +import org.gavaghan.geodesy.Ellipsoid; +import org.gavaghan.geodesy.GeodeticCalculator; +import org.gavaghan.geodesy.GeodeticCurve; +import org.gavaghan.geodesy.GlobalCoordinates; + +public class PositionUtil { + private static double pi = 3.1415926535897932384626; + private static double a = 6378245.0; + private static double ee= 0.00669342162296594323; + + public static Gps gps84_To_Gcj02(double lat, double lon){ + if(outOfChina(lat, lon)){ + return new Gps(lat, lon); + } + + double dLat = transformLat(lon - 105.0, lat-35.0); + double dLon = transformLon(lon - 105.0, lat-35.0); + double radLat = lat*pi/180.0; + double magic = Math.sin(radLat); + magic = 1 - ee*magic*magic; + double sqrtMagic = Math.sqrt(magic); + dLat = (dLat * 180.0)/ ((a * (1 - ee))/(magic*sqrtMagic)* pi); + dLon = (dLon * 180.0)/ ( a /sqrtMagic * Math.cos(radLat)* pi); + double mgLat = lat + dLat; + double mgLon = lon+dLon; + + return new Gps(mgLat, mgLon); + } + + public static Gps transform(double lat, double lon){ + if(outOfChina(lat, lon)){ + return new Gps(lat, lon); + } + + double dLat = transformLat(lon - 105.0, lat-35.0); + double dLon = transformLon(lon - 105.0, lat-35.0); + double radLat = lat*pi/180.0; + double magic = Math.sin(radLat); + magic = 1 - ee*magic*magic; + double sqrtMagic = Math.sqrt(magic); + dLat = (dLat * 180.0)/ ((a * (1 - ee))/(magic*sqrtMagic)* pi); + dLon = (dLon * 180.0)/ ( a /sqrtMagic * Math.cos(radLat)* pi); + double mgLat = lat + dLat; + double mgLon = lon+dLon; + + return new Gps(mgLat, mgLon); + } + + public static Gps gcj02_To_wgs84(double lat,double lon){ + Gps gps = transform(lat, lon); + double lonti = lon*2 - gps.getWgLon(); + double latitude = lat*2 - gps.getWgLat(); + return new Gps(latitude, lonti); + } + + public static Gps gcj02_To_wgs84_exact(double lat,double lon) { + if(outOfChina(lat, lon)){ + return new Gps(lat, lon); + } + double initDelta = 0.01; + double threshold = 0.000001; + double dLat = initDelta; + double dLon = initDelta; + double mLat = lat - dLat; + double mLon = lon - dLon; + double pLat = lat + dLat; + double pLon = lon + dLon; + double wgsLat = 0; + double wgsLon = 0; + int i = 0; + while (true) { + wgsLat = (mLat + pLat) / 2; + wgsLon = (mLon + pLon) / 2; + Gps tmp = gps84_To_Gcj02(wgsLat, wgsLon); + dLat = tmp.getWgLat() - lat; + dLon = tmp.getWgLon() - lon; + if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold)){ + break; + } + + if (dLat > 0) { + pLat = wgsLat; + } + else { + mLat = wgsLat; + } + if (dLon > 0) { + pLon = wgsLon; + } else { + mLon = wgsLon; + } + + if (++i > 1000) break; + } + return new Gps(wgsLat, wgsLon); + + } + + + + private static boolean outOfChina(double lat, double lon){ + if(lon < 72.004 || lon > 137.8347){ + return true; + } + if(lat < 0.8293 || lat > 55.8271){ + return true; + } + return false; + } + + private static double transformLat(double x, double y){ + double ret = -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*Math.sqrt(Math.abs(x)); + ret += (20.0*Math.sin(6.0*x*pi) + 20.0*Math.sin(2.0*x*pi)) * 2.0/3.0; + ret += (20.0*Math.sin(y*pi) + 40.0*Math.sin(y*pi/3.0)) * 2.0/3.0; + ret += (160.0*Math.sin(y*pi/12.0) + 320.0*Math.sin(y*pi/30.0)) * 2.0/3.0; + + return ret; + } + + private static double transformLon(double x, double y){ + double ret = 300.0 + x + 2*y + 0.1*x*x + 0.1*x*y + 0.1*Math.sqrt(Math.abs(x)); + ret += (20.0*Math.sin(6.0*x*pi) + 20.0*Math.sin(2.0*x*pi)) * 2.0/3.0; + ret += (20.0*Math.sin(x*pi) + 40.0*Math.sin(x*pi/3.0)) * 2.0/3.0; + ret += (150.0*Math.sin(x*pi/12.0) + 300.0*Math.sin(x*pi/30.0)) * 2.0/3.0; + + return ret; + } + + public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo){ + GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, gpsFrom, gpsTo); + return geoCurve.getEllipsoidalDistance(); + } + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/RSAUtil.java b/src/main/java/com/jingyi/iotserver/utils/RSAUtil.java new file mode 100644 index 0000000..dccf252 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/RSAUtil.java @@ -0,0 +1,78 @@ +package com.jingyi.iotserver.utils; + +import javax.crypto.Cipher; +import java.io.IOException; +import java.security.*; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.Base64; + +public class RSAUtil { + //生成秘钥对 + public static KeyPair getKeyPair(int keysize) throws Exception { + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + if(keysize<1024) + keysize = 1024; + keyPairGenerator.initialize(keysize); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + return keyPair; + } + + //获取公钥(Base64编码) + public static String getPublicKey(KeyPair keyPair){ + PublicKey publicKey = keyPair.getPublic(); + byte[] bytes = publicKey.getEncoded(); + return byte2Base64(bytes); + } + + //获取私钥(Base64编码) + public static String getPrivateKey(KeyPair keyPair){ + PrivateKey privateKey = keyPair.getPrivate(); + byte[] bytes = privateKey.getEncoded(); + return byte2Base64(bytes); + } + + //将Base64编码后的公钥转换成PublicKey对象 + public static PublicKey string2PublicKey(String pubStr) throws Exception{ + byte[] keyBytes = base642Byte(pubStr); + X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + PublicKey publicKey = keyFactory.generatePublic(keySpec); + return publicKey; + } + + //将Base64编码后的私钥转换成PrivateKey对象 + public static PrivateKey string2PrivateKey(String priStr) throws Exception{ + byte[] keyBytes = base642Byte(priStr); + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + PrivateKey privateKey = keyFactory.generatePrivate(keySpec); + return privateKey; + } + + //公钥加密 + public static byte[] publicEncrypt(byte[] content, PublicKey publicKey) throws Exception{ + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, publicKey); + byte[] bytes = cipher.doFinal(content); + return bytes; + } + + //私钥解密 + public static byte[] privateDecrypt(byte[] content, PrivateKey privateKey) throws Exception{ + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE, privateKey); + byte[] bytes = cipher.doFinal(content); + return bytes; + } + + //字节数组转Base64编码 + public static String byte2Base64(byte[] bytes){ + return Base64.getEncoder().encodeToString(bytes); + } + + //Base64编码转字节数组 + public static byte[] base642Byte(String base64Key) throws IOException { + return Base64.getDecoder().decode(base64Key); + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SQLCreateTableCmd.java b/src/main/java/com/jingyi/iotserver/utils/SQLCreateTableCmd.java new file mode 100644 index 0000000..93459ec --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SQLCreateTableCmd.java @@ -0,0 +1,130 @@ +package com.jingyi.iotserver.utils; + + +import com.alibaba.druid.pool.DruidDataSource; +import com.jingyi.iotserver.common.service.EnvConfigService; + +import javax.sql.DataSource; + +public class SQLCreateTableCmd { + private int count = 0; + private String sql; + private String sqltype = "mysql";//sqlserver + private EnvConfigService envConfigService; + public SQLCreateTableCmd(){ + envConfigService = (EnvConfigService)SpringContextUtil.getBean(EnvConfigService.class); + sqltype = envConfigService.getDataBaseType(); + } + + public SQLCreateTableCmd(DataSource dataSource){ + if(dataSource==null) { + envConfigService = (EnvConfigService) SpringContextUtil.getBean(EnvConfigService.class); + sqltype = envConfigService.getDataBaseType(); + }else{ + try { + DruidDataSource ds = (DruidDataSource) dataSource; + if(ds.getUrl().indexOf("mysql")>=0) + sqltype = "mysql"; + else if(ds.getUrl().indexOf("sqlserver")>=0) + sqltype = "sqlserver"; + else + sqltype = "mysql"; + }catch (Exception e){ + sqltype = "mysql"; + } + } + } + + public String getSql() { + return sql; + } + + public void start(String tablename){ + sql = "CREATE TABLE "+tablename+"("; + count = 0; + } + + public void addInt(String name){ + if(count>0){ + sql += ","; + } + if(sqltype.equals("mysql")&&name.equals("signal")) + name = "radiosignal"; + sql += name+" int"; + count++; + } + + public void addIdentity(String name){ + if(count>0){ + sql += ","; + } + if(sqltype.equals("sqlserver")) + sql += name+ " int identity(1,1)"; + else if(sqltype.equals("mysql")) + sql += name+ " int NOT NULL AUTO_INCREMENT,PRIMARY KEY ("+name+") "; + count++; + } + + public void addShortString(String name){ + if(count>0){ + sql += ","; + } + if(sqltype.equals("mysql")&&name.equals("usage")) + name = "enableuse"; + sql += name+" varchar(255)"; + count++; + } + + public void addLongString(String name,int length){ + if(count>0){ + sql += ","; + } + if(sqltype.equals("sqlserver")) + sql += name+" varchar("+length+")"; + else if(sqltype.equals("mysql")) { + if(length<=65535) + sql += name + " TEXT"; + else + sql += name + " MEDIUMTEXT"; + } + + count++; + } + + public void addDouble(String name){ + if(count>0){ + sql += ","; + } + sql += name+" float(53)"; + count++; + } + + public void addDateTime(String name){ + if(count>0){ + sql += ","; + } + sql += name+" datetime"; + count++; + } + + public void addBigInt(String name){ + if(count>0){ + sql += ","; + } + sql += name+" BIGINT"; + count++; + + } + + public void addBuildIndex(String indexStr){ + if(count>0){ + sql += ","; + } + sql += "INDEX index_name("+indexStr+")"; + count++; + } + + public void end(){ + sql+=")"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SQLDataObject.java b/src/main/java/com/jingyi/iotserver/utils/SQLDataObject.java new file mode 100644 index 0000000..1253ae5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SQLDataObject.java @@ -0,0 +1,1197 @@ +package com.jingyi.iotserver.utils; + + +import javax.sql.DataSource; +import java.lang.reflect.Field; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class SQLDataObject { + protected boolean enableDiffContion = false; + protected String diffConList = null; + protected String tableExtName = null; + public String tableName(){ + return null; + } + + public void extendName(String extname){ + tableExtName = extname; + } + + public void setEnableDiffContion(boolean enableDiffContion){ + this.enableDiffContion = enableDiffContion; + } + + public void addDiffCond(String name){ + if(name==null||name.length()<=0) + return; + if(diffConList==null){ + diffConList = "##"; + }else{ + diffConList += "##"; + } + diffConList += name; + diffConList += "$"; + } + + public boolean isDiffConf(Field fie){ + + JPos pos = fie.getAnnotation(JPos.class); + if(!pos.diffconf()||diffConList==null) + return false; + String str = "##"+fie.getName()+"$"; + if(diffConList.contains(str)) + return true; + return false; + } + + public void createTable(DataSource dataSource){ + + int maxpos = -1; + Field[] datafs = new Field[200]; + Field[] f = getClass().getDeclaredFields(); + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.index()<200){ + datafs[pos.index()] = fie; + if(pos.index()>maxpos) + maxpos = pos.index(); + } + } + } catch (Exception e) { + + } + } + if(maxpos<0) + return; + + SQLCreateTableCmd cmd = new SQLCreateTableCmd(dataSource); + cmd.start(tableName()); + for(Field fie : datafs){ + if(fie==null) + continue; + Class membertype = fie.getType(); + if(membertype.equals(String.class)){ + try{ + JPos pos = fie.getAnnotation(JPos.class); + if(pos!=null&&pos.strlen()>255){ + cmd.addLongString(fie.getName(),pos.strlen()); + }else{ + cmd.addShortString(fie.getName()); + } + }catch (Exception e){ + return ; + } + }else if(membertype.getName().equals("int")) { + try{ + JPos pos = fie.getAnnotation(JPos.class); + if(pos.identify()){ + cmd.addIdentity(fie.getName()); + }else{ + cmd.addInt(fie.getName()); + } + }catch (Exception e){ + + } + }else if(membertype.getName().equals("float")){ + cmd.addDouble(fie.getName()); + }else if(membertype.getName().equals("double")) { + cmd.addDouble(fie.getName()); + }else if(membertype.getName().equals("long")){ + cmd.addBigInt(fie.getName()); + }else if(membertype.equals(Date.class)){ + cmd.addDateTime(fie.getName()); + } + } + + String indexStr = buildIndexKey(); + if(indexStr != null){ + cmd.addBuildIndex(indexStr); + } + + cmd.end(); + try{ + SQLTools.ExecuteSQL(dataSource, cmd.getSql()); + }catch (Exception e){ + + } + } + + public String InsertSql() { + int maxpos = -1; + Field[] datafs = new Field[200]; + Field[] f = getClass().getDeclaredFields(); + Field identifyfield = null; + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.index()<200){ + datafs[pos.index()] = fie; + if(pos.index()>maxpos) + maxpos = pos.index(); + } + } + } catch (Exception e) { + + } + } + if(maxpos<0) + return null; + + + SQLInsertCmd cmd = new SQLInsertCmd(); + cmd.start(tableName()); + + for(Field fie : datafs){ + if(fie==null) + continue; + Class membertype = fie.getType(); + if(membertype.equals(String.class)){ + try { + fie.setAccessible(true); + cmd.appenValue(fie.getName(), (String)fie.get(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("int")) { + try{ + JPos pos = fie.getAnnotation(JPos.class); + if(pos!=null&&pos.identify()) { + identifyfield = fie; + continue; + } + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getInt(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("float")){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getFloat(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("double")){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getDouble(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("long")){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getLong(this)); + }catch (Exception e){ + + } + }else if(membertype.equals(Date.class)){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), (Date)fie.get(this)); + }catch (Exception e){ + + } + } + + } + cmd.end(); + return cmd.getSql(); + } + + public String timeKey(){ + Field[] f = getClass().getDeclaredFields(); + for (Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if (pos.timekey()) { + return fie.getName(); + } + + } + } catch (Exception e) { + + } + } + return null; + } + + public String orderKey(){ + Field[] f = getClass().getDeclaredFields(); + for (Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if (pos.orderkey()) { + return fie.getName(); + } + + } + } catch (Exception e) { + + } + } + return null; + } + + public String buildIndexKey(){ + Field[] f = getClass().getDeclaredFields(); + String indexKey = null; + for (Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if (pos.buildindex()) { + if(indexKey == null){ + indexKey = fie.getName(); + }else{ + indexKey += ","; + indexKey += fie.getName(); + } + } + } + } catch (Exception e) { + + } + } + return indexKey; + } + + public String uniqueCondition() { + + ArrayList keyfeild = new ArrayList(); + Field[] f = getClass().getDeclaredFields(); + for (Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if (pos.primary()) { + keyfeild.add(fie); + continue; + } + + } + } catch (Exception e) { + + } + } + + + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(), null, null); + String con = null; + for (Field fie : keyfeild) { + if (fie == null) + continue; + + Class membertype = fie.getType(); + if (membertype.equals(String.class)) { + try { + fie.setAccessible(true); + String val = (String)fie.get(this); + if(val==null) + continue; + if(con==null) + con = fie.getName()+"='"+ val+"'"; + else + con += " and "+fie.getName()+"='"+ fie.get(this)+"'"; + } catch (Exception e) { + + } + } else if (membertype.getName().equals("int")) { + try { + fie.setAccessible(true); + if(con==null) + con = fie.getName()+"="+ fie.getInt(this); + else + con += " and "+fie.getName()+"="+ fie.getInt(this); + } catch (Exception e) { + + } + } else if (membertype.getName().equals("long")) { + try { + fie.setAccessible(true); + if(con==null) + con = fie.getName()+"="+ fie.getLong(this); + else + con += " and "+fie.getName()+"="+ fie.getLong(this); + } catch (Exception e) { + + } + } else if (membertype.equals(Date.class)) { + try { + fie.setAccessible(true); + Date val = (Date)fie.get(this); + if(val==null) + continue; + if(con==null) + con = fie.getName()+"='"+ SQLTools.formatDate(val)+"'"; + else + con += " and "+fie.getName()+"='"+ SQLTools.formatDate(val)+"'"; + } catch (Exception e) { + + } + } + } + return con; + } + + public boolean Insert(DataSource dataSource){ + int maxpos = -1; + Field[] datafs = new Field[200]; + Field[] f = getClass().getDeclaredFields(); + Field identifyfield = null; + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.index()<200){ + datafs[pos.index()] = fie; + if(pos.index()>maxpos) + maxpos = pos.index(); + } + } + } catch (Exception e) { + + } + } + if(maxpos<0) + return false; + + + SQLInsertCmd cmd = new SQLInsertCmd(); + cmd.start(tableName()); + + for(Field fie : datafs){ + if(fie==null) + continue; + Class membertype = fie.getType(); + if(membertype.equals(String.class)){ + try { + fie.setAccessible(true); + cmd.appenValue(fie.getName(), (String)fie.get(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("int")) { + try{ + JPos pos = fie.getAnnotation(JPos.class); + if(pos!=null&&pos.identify()) { + identifyfield = fie; + continue; + } + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getInt(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("float")){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getFloat(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("double")){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getDouble(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("long")){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), fie.getLong(this)); + }catch (Exception e){ + + } + }else if(membertype.equals(Date.class)){ + try{ + fie.setAccessible(true); + cmd.appenValue(fie.getName(), (Date)fie.get(this)); + }catch (Exception e){ + + } + } + + } + cmd.end(); + + if(identifyfield!=null){ + try{ + int keytid = SQLTools.ExecuteInsertSQLGetIdentify(dataSource, cmd.getSql()); + if(keytid<0){ + createTable(dataSource); + keytid = SQLTools.ExecuteInsertSQLGetIdentify(dataSource, cmd.getSql()); + if(keytid<0) + return false; + } + try { + identifyfield.setAccessible(true); + identifyfield.setInt(this,keytid); + }catch (Exception e){ + + } + }catch (Exception e){ + return false; + } + }else + { + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())){ + createTable(dataSource); + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + } + + + }catch (Exception e){ + return false; + } + + } + return true; + } + + private void tryCreateTable(DataSource dataSource){ + try{ + Connection cnt = dataSource.getConnection();// + DatabaseMetaData dbmd=cnt.getMetaData(); + ResultSet tableRS = dbmd.getTables(null, null, tableName(), null ); + if (tableRS.next()) { + System.out.println(" the table is ready"); + }else{ + System.out.println(" There is no table info"); + createTable(dataSource); + } + }catch(Exception e) { + e.printStackTrace(); + } + } + + public boolean Delete(DataSource dataSource){ + String con = uniqueCondition(); + if(con==null) + return false; + String sql = "DELETE FROM "+tableName()+" WHERE "+con; + try{ + SQLTools.ExecuteSQL(dataSource, sql); + return true; + }catch (Exception e){ + + } + return false; + } + + public boolean Update(DataSource dataSource){ + int maxpos = -1; + Field[] datafs = new Field[200]; + ArrayList keyfeild = new ArrayList(); + Field[] f = getClass().getDeclaredFields(); + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.primary()){ + keyfeild.add(fie); + continue; + } + if(!pos.update()||pos.identify()) + continue; + if(pos.index()<200){ + datafs[pos.index()] = fie; + if(pos.index()>maxpos) + maxpos = pos.index(); + } + } + } catch (Exception e) { + + } + } + if(maxpos<0||keyfeild.size()<=0) + return false; + + + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(),null, null); + + for(Field fie : keyfeild) { + if(fie==null) + continue; + + Class membertype = fie.getType(); + if(membertype.equals(String.class)){ + try { + fie.setAccessible(true); + String val = (String)fie.get(this); + if(val==null) + continue; + cmd.appendKey(fie.getName(), val); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("int")) { + try{ + fie.setAccessible(true); + cmd.appendKey(fie.getName(), fie.getInt(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("long")){ + try{ + fie.setAccessible(true); + cmd.appendKey(fie.getName(),fie.getLong(this)); + }catch (Exception e){ + + } + }else if(membertype.equals(Date.class)){ + try{ + fie.setAccessible(true); + Date val = (Date)fie.get(this); + if(val==null) + continue; + cmd.appendKey(fie.getName(), val); + }catch (Exception e){ + + } + } + } + + for(Field fie : datafs){ + if(fie==null) + continue; + Class membertype = fie.getType(); + JPos pos = fie.getAnnotation(JPos.class); + if(membertype.equals(String.class)){ + try { + fie.setAccessible(true); + cmd.appendValue(fie.getName(), (String)fie.get(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("int")) { + try{ + if(pos!=null&&pos.identify()) + continue; + fie.setAccessible(true); + int val = fie.getInt(this); + if(val>pos.threshold()) + cmd.appendValue(fie.getName(), fie.getInt(this)); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("float")){ + try{ + fie.setAccessible(true); + float val = fie.getFloat(this); + if(val>pos.floatthreshold()) + cmd.appendValue(fie.getName(), val); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("double")){ + try{ + fie.setAccessible(true); + double val = fie.getDouble(this); + if(val>pos.floatthreshold()) + cmd.appendValue(fie.getName(), val); + }catch (Exception e){ + + } + }else if(membertype.getName().equals("long")){ + try{ + fie.setAccessible(true); + long val = fie.getLong(this); + if(val>pos.threshold()) + cmd.appendValue(fie.getName(), fie.getLong(this)); + }catch (Exception e){ + + } + }else if(membertype.equals(Date.class)){ + try{ + fie.setAccessible(true); + cmd.appendValue(fie.getName(), (Date)fie.get(this)); + }catch (Exception e){ + + } + } + + } + + try{ + if(!SQLTools.ExecuteSQL(dataSource, cmd.getSql())) + return false; + return true; + }catch (Exception e){ + + } + return false; + } + + public SQLDataObject QueryIt(DataSource dataSource){ + String con = uniqueCondition(); + if(con==null) + return null; + + String sql = "select * from " + tableName() + " where " +con; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, getClass()); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + tryCreateTable(dataSource); + } + return null; + } + + public SQLDataObject QueryIdentify(DataSource dataSource){ + Field identify = null; + Field[] f = getClass().getDeclaredFields(); + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.identify()){ + identify = fie; + break; + } + } + } catch (Exception e) { + + } + } + if(identify==null) + return null; + int val = -1; + try{ + identify.setAccessible(true); + val = identify.getInt(this); + }catch (Exception e){ + return null; + } + String sql = "select * from " + tableName() + " where "+identify.getName()+"="+val; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, getClass()); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + tryCreateTable(dataSource); + } + return null; + } + + public SQLDataObject QueryLast(DataSource dataSource){ + + Field time = null; + Field[] f = getClass().getDeclaredFields(); + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.timekey()){ + time = fie; + break; + } + } + } catch (Exception e) { + + } + } + if(time==null) + return null; + String con = queryCondition(); + String sql = "select * from " + tableName() ; + if(con!=null) + sql += " where "+con+ " order by "+time.getName()+" desc limit 1"; + else + sql += " order by "+time.getName()+" desc limit 1"; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, getClass()); + if (list != null && list.size() > 0) { + return list.get(0); + } + } catch (Exception e) { + tryCreateTable(dataSource); + } + return null; + } + + public List QueryLasts(DataSource dataSource, int limitCount){ + + Field time = null; + Field[] f = getClass().getDeclaredFields(); + for(Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if(pos.timekey()){ + time = fie; + break; + } + } + } catch (Exception e) { + + } + } + if(time==null) + return null; + String con = queryCondition(); + String sql = "select * from " + tableName() ; + if(con!=null) + sql += " where "+con+ " order by "+time.getName()+" desc limit "+limitCount; + else + sql += " order by "+time.getName()+" desc limit "+limitCount; + try { + List list = SQLTools.ExecuteQuery(dataSource, sql, getClass()); + if (list != null && list.size() > 0) { + return list; + } + } catch (Exception e) { + tryCreateTable(dataSource); + } + return null; + } + + public String queryCondition() { + ArrayList keyfeild = new ArrayList(); + Field[] f = getClass().getDeclaredFields(); + for (Field fie : f) { + try { + JPos pos = fie.getAnnotation(JPos.class); + if (pos != null) { + if (pos.filter()) { + keyfeild.add(fie); + continue; + } + + } + } catch (Exception e) { + + } + } + + SQLUpdateCmd cmd = new SQLUpdateCmd(); + cmd.start(tableName(), null, null); + String con = null; + for (Field fie : keyfeild) { + if (fie == null) + continue; + + Class membertype = fie.getType(); + JPos pos = fie.getAnnotation(JPos.class); + if (membertype.equals(String.class)) { + try { + fie.setAccessible(true); + String val = (String)fie.get(this); + if(val==null||val.length()<=0) + continue; + String compare = "='"; + if(isDiffConf(fie)){ + compare = "<>'"; + } + if(con==null) + con = fie.getName()+compare+ fie.get(this)+"'"; + else + con += " and "+fie.getName()+compare+ fie.get(this)+"'"; + } catch (Exception e) { + + } + } else if (membertype.getName().equals("int")) { + try { + fie.setAccessible(true); + int val = fie.getInt(this); + if(val>pos.threshold()) { + String compare = "="; + if(isDiffConf(fie)){ + compare = "<>"; + } + if (con == null) + con = fie.getName() + compare + fie.getInt(this); + else + con += " and " + fie.getName() + compare + fie.getInt(this); + } + } catch (Exception e) { + + } + } else if (membertype.getName().equals("long")) { + try { + fie.setAccessible(true); + long val = fie.getLong(this); + if(val>pos.threshold()) { + String compare = "="; + if(isDiffConf(fie)){ + compare = "<>"; + } + if (con == null) + con = fie.getName() + compare + fie.getLong(this); + else + con += " and " + fie.getName() + compare + fie.getLong(this); + } + } catch (Exception e) { + + } + } else if (membertype.equals(Date.class)) { + try { + fie.setAccessible(true); + String compare = "='"; + if(isDiffConf(fie)){ + compare = "<>'"; + } + if(con==null) + con = fie.getName()+compare+ SQLTools.formatDate((Date)fie.get(this))+"'"; + else + con += " and "+fie.getName()+compare+ SQLTools.formatDate((Date)fie.get(this))+"'"; + } catch (Exception e) { + } + } + } + return con; + } + + public int queryCount(DataSource dataSource,String start ,String end){ + long t1 = System.currentTimeMillis(); + String condition = queryCondition(); + long t2 = System.currentTimeMillis(); + //System.out.println("querycondition use time: "+(t2-t1)); + String sql = "select count(*) from "+tableName(); + Date st = null; + Date et = null; + boolean longtime = false; + try { + Field fie = getClass().getField(timeKey()); + if(fie!=null){ + Class membertype = fie.getType(); + if(membertype.getName().equals("long")){ + longtime = true; + if(start!=null) + st = SQLTools.StrToDateTime(start); + if(end!=null) + et = SQLTools.StrToDateTime(end); + }else if(membertype.equals(Date.class)){ + longtime = false; + }else + return 0; + } + }catch (Exception e){ + + } + + if(start!=null&&start.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + st.getTime() ; + } else + condition += " and " + timeKey() + ">=" + st.getTime() ; + }else { + if (condition == null) { + condition = " " + timeKey() + ">='" + start + "'"; + } else + condition += " and " + timeKey() + ">='" + start + "'"; + } + } + + if(end!=null&&end.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + et.getTime() ; + } else + condition += " and " + timeKey() + ">=" + et.getTime() ; + }else { + if (condition == null) + condition = " " + timeKey() + "<='" + end + "'"; + else + condition += " and " + timeKey() + "<='" + end + "'"; + } + } + if(condition!=null){ + sql += " where "+condition; + } + long t3 = System.currentTimeMillis(); + // System.out.println("ping condtion use time: "+(t3-t2)); + try{ + int count = SQLTools.ExecuteQueryCount(dataSource,sql); + long t4 = System.currentTimeMillis(); + // System.out.println("exeute query use time: "+(t4-t3)); + return count; + }catch (Exception e){ + tryCreateTable(dataSource); + + } + return 0; + } + + public List queryPage(DataSource dataSource,String start , String end,int pageindex,int pagesize){ + String condition = queryCondition(); + String sql = "select * from "+tableName(); + Date st = null; + Date et = null; + boolean longtime = false; + try { + Field fie = getClass().getField(timeKey()); + if(fie!=null){ + Class membertype = fie.getType(); + if(membertype.getName().equals("long")){ + longtime = true; + if(start!=null) + st = SQLTools.StrToDateTime(start); + if(end!=null) + et = SQLTools.StrToDateTime(end); + }else if(membertype.equals(Date.class)){ + longtime = false; + }else + return null; + } + }catch (Exception e){ + + } + + if(start!=null&&start.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + st.getTime() ; + } else + condition += " and " + timeKey() + ">=" + st.getTime() ; + }else { + if (condition == null) { + condition = " " + timeKey() + ">='" + start + "'"; + } else + condition += " and " + timeKey() + ">='" + start + "'"; + } + } + + if(end!=null&&end.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + et.getTime() ; + } else + condition += " and " + timeKey() + ">=" + et.getTime() ; + }else { + if (condition == null) + condition = " " + timeKey() + "<='" + end + "'"; + else + condition += " and " + timeKey() + "<='" + end + "'"; + } + } + + if(condition!=null){ + sql += " where "+condition; + } + + try{ + List list = SQLTools.queryPage(dataSource, getClass(),sql,pageindex,pagesize,orderKey()); + return list; + }catch (Exception e){ + tryCreateTable(dataSource); + + } + return null; + } + + public List queryList(DataSource dataSource,String start , String end){ + String condition = queryCondition(); + String sql = "select * from "+tableName(); + Date st = null; + Date et = null; + boolean longtime = false; + try { + Field fie = getClass().getField(timeKey()); + if(fie!=null){ + Class membertype = fie.getType(); + if(membertype.getName().equals("long")){ + longtime = true; + if(start!=null) + st = SQLTools.StrToDateTime(start); + if(end!=null) + et = SQLTools.StrToDateTime(end); + }else if(membertype.equals(Date.class)){ + longtime = false; + }else + return null; + } + }catch (Exception e){ + + } + + if(start!=null&&start.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + st.getTime() ; + } else + condition += " and " + timeKey() + ">=" + st.getTime() ; + }else { + if (condition == null) { + condition = " " + timeKey() + ">='" + start + "'"; + } else + condition += " and " + timeKey() + ">='" + start + "'"; + } + } + + if(end!=null&&end.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + et.getTime() ; + } else + condition += " and " + timeKey() + ">=" + et.getTime() ; + }else { + if (condition == null) + condition = " " + timeKey() + "<='" + end + "'"; + else + condition += " and " + timeKey() + "<='" + end + "'"; + } + } + + if(condition!=null){ + sql += " where "+condition; + } + + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, getClass()); + return list; + }catch (Exception e){ + tryCreateTable(dataSource); + + } + return null; + } + + public List queryList(DataSource dataSource,long start , long end){ + String condition = queryCondition(); + String sql = "select * from "+tableName(); + Date st = new Date(start); + Date et = new Date(end); + boolean longtime = false; + try { + Field fie = getClass().getField(timeKey()); + if(fie!=null){ + Class membertype = fie.getType(); + if(membertype.getName().equals("long")){ + longtime = true; + }else if(membertype.equals(Date.class)){ + longtime = false; + }else + return new ArrayList(); + } + }catch (Exception e){ + + } + + if(timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + st.getTime() ; + } else + condition += " and " + timeKey() + ">=" + st.getTime() ; + }else { + if (condition == null) { + condition = " " + timeKey() + ">='" + SQLTools.formatDate(st) + "'"; + } else + condition += " and " + timeKey() + ">='" + SQLTools.formatDate(st) + "'"; + } + } + + if(timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + et.getTime() ; + } else + condition += " and " + timeKey() + ">=" + et.getTime() ; + }else { + if (condition == null) + condition = " " + timeKey() + "<='" + SQLTools.formatDate(et) + "'"; + else + condition += " and " + timeKey() + "<='" + SQLTools.formatDate(et) + "'"; + } + } + + if(condition!=null){ + sql += " where "+condition; + } + + try{ + List list = SQLTools.ExecuteQuery(dataSource,sql, getClass()); + return list; + }catch (Exception e){ + tryCreateTable(dataSource); + + } + return null; + } + + + public boolean deleteRecords(DataSource dataSource,String start, String end){ + String condition = queryCondition(); + String sql = "delete from "+tableName(); + Date st = null; + Date et = null; + boolean longtime = false; + try { + Field fie = getClass().getField(timeKey()); + if(fie!=null){ + Class membertype = fie.getType(); + if(membertype.getName().equals("long")){ + longtime = true; + if(start!=null) + st = SQLTools.StrToDateTime(start); + if(end!=null) + et = SQLTools.StrToDateTime(end); + }else if(membertype.equals(Date.class)){ + longtime = false; + }else + return false; + } + }catch (Exception e){ + + } + + if(start!=null&&start.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + st.getTime() ; + } else + condition += " and " + timeKey() + ">=" + st.getTime() ; + }else { + if (condition == null) { + condition = " " + timeKey() + ">='" + start + "'"; + } else + condition += " and " + timeKey() + ">='" + start + "'"; + } + } + + if(end!=null&&end.length()>0&&timeKey()!=null){ + if(longtime) { + if (condition == null) { + condition = " " + timeKey() + ">=" + et.getTime() ; + } else + condition += " and " + timeKey() + ">=" + et.getTime() ; + }else { + if (condition == null) + condition = " " + timeKey() + "<='" + end + "'"; + else + condition += " and " + timeKey() + "<='" + end + "'"; + } + } + + if(condition!=null){ + sql += " where "+condition; + } + + try{ + return SQLTools.ExecuteSQL(dataSource,sql); + }catch (Exception e){ + return false; + } + + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SQLInsertCmd.java b/src/main/java/com/jingyi/iotserver/utils/SQLInsertCmd.java new file mode 100644 index 0000000..d446311 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SQLInsertCmd.java @@ -0,0 +1,112 @@ +package com.jingyi.iotserver.utils; + +import java.util.Date; + +public class SQLInsertCmd { + int count = 0; + private String namepart; + private String valuepart; + + public String getSql() { + return namepart+valuepart; + } + + public void start(String tablename){ + namepart = "INSERT INTO "+tablename+"("; + valuepart = " VALUES("; + } + + public void appenValue(String name,int val){ + if(count>0){ + namepart += ","; + valuepart += ","; + } + if(name.equals("signal")) + name = "radiosignal"; + namepart += name; + valuepart += val; + count++; + } + + public void appenValue(String name,long val){ + if(count>0){ + namepart += ","; + valuepart += ","; + } + namepart += name; + valuepart += val; + count++; + } + + public void appenValue(String name,double val){ + if(count>0){ + namepart += ","; + valuepart += ","; + } + namepart += name; + valuepart += val; + count++; + } + + public void appenValue(String name,float val){ + if(count>0){ + namepart += ","; + valuepart += ","; + } + namepart += name; + valuepart += val; + count++; + } + + public void appenValue(String name,short val){ + if(count>0){ + namepart += ","; + valuepart += ","; + } + namepart += name; + valuepart += val; + count++; + } + + public void appenValue(String name,byte val){ + if(count>0){ + namepart += ","; + valuepart += ","; + } + namepart += name; + valuepart += val; + count++; + } + + public void appenValue(String name,String val){ + if(val==null) + return ; + if(count>0){ + namepart += ","; + valuepart += ","; + } + if(name.equals("usage")) + name = "enableuse"; + + namepart += name; + valuepart += "'"+val+"'"; + count++; + } + + public void appenValue(String name, Date val){ + if(val==null) + return; + if(count>0){ + namepart += ","; + valuepart += ","; + } + namepart += name; + valuepart += "'"+SQLTools.formatDate(val)+"'"; + count++; + } + + public void end(){ + namepart+=")"; + valuepart+=")"; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SQLQueryCmd.java b/src/main/java/com/jingyi/iotserver/utils/SQLQueryCmd.java new file mode 100644 index 0000000..5c8e5af --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SQLQueryCmd.java @@ -0,0 +1,110 @@ +package com.jingyi.iotserver.utils; + +import java.util.Date; + +public class SQLQueryCmd { + int count = 0; + private String sql; + + public String getSql() { + return sql; + } + + public void start(String tablename){ + count = 0; + sql = "select * from "+tablename; + + } + + + public void appendValue(String name,int val){ + if(count>0){ + sql += " ,"; + sql += name + "="+val; + }else { + sql += " where "+name+"="+val; + } + + count++; + } + + public void appendValue(String name,long val){ + if(count>0){ + sql += " ,"; + sql += name + "="+val; + }else { + sql += " where "+name+"="+val; + } + + count++; + } + + public void appendValue(String name,double val){ + if(count>0){ + sql += " ,"; + sql += name + "="+val; + }else { + sql += " where "+name+"="+val; + } + + count++; + } + + public void appendValue(String name,float val){ + if(count>0){ + sql += " ,"; + sql += name + "="+val; + }else { + sql += " where "+name+"="+val; + } + + count++; + } + + public void appendValue(String name,short val){ + if(count>0){ + sql += " ,"; + sql += name + "="+val; + }else { + sql += " where "+name+"="+val; + } + + count++; + } + + public void appendValue(String name,byte val){ + if(count>0){ + sql += " ,"; + sql += name + "="+val; + }else { + sql += " where "+name+"="+val; + } + + count++; + } + + public void appendValue(String name,String val){ + if(val==null) + return ; + if(count>0){ + sql += " ,"; + sql += name + "='"+val+"'"; + }else { + sql += " where "+name+"='"+val+"'"; + } + + count++; + } + + public void appendValue(String name, Date val){ + if(val==null) + return ; + if(count>0){ + sql += " ,"; + sql += name + "='"+SQLTools.formatDate(val)+"'"; + }else { + sql += " where "+name+"='"+SQLTools.formatDate(val)+"'"; + } + count++; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SQLTools.java b/src/main/java/com/jingyi/iotserver/utils/SQLTools.java new file mode 100644 index 0000000..cf50eba --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SQLTools.java @@ -0,0 +1,722 @@ +package com.jingyi.iotserver.utils; + +import com.alibaba.druid.pool.DruidDataSource; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +//import com.sun.org.apache.xpath.internal.operations.Bool; + +import com.jingyi.iotserver.common.service.EnvConfigService; +import org.springframework.beans.BeanUtils; + +import javax.sql.DataSource; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.Date; + +public class SQLTools { + + static public String getDateString(Date date){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); //放入Date类型数据 + + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH); //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + + // int hour = calendar.get(Calendar.HOUR); //时(12小时制) + int hour = calendar.get(Calendar.HOUR_OF_DAY); //时(24小时制) + int minute = calendar.get(Calendar.MINUTE); //分 + int second = calendar.get(Calendar.SECOND); //秒 + + return null; + } + + static public Date getDay(Date date){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); //放入Date类型数据 + + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH); //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + + // int hour = calendar.get(Calendar.HOUR); //时(12小时制) + int hour = calendar.get(Calendar.HOUR_OF_DAY); //时(24小时制) + int minute = calendar.get(Calendar.MINUTE); //分 + int second = calendar.get(Calendar.SECOND); //秒 + + String ts = ""; + ts += year; + ts += "-"; + ts += month; + ts += "-"; + ts += day; + ts += " 00:00:00"; + return StrToDate(ts); + } + + static public Date getMonth(Date date){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); //放入Date类型数据 + + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH); //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + + // int hour = calendar.get(Calendar.HOUR); //时(12小时制) + int hour = calendar.get(Calendar.HOUR_OF_DAY); //时(24小时制) + int minute = calendar.get(Calendar.MINUTE); //分 + int second = calendar.get(Calendar.SECOND); //秒 + + String ts = ""; + ts += year; + ts += "-"; + ts += month; + ts += "-"; + ts += 1; + ts += " 00:00:00"; + return StrToDate(ts); + } + + static public Date getToday(){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); //放入Date类型数据 + + int year = calendar.get(Calendar.YEAR); //获取年份 + int month = calendar.get(Calendar.MONTH); //获取月份 + int day = calendar.get(Calendar.DATE); //获取日 + + // int hour = calendar.get(Calendar.HOUR); //时(12小时制) + int hour = calendar.get(Calendar.HOUR_OF_DAY); //时(24小时制) + int minute = calendar.get(Calendar.MINUTE); //分 + int second = calendar.get(Calendar.SECOND); //秒 + + String ts = ""; + ts += year; + ts += "-"; + ts += month; + ts += "-"; + ts += day; + ts += " 00:00:00"; + return StrToDate(ts); + } + + static public String formatDate(Date date){ + String format = "yyyy-MM-dd HH:mm:ss"; + // String format = "yyyy-MM-dd'T'HH:mm:ssZZZ"; + String str = new SimpleDateFormat(format).format(date); + return str; + } + + static public String formatDay(Date date){ + String format = "yyyy-MM-dd"; + String str = new SimpleDateFormat(format).format(date); + return str; + } + + public static Date StrToDate(String str) { + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + Date date = null; + try { + date = format.parse(str); + } catch (Exception e) { + // e.printStackTrace(); + } + return date; + } + + public static Date StrToDateTime(String str) { + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = null; + try { + date = format.parse(str); + } catch (Exception e) { + // e.printStackTrace(); + } + return date; + } + + static public boolean ExecuteSQL(DataSource dataSource,String sql){ + boolean rel = false; + Connection conn = null; + java.sql.Statement stmt = null; + try { + StringBuffer ddl = new StringBuffer(); + ddl.append(sql); + conn = dataSource.getConnection(); + + stmt = conn.createStatement(); + try { + rel = stmt.execute(ddl.toString()); + rel = true; + }catch (Exception e){ + e.printStackTrace(); + } + if(stmt!=null) { + stmt.close(); + stmt = null; + } + + if(conn!=null) { + conn.close(); + conn = null; + } + }catch (Exception e){ + if(stmt!=null) { + try { + stmt.close(); + }catch (Exception ee){ + + } + stmt = null; + } + + if(conn!=null) { + try { + conn.close(); + }catch (Exception ee){ + + } + conn = null; + } + } + return rel; + } + + static public int ExecuteInsertSQLGetIdentify(DataSource dataSource,String sql){ + boolean rel = false; + Connection conn = null; + PreparedStatement stmt = null; + int id = -1; + try { + StringBuffer ddl = new StringBuffer(); + ddl.append(sql); + conn = dataSource.getConnection(); + + try { + stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + stmt.executeUpdate(); + ResultSet rs = stmt.getGeneratedKeys(); + if(rs.next()){ + id = rs.getInt(1); + } + rel = true; + }catch (Exception e){ + e.printStackTrace(); + } + if(stmt!=null) { + stmt.close(); + stmt = null; + } + + if(conn!=null) { + conn.close(); + conn = null; + } + }catch (Exception e){ + + }finally { + if(stmt!=null) { + try { + stmt.close(); + }catch (Exception ee){ + + } + stmt = null; + } + + if(conn!=null) { + try { + conn.close(); + }catch (Exception ee){ + + } + conn = null; + } + } + + return id; + } + + static public List ExecuteQuery(DataSource dataSource,String sql,Class cl){ + ResultSet result = null; + List list = null; + Connection conn = null; + java.sql.Statement stmt = null; + try { + StringBuffer ddl = new StringBuffer(); + ddl.append(sql); + conn = dataSource.getConnection(); + + stmt = conn.createStatement(); + try { + stmt.execute(ddl.toString()); + result = stmt.getResultSet(); + list = getListFromResultSet(cl, result); + }catch (Exception e){ + e.printStackTrace(); + } + if(stmt!=null) { + stmt.close(); + stmt = null; + } + + if(conn!=null) { + conn.close(); + conn = null; + } + }catch (Exception e){ + if(stmt!=null) { + try { + stmt.close(); + }catch (Exception ee){ + + } + stmt = null; + } + + if(conn!=null) { + try { + conn.close(); + }catch (Exception ee){ + + } + conn = null; + } + return list; + } + return list; + } + + public static int ExecuteQueryCount(DataSource dataSource,String sql){ + ResultSet result = null; + Connection conn = null; + java.sql.Statement stmt = null; + int rel = 0; + try { + StringBuffer ddl = new StringBuffer(); + ddl.append(sql); + conn = dataSource.getConnection(); + + stmt = conn.createStatement(); + try { + stmt.execute(ddl.toString()); + result = stmt.getResultSet(); + if(result.next()) { + rel = result.getInt(1); + } + }catch (Exception e){ + e.printStackTrace(); + } + if(stmt!=null) { + stmt.close(); + stmt = null; + } + + if(conn!=null) { + conn.close(); + conn = null; + } + }catch (Exception e){ + if(stmt!=null) { + try { + stmt.close(); + }catch (Exception ee){ + + } + stmt = null; + } + + if(conn!=null) { + try { + conn.close(); + }catch (Exception ee){ + + } + conn = null; + } + return 0; + } + return rel; + } + + public static int ExecuteQueryCount(DataSource dataSource,String tablename, String condition){ + String sql; + if(condition==null) + sql = "SELECT COUNT(*) FROM "+tablename; + else + sql = "SELECT COUNT(*) FROM "+tablename+" WHERE "+condition; + return ExecuteQueryCount(dataSource,sql); + } + + public static List queryPage(DataSource dataSource,Class cl,String sql,int pageIndex,int pageSize,String byorder){ + String cmd ; + boolean sqlserver = false; + try { + DruidDataSource ds = (DruidDataSource) dataSource; + if(ds.getUrl().indexOf("mysql")>=0) + sqlserver = false; + else if(ds.getUrl().indexOf("sqlserver")>=0) + sqlserver = true; + else + sqlserver = false; + }catch (Exception e){ + sqlserver = false; + } + + if(sqlserver) + { + cmd = "SELECT * FROM(SELECT ROW_NUMBER() OVER (ORDER BY "+byorder+" ) AS Row_Number,* FROM("+ + sql+" ) AS REALLAYOUT) AS RESULT WHERE Row_Number>"+pageIndex*pageSize+" AND Row_Number<="+ + (pageIndex+1)*pageSize; + }else {//DESC + cmd = sql + " ORDER BY "+byorder + " ASC"+" limit " + pageIndex * pageSize + "," + pageSize ; + } + + Connection conn = null; + java.sql.Statement stmt = null; + ResultSet result = null; + List list = null; + try { + StringBuffer ddl = new StringBuffer(); + ddl.append(cmd); + + conn = dataSource.getConnection(); + + stmt = conn.createStatement(); + stmt.execute(ddl.toString()); + result = stmt.getResultSet(); + list = getListFromResultSet(cl,result); + if(stmt!=null) { + stmt.close(); + stmt = null; + } + + if(conn!=null) { + conn.close(); + conn = null; + } + }catch (Exception e){ + if(stmt!=null) { + try { + stmt.close(); + }catch (Exception ee){ + + } + stmt = null; + } + + if(conn!=null) { + try { + conn.close(); + }catch (Exception ee){ + + } + conn = null; + } + } + return list; + } + + static public boolean CheckTableExist(DataSource dataSource,String database,String tablename){ + boolean rel = false; + return false; + /* + try { + String sql = "select count(*) from sysobjects where id = object_id('"+database+".Owner."+tablename+"')"; + StringBuffer ddl = new StringBuffer(); + ddl.append(sql); + Connection conn = dataSource.getConnection(); + + java.sql.Statement stmt = conn.createStatement(); + try { + stmt.execute(ddl.toString()); + stmt.getResultSetType(); + DruidPooledResultSet result = (DruidPooledResultSet)stmt.getResultSet(); + + ResultSet rs = result.getRawResultSet(); + ResultSetMetaData meta = rs.getMetaData(); + + // meta. + int count = meta.getColumnCount(); + if(count>0) + rel = true; + }catch (Exception e){ + e.printStackTrace(); + } + stmt.close(); + conn.close(); + + }catch (Exception e){ + e.printStackTrace(); + + } + return rel; + */ + } + + static public List getListFromResultSet(Class element, ResultSet result){ + List list = new ArrayList(); + try { + Map propertymap = new HashMap(); + PropertyDescriptor pds[] = BeanUtils.getPropertyDescriptors(element); + for(int i = 0; i < pds.length; i++){ + propertymap.put(pds[i].getName(),pds[i]); + } + + ResultSetMetaData md = result.getMetaData();//获取键名 + int columnCount = md.getColumnCount();//获取行的数量 + + while (result.next()) { + Object beanObj = element.getConstructor().newInstance(); + for (int i = 1; i <= columnCount; i++) { + try{ + String colname = md.getColumnName(i);//获取键名 + Object value = result.getObject(i);//获取键值 + Method method = propertymap.get(colname).getWriteMethod(); + + //注意这里的参数。 + method.invoke(beanObj, value); + }catch(Exception iea){ + // System.out.println("参数错误。"); + // iea.printStackTrace(); + } + + } + list.add(beanObj); + } + }catch (Exception e){ + // e.printStackTrace(); + } + return list; + } + + static public Object getEntityFromJson(String json,Class element ){ + Object beanObj = null; + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null) + return null; + beanObj = getEntityFromJson(rootnode,element); + + }catch (Exception e){ + + } + return beanObj; + } + + static public Object getEntityFromJson(JsonNode rootnode,Class element ){ + Object beanObj = null; + try { + Map propertymap = new HashMap(); + PropertyDescriptor pds[] = BeanUtils.getPropertyDescriptors(element); + for (int i = 0; i < pds.length; i++) { + propertymap.put(pds[i].getName(), pds[i]); + } + + beanObj = element.getConstructor().newInstance(); + + try { + if (rootnode == null) + return null; + + Iterator> iterator = rootnode.fields(); + while (iterator.hasNext()) { + Map.Entry property = iterator.next(); + String title = property.getKey(); + if (title != null) { + JsonNode pro = property.getValue(); + if (pro != null ) { + try { + Method method = propertymap.get(title).getWriteMethod(); + + PropertyDescriptor member = propertymap.get(title); + Class membertype = member.getPropertyType(); + if(membertype.equals(Date.class)){ + Date date = StrToDateTime(pro.asText()); + if(date==null) + date = StrToDate(pro.asText()); + if(date==null){ + try{ + date = new Date(pro.asLong()); + }catch (Exception e){ + + } + } + method.invoke(beanObj, date); + }else if(membertype.equals(String.class)){ + if(pro.isNull()) + method.invoke(beanObj, null); + else + method.invoke(beanObj, pro.asText()); + }else if(membertype.getName().equals("int")) { + if(pro.isInt()) + method.invoke(beanObj, pro.asInt()); + else if(pro.isFloat()|| pro.isDouble()) + method.invoke(beanObj,(int)pro.asDouble()); + else if(pro.isLong()) + method.invoke(beanObj, (int)pro.asLong()); + }else if(membertype.getName().equals("float")&&(pro.isFloat()|| pro.isDouble()||pro.isInt())){ + method.invoke(beanObj, (float)pro.asDouble()); + }else if(membertype.getName().equals("double")&&(pro.isFloat()|| pro.isDouble()||pro.isInt())){ + method.invoke(beanObj, pro.asDouble()); + }else if(membertype.getName().equals("boolean")&&pro.isBoolean()){ + method.invoke(beanObj, pro.asBoolean()); + }else if(membertype.getName().equals("long")&&pro.isLong()){ + method.invoke(beanObj, pro.asLong()); + } + + } catch (IllegalArgumentException iea) { + // System.out.println("参数错误。"); + // iea.printStackTrace(); + }catch (Exception e) { + // e.printStackTrace(); + } + } + } + } + + + } catch (Exception e) { + // e.printStackTrace(); + } + }catch (Exception e){ + + } + return beanObj; + } + + static public List getEntityListFromJson(String json,Class element ){ + List list = null; + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootnode = mapper.readTree(json); + if (rootnode == null) + return null; + return getEntityListFromJsonArray(rootnode,element); + + }catch (Exception e){ + e.printStackTrace(); + } + return list; + } + + static public List getEntityListFromJsonArray(JsonNode rootnode,Class element ){ + List list = new ArrayList(); + Object beanObj = null; + + try { + Map propertymap = new HashMap(); + PropertyDescriptor pds[] = BeanUtils.getPropertyDescriptors(element); + for (int i = 0; i < pds.length; i++) { + propertymap.put(pds[i].getName(), pds[i]); + Class ty = pds[i].getPropertyType(); + String typname = ty.getName(); + if(typname.equals(Date.class.getName())){ + + } + } + + try { + if (rootnode == null) + return null; + + if(!rootnode.isArray()) + return null; + for(int i=0;i> iterator = node.fields(); + while (iterator.hasNext()) { + Map.Entry property = iterator.next(); + String title = property.getKey(); + // System.out.print("title:"+title); + if (title != null) { + JsonNode pro = property.getValue(); + // System.out.println(" value:"+title); + if (pro != null) { + try { + Method method = propertymap.get(title).getWriteMethod(); + + PropertyDescriptor member = propertymap.get(title); + Class membertype = member.getPropertyType(); + if(membertype.equals(Date.class)){ + Date date = StrToDateTime(pro.asText()); + if(date==null) + date = StrToDate(pro.asText()); + if(date==null){ + try{ + date = new Date(pro.asLong()); + }catch (Exception e){ + + } + } + method.invoke(beanObj, date); + }else if(membertype.equals(String.class)){ + if(pro.isNull()) + method.invoke(beanObj, null); + else + method.invoke(beanObj, pro.asText()); + }else if(membertype.getName().equals("int")) { + if(pro.isInt()) + method.invoke(beanObj, pro.asInt()); + else if(pro.isFloat()|| pro.isDouble()) + method.invoke(beanObj,(int)pro.asDouble()); + else if(pro.isLong()) + method.invoke(beanObj, (int)pro.asLong()); + }else if(membertype.getName().equals("float")&&(pro.isFloat()|| pro.isDouble()||pro.isInt())){ + method.invoke(beanObj, (float)pro.asDouble()); + }else if(membertype.getName().equals("double")&&(pro.isFloat()|| pro.isDouble()||pro.isInt())){ + method.invoke(beanObj, pro.asDouble()); + }else if(membertype.getName().equals("boolean")&&pro.isBoolean()){ + method.invoke(beanObj, pro.asBoolean()); + }else if(membertype.getName().equals("long")&&(pro.isLong()||pro.isInt())){ + method.invoke(beanObj, pro.asLong()); + } + + procount++; + } catch (Exception iea) { + // System.out.println("参数错误。"); + // iea.printStackTrace(); + + } + } + } + } + if(procount>0) + list.add(beanObj); + } + + } catch (Exception e) { + // e.printStackTrace(); + } + }catch (Exception e){ + // e.printStackTrace(); + } + return list; + } + + public static List getFiledsInfo(Class clazz) throws ClassNotFoundException { + List list = new ArrayList<>(); + // Class clazz = Class.forName(className); + Field[] fields = clazz.getDeclaredFields(); + list.addAll(Arrays.asList(fields)); + Class superClazz = clazz.getSuperclass(); + if (superClazz != null) { + Field[] superFields = superClazz.getDeclaredFields(); + list.addAll(Arrays.asList(superFields)); + } + return list; + } + + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SQLUpdateCmd.java b/src/main/java/com/jingyi/iotserver/utils/SQLUpdateCmd.java new file mode 100644 index 0000000..e1646b6 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SQLUpdateCmd.java @@ -0,0 +1,126 @@ +package com.jingyi.iotserver.utils; + +import java.util.Date; + +public class SQLUpdateCmd { + int count = 0; + private String sql; + private String contidion; + + public String getSql() { + return sql+contidion; + } + + public void start(String tablename,String key,String keyval){ + count = 0; + sql = "update "+tablename+" set "; + if(key!=null&&keyval!=null) + contidion = " where "+key+"='"+keyval+"'"; + } + + public void start(String tablename,String key,int keyval){ + count = 0; + sql = "update "+tablename+" set "; + if(key!=null) + contidion = " where "+key+"='"+keyval+"'"; + } + + public void appendKey(String key,String keyval){ + if(contidion==null){ + contidion = " where "+key+"='"+keyval+"'"; + }else{ + contidion += " and "+key+"='"+keyval+"'"; + } + } + + public void appendKey(String key,int keyval){ + if(contidion==null){ + contidion = " where "+key+"="+keyval+""; + }else{ + contidion += " and "+key+"="+keyval+""; + } + } + + public void appendKey(String key,long keyval){ + if(contidion==null){ + contidion = " where "+key+"="+keyval+""; + }else{ + contidion += " and "+key+"="+keyval+""; + } + } + + public void appendKey(String key,Date keyval){ + if(contidion==null){ + contidion = " where "+key+"='"+SQLTools.formatDate(keyval)+"'"; + }else{ + contidion += " and "+key+"='"+SQLTools.formatDate(keyval)+"'"; + } + } + + public void appendValue(String name,long val){ + if(count>0){ + sql += " ,"; + } + sql += name + "="+val; + count++; + } + + public void appendValue(String name,int val){ + if(count>0){ + sql += " ,"; + } + sql += name + "="+val; + count++; + } + public void appendValue(String name,double val){ + if(count>0){ + sql += " ,"; + } + sql += name + "="+val; + count++; + } + + public void appendValue(String name,float val){ + if(count>0){ + sql += " ,"; + } + sql += name + "="+val; + count++; + } + + public void appendValue(String name,short val){ + if(count>0){ + sql += " ,"; + } + sql += name + "="+val; + count++; + } + + public void appendValue(String name,byte val){ + if(count>0){ + sql += " ,"; + } + sql += name + "="+val; + count++; + } + + public void appendValue(String name,String val){ + if(val==null||val.equals("null")) + return; + if(count>0){ + sql += " ,"; + } + sql += name + "='"+val+"'"; + count++; + } + + public void appendValue(String name, Date val){ + if(val==null||val.equals("null")) + return; + if(count>0){ + sql += " ,"; + } + sql += name + "='"+SQLTools.formatDate(val)+"'"; + count++; + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SkynetHikAPI.java b/src/main/java/com/jingyi/iotserver/utils/SkynetHikAPI.java new file mode 100644 index 0000000..82d63f5 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SkynetHikAPI.java @@ -0,0 +1,309 @@ +package com.jingyi.iotserver.utils; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.hikvision.artemis.sdk.ArtemisHttpUtil; +import com.hikvision.artemis.sdk.config.ArtemisConfig; +import com.jingyi.iotserver.firestationport.model.school.PersonBlacklistEntity; +import com.jingyi.iotserver.firestationport.model.sensor.SkynetIPCEntity; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.FaceAlarmPersonSummary; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.FaceAlarmStationSummary; +import com.jingyi.iotserver.firestationport.model.sensor.aiipc.HikFaceAlarmRecordEntity; +import com.jingyi.iotserver.firestationport.websocket.ClientWebsocketManager; +import com.jingyi.iotserver.iotctrl.IoTCtrlServer; +import org.gavaghan.geodesy.GlobalCoordinates; + +import javax.sql.DataSource; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SkynetHikAPI { + + /** + * STEP2:设置OpenAPI接口的上下文 + */ + public static final String ARTEMIS_PATH = "/artemis"; + + public static String getTimestamp(long ts){ + SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + String timestamp = formater.format(ts); + return timestamp; + } + + public static Date HikTimeToDateTime(String str) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + Date date = null; + try { + date = format.parse(str); + } catch (Exception e) { + // e.printStackTrace(); + } + return date; + } + + public static void initHK(){ + /** + * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数. + */ + //ArtemisConfig.host = "192.168.10.240:2443"; // artemis网关服务器ip端口 + ArtemisConfig.host = "43.15.244.10:443"; // artemis网关服务器ip端口 + ArtemisConfig.appKey = "29630331"; // 秘钥appkey 834710595 芙蓉区校园安防 + ArtemisConfig.appSecret = "7ZDkgURAMuRh9h7FvqOj";// 秘钥appSecret + } + + public static String queryFaceAlarmRecords(IoTCtrlServer ioTCtrlServer, DataSource dataSource, ClientWebsocketManager clientWebsocketManager) { + initHK(); + /** + * STEP3:设置接口的URI地址 + */ + final String previewURLsApi = ARTEMIS_PATH + "/api/aiapplication/v3/face/queryFaceAlarmRecordsWithPage"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + /** + * STEP4:设置参数提交方式 + */ + String contentType = "application/json"; + + /** + * STEP5:组装请求参数,804661589 2022下半年全国在逃库布控 + */ + JSONObject jsonBody = new JSONObject(); + jsonBody.put("pageNo", 1); + jsonBody.put("pageSize", 100); + jsonBody.put("taskId", "834710595"); + jsonBody.put("name", "芙蓉区校园安防"); + + long currentTime = new Date().getTime(); + String endTime = getTimestamp(currentTime);// ;"2023-07-15T01:00:00.000+08:00" + String startTime = getTimestamp(currentTime - 700000);// ; "2023-07-18T01:00:00.000+08:00" + + System.out.println("Skynet HikvisionAPI: startTime = " + startTime); + System.out.println("Skynet HikvisionAPI: endTime = " + endTime); + + jsonBody.put("beginTime", startTime); + jsonBody.put("endTime", endTime); + String body = jsonBody.toJSONString(); + /** + * STEP6:调用接口 + */ + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数 + // System.out.println("Skynet HikvisionAPI: queryFaceAlarmRecords = " + result); + + try { + JSONObject rootJs = JSON.parseObject(result); + if(!rootJs.containsKey("code")){ + return "error"; + } + String strCode = rootJs.getString("code"); + if(strCode == null){ + return "error"; + } + if(!strCode.equalsIgnoreCase("0")){ + return "error"; + } + + if(!rootJs.containsKey("data")){ + return "no data"; + } + + String data1 = rootJs.getString("data"); + JSONObject dataJs1 = JSON.parseObject(data1); + + int ipcTotal = dataJs1.getIntValue("total"); + + System.out.println("HikvisionAPI: GetDeviceList = " + ipcTotal); + JSONArray jsonArray = dataJs1.getJSONArray("list"); + List alarmRecordEntitieListOrg = jsonArray.toJavaList(HikFaceAlarmRecordEntity.class); + + if(alarmRecordEntitieListOrg != null && alarmRecordEntitieListOrg.size() > 0){ + + List alarmRecordEntitieList = new ArrayList<>(new HashSet<>(alarmRecordEntitieListOrg)); + + Calendar signDayTime = Calendar.getInstance(); + String sYear = String.valueOf(signDayTime.get(Calendar.YEAR)); + String sMonth = String.valueOf(signDayTime.get(Calendar.MONTH)+1); + String sDay = String.valueOf(signDayTime.get(Calendar.DAY_OF_MONTH)); + + for(HikFaceAlarmRecordEntity ipcAlarm: alarmRecordEntitieList){ + + HikFaceAlarmRecordEntity oldAlarm = (HikFaceAlarmRecordEntity)ipcAlarm.QueryIt(dataSource); + if(oldAlarm != null){ + continue; + } + Gps gdGps = PositionUtil.gps84_To_Gcj02(ipcAlarm.getLatitude(), ipcAlarm.getLongitude()); + ipcAlarm.setLatitude(gdGps.getWgLat()); + ipcAlarm.setLongitude(gdGps.getWgLon()); + + ipcAlarm.setReadState(HikFaceAlarmRecordEntity.STATE_Unread); + + SkynetIPCEntity hikIPC = SkynetIPCEntity.QueryWithCameraCode(dataSource, ipcAlarm.getCameraIndexCode()); + SkynetIPCEntity hikIPCName = SkynetIPCEntity.QueryWithCameraName(dataSource, ipcAlarm.getCameraName()); + + if(hikIPC != null){ + saveFaceAlarm(ioTCtrlServer, dataSource, clientWebsocketManager, ipcAlarm, hikIPC,sYear , sMonth, sDay); + }else if(hikIPCName != null){ + System.out.println("Skynet HikvisionAPI: QueryWithCameraName = " + JSON.toJSONString(hikIPCName)); + saveFaceAlarm(ioTCtrlServer,dataSource, clientWebsocketManager, ipcAlarm, hikIPCName,sYear , sMonth, sDay); + } else{ + List nearIPCList = SkynetIPCEntity.searchPosition(dataSource, ipcAlarm.getLatitude(), ipcAlarm.getLongitude(), 0.007); + + if(nearIPCList != null){ + System.out.println("Skynet HikvisionAPI: queryFaceAlarm with positon ipc = " + JSON.toJSONString(ipcAlarm)); + double nearestDis = 1000; + SkynetIPCEntity nearestIPC = null; + GlobalCoordinates gpsFrom = new GlobalCoordinates(ipcAlarm.getLatitude(), ipcAlarm.getLongitude()); + System.out.println("Skynet HikvisionAPI: queryFaceAlarm with positon dis = " + nearIPCList.size()); + for(int ipcIndex = 0; ipcIndex < nearIPCList.size(); ipcIndex++){ + SkynetIPCEntity ipcEntity = nearIPCList.get(ipcIndex); + GlobalCoordinates gpsTo = new GlobalCoordinates(ipcEntity.getLatitude(), ipcEntity.getLongitude()); + double ipcDis = PositionUtil.getDistanceMeter(gpsFrom, gpsTo); + + if(ipcDis < nearestDis){ + nearestDis = ipcDis; + nearestIPC = ipcEntity; + } + } + if(nearestIPC != null){ + System.out.println("Skynet HikvisionAPI: queryFaceAlarm with positon ipc nearest dis = " + nearestDis); + System.out.println("Skynet HikvisionAPI: queryFaceAlarm with positon ipc = " + JSON.toJSONString(nearestIPC)); + + saveFaceAlarm(ioTCtrlServer,dataSource, clientWebsocketManager, ipcAlarm, nearestIPC,sYear , sMonth, sDay); + } + } + } + + } + + return "ok"; + } + }catch (Exception e){ + } + + + return "ok"; + } + + private static void saveFaceAlarm(IoTCtrlServer ioTCtrlServer, DataSource dataSource, ClientWebsocketManager clientWebsocketManager, HikFaceAlarmRecordEntity ipcAlarm, SkynetIPCEntity hikIPC, + String sYean , String sMonth, String sDay){ + ipcAlarm.setBrigade(hikIPC.getBrigade()); + ipcAlarm.setBorough(hikIPC.getBorough()); + ipcAlarm.setDetachment(hikIPC.getDetachment()); + ipcAlarm.setStation(hikIPC.getStation()); + ipcAlarm.setLatitude(hikIPC.getLatitude()); + ipcAlarm.setLongitude(hikIPC.getLongitude()); + ipcAlarm.setPointCode(hikIPC.getPointCode()); + ipcAlarm.setCameraName(hikIPC.getName()); + ipcAlarm.setTimestamp(HikTimeToDateTime(ipcAlarm.getAlarmTime())); + + PersonBlacklistEntity personBlacklist = new PersonBlacklistEntity(); + personBlacklist.setPersonId(ipcAlarm.getCertificateNumber()); + personBlacklist = (PersonBlacklistEntity)personBlacklist.QueryIt(dataSource); + if(personBlacklist != null){ + if(personBlacklist.getGroupType() != null) { + ipcAlarm.setGroupType(personBlacklist.getGroupType()); + } + }else{ + personBlacklist = new PersonBlacklistEntity(); + personBlacklist.setPersonId(ipcAlarm.getCertificateNumber()); + personBlacklist.setPersonName(ipcAlarm.getPersonName()); + personBlacklist.setGenderName(ipcAlarm.getRegisterGenderName()); + personBlacklist.Insert(dataSource); + } + + ipcAlarm.Insert(dataSource); + + if(ipcAlarm.getStation() != null){ + FaceAlarmStationSummary faceAlarm = new FaceAlarmStationSummary(); + faceAlarm.setStation(ipcAlarm.getStation()); + faceAlarm.setYear(sYean); + faceAlarm.setMonth(sMonth); + faceAlarm.setDay(sDay); + + FaceAlarmStationSummary faceAlarmOrg = (FaceAlarmStationSummary)faceAlarm.QueryIt(dataSource); + if(faceAlarmOrg != null){ + faceAlarm.setAlarmCount(faceAlarmOrg.getAlarmCount()+1); + faceAlarm.setLastTimestamp(ipcAlarm.getTimestamp()); + faceAlarm.setLastPicUrl(ipcAlarm.getSnappedPicUrl()); + faceAlarm.Update(dataSource); + }else{ + faceAlarm.setAlarmCount(1); + faceAlarm.setLastTimestamp(ipcAlarm.getTimestamp()); + faceAlarm.setLastPicUrl(ipcAlarm.getSnappedPicUrl()); + faceAlarm.setBrigade(ipcAlarm.getBrigade()); + faceAlarm.setBorough(ipcAlarm.getBorough()); + faceAlarm.setDetachment(ipcAlarm.getDetachment()); + faceAlarm.Insert(dataSource); + } + } + + if(personBlacklist.getPersonId() != null){ + FaceAlarmPersonSummary personAlarm = new FaceAlarmPersonSummary(); + personAlarm.setPersonId(ipcAlarm.getCertificateNumber()); + personAlarm.setYear(sYean); + personAlarm.setMonth(sMonth); + personAlarm.setDay(sDay); + + FaceAlarmPersonSummary faceAlarmOrg = (FaceAlarmPersonSummary)personAlarm.QueryIt(dataSource); + if(faceAlarmOrg != null){ + personAlarm.setAlarmCount(faceAlarmOrg.getAlarmCount()+1); + personAlarm.setLastTimestamp(ipcAlarm.getTimestamp()); + personAlarm.setLastPicUrl(ipcAlarm.getSnappedPicUrl()); + personAlarm.Update(dataSource); + }else{ + personAlarm.setAlarmCount(1); + personAlarm.setLastTimestamp(ipcAlarm.getTimestamp()); + personAlarm.setLastPicUrl(ipcAlarm.getSnappedPicUrl()); + personAlarm.Insert(dataSource); + } + } + + /* + HikFaceAlarmNotify eventNotify = new HikFaceAlarmNotify(ipcAlarm); + FireStationBaseInfoEntity from = FireStationBaseInfoEntity.Query(dataSource, ipcAlarm.getStation()); + if (from != null) { + WebNotifyProperty pro = new WebNotifyProperty(); + pro.setBrigade(from.getBrigade()); + pro.setBorough(from.getBorough()); + pro.setDetachment(from.getDetachment()); + pro.setStation(from.getName()); + pro.setDevice_id(eventNotify.getCameraIndexCode()); + pro.setDevice_type("skynet"); + eventNotify.attachProperty(pro); + clientWebsocketManager.addWebNotify(eventNotify); + } + + */ + + /* + if(FireCtrlSystemInit.netMode == 0) { + + ipcAlarm.setBkgPicUrl(""); + ipcAlarm.setBkgPicUrlBak(""); + ipcAlarm.setRefrencePicUrl(""); + + MessageToStation msg = new MessageToStation(); + msg.setMessage("skynet_face"); + msg.setData(JSON.toJSONString(ipcAlarm)); + msg.setTitle("iot"); + String str = JsonHelper.convertObjectToStr(msg); + + UDPAgentMQTTMessage agentMQTTMessage = new UDPAgentMQTTMessage(); + agentMQTTMessage.setMessage(str); + agentMQTTMessage.setTopic(ipcAlarm.getStation()); + try { + ioTCtrlServer.translateHttp2Internet(UDPAgentPackage.TYPE_MDEV_MQTT, JSON.toJSONString(agentMQTTMessage)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + */ + + } + +} diff --git a/src/main/java/com/jingyi/iotserver/utils/SpringContextUtil.java b/src/main/java/com/jingyi/iotserver/utils/SpringContextUtil.java new file mode 100644 index 0000000..ff14146 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/SpringContextUtil.java @@ -0,0 +1,57 @@ +package com.jingyi.iotserver.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import org.springframework.web.context.support.WebApplicationContextUtils; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +@Component +public class SpringContextUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + @Override + public void setApplicationContext(ApplicationContext ac) throws BeansException { + applicationContext = ac; + } + + public static Object getBean(Class cls){ + return applicationContext.getBean(cls); + } + + public static Object getWebBean(HttpServletRequest request, Class cls){ + return getWebSpringContext(request).getBean(cls); + } + + public static Object getWebBean(HttpSession session, Class cls){ + return getWebSpringContext(session).getBean(cls); + } + + public static Object getWebBean(ServletContext servletContext, Class cls){ + return getWebSpringContext(servletContext).getBean(cls); + } + + public static ApplicationContext getWebSpringContext(ServletContext servletContext){ + return WebApplicationContextUtils.getWebApplicationContext(servletContext); + } + + public static ApplicationContext getWebSpringContext(HttpServletRequest request){ + return getWebSpringContext(request.getServletContext()); + } + + public static ApplicationContext getWebSpringContext(HttpSession session){ + return getWebSpringContext(session.getServletContext()); + } + + + +} \ No newline at end of file diff --git a/src/main/java/com/jingyi/iotserver/utils/TokenUtils.java b/src/main/java/com/jingyi/iotserver/utils/TokenUtils.java new file mode 100644 index 0000000..e8a3e7f --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/TokenUtils.java @@ -0,0 +1,137 @@ +package com.jingyi.iotserver.utils; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtBuilder; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import javax.crypto.spec.SecretKeySpec; +import javax.xml.bind.DatatypeConverter; +import java.security.Key; +import java.util.Date; + +//maven: jjwt + +public class TokenUtils { + /** + * 签名秘钥 + */ + + public static final String SECRET = "admin"; + /** + * 生成token + * + * @param id 一般传入userName + * @return + */ + + public static String createJwtToken(String id) { + + String issuer = "www.jingyi.com"; + + String subject = "jingyi@126.com"; + + long ttlMillis = 3600000; + + return createJwtToken(id, issuer, subject, ttlMillis); + + } + + /** + + * 生成Token + + * + + * @param id 编号 + + * @param issuer 该JWT的签发者,是否使用是可选的 + + * @param subject 该JWT所面向的用户,是否使用是可选的; + + * @param ttlMillis 签发时间 (有效时间,过期会报错) + + * @return token String + + */ + + public static String createJwtToken(String id, String issuer, String subject, long ttlMillis) { + + + + // 签名算法 ,将对token进行签名 + + SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; + + + + // 生成签发时间 + + long nowMillis = System.currentTimeMillis(); + + Date now = new Date(nowMillis); + + + + // 通过秘钥签名JWT + + byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(SECRET); + + Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName()); + + + + // Let's set the JWT Claims + + JwtBuilder builder = Jwts.builder().setId(id) + + .setIssuedAt(now) + + .setSubject(subject) + + .setIssuer(issuer) + + .signWith(signatureAlgorithm, signingKey); + + + + // if it has been specified, let's add the expiration + + if (ttlMillis >= 0) { + + long expMillis = nowMillis + ttlMillis; + + Date exp = new Date(expMillis); + + builder.setExpiration(exp); + + } + + + + // Builds the JWT and serializes it to a compact, URL-safe string + + return builder.compact(); + + + + } + + + + // Sample method to validate and read the JWT + + public static Claims parseJWT(String jwt) { + + // This line will throw an exception if it is not a signed JWS (as expected) + + Claims claims = Jwts.parser() + + .setSigningKey(DatatypeConverter.parseBase64Binary(SECRET)) + + .parseClaimsJws(jwt).getBody(); + + return claims; + + } +} diff --git a/src/main/java/com/jingyi/iotserver/utils/TriDESEncryptUtil.java b/src/main/java/com/jingyi/iotserver/utils/TriDESEncryptUtil.java new file mode 100644 index 0000000..8aba178 --- /dev/null +++ b/src/main/java/com/jingyi/iotserver/utils/TriDESEncryptUtil.java @@ -0,0 +1,72 @@ +package com.jingyi.iotserver.utils; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +//import java.util.Base64; +import org.apache.commons.codec.binary.Base64; + +public class TriDESEncryptUtil { + + //定义加密算法:有DES、DESede(即3DES)、Blowfish + private static String Algorithm = "DESede"; + + public static byte[] DESEncrypt(String key,String data) { + try { + //SecretKey:是对密钥和算法类型(3DES)进行封装识别的一个标准定义 + SecretKey deskey = new SecretKeySpec(key.getBytes(), Algorithm); + Cipher cipher = Cipher.getInstance("DESede");//初始化加密并申明加密算法类型 + /** + * Cipher的几种模式: + * .ENCRYPT_MODE:加密模式, + * .DECRYPT_MODE:解密模式 + * .WRAP_MODE:对key-value进行包装 + * .UNWRAP_MODE:对key-value进行不包装 + */ + cipher.init(Cipher.ENCRYPT_MODE, deskey);//如果是加密则使用加密模式,反之 + byte[] bytes = cipher.doFinal(data.getBytes()); + return bytes; + } catch (Exception ex) { + ex.printStackTrace(); //加密失败,打日志 + } + return null; + } + + /** + *3DES解密还原文 + * 同理,第一步:初始化密钥和算法类型标准协议配置, + * 第二步:初始化校正加密算法类型,使用解密模式 + * 第三步:对数据进行解密,返回转换成字符串解密数据 + * @param data + * @return + */ + public static String DESDecrypt(String key,byte[] data) { + try { + SecretKey deskey = new SecretKeySpec(key.getBytes(), Algorithm); + Cipher cipher = Cipher.getInstance("DESede"); + //ENCRYPT_MODE:解密模式 + cipher.init(Cipher.DECRYPT_MODE, deskey); + byte[] bytes = cipher.doFinal(data); + return new String(bytes, "utf-8").toString(); + } catch (Exception ex) { + ex.printStackTrace();//解密失败,打日志 + } + return null; + } + + public static String StringDESEncrypt2Base64(String key,String src){ + byte[] trides = DESEncrypt(key,src); + String base64 = Base64.encodeBase64String(trides); + return base64; + } + + public static String Base64DESDecrypt2String(String key,String base64){ + byte[] trides = Base64.decodeBase64(base64); + return DESDecrypt(key,trides); + } + + public static String Base64DESDecrypt2ByteString(String key,String base64) throws Exception{ + byte[] trides = Base64.decodeBase64(base64); + return DESDecrypt(key,trides); + } +} diff --git a/src/main/resources/4343266_corejoyo.com.pfx b/src/main/resources/4343266_corejoyo.com.pfx new file mode 100644 index 0000000..1444eaa Binary files /dev/null and b/src/main/resources/4343266_corejoyo.com.pfx differ diff --git a/src/main/resources/4512967_tjcups.unicomiot.net.pfx b/src/main/resources/4512967_tjcups.unicomiot.net.pfx new file mode 100644 index 0000000..1f3b051 Binary files /dev/null and b/src/main/resources/4512967_tjcups.unicomiot.net.pfx differ diff --git a/src/main/resources/5614888_jyzngc.cn.pfx b/src/main/resources/5614888_jyzngc.cn.pfx new file mode 100644 index 0000000..968cbdf Binary files /dev/null and b/src/main/resources/5614888_jyzngc.cn.pfx differ diff --git a/src/main/resources/6131666_www.jyshir.cn.pfx b/src/main/resources/6131666_www.jyshir.cn.pfx new file mode 100644 index 0000000..bbea1f8 Binary files /dev/null and b/src/main/resources/6131666_www.jyshir.cn.pfx differ diff --git a/src/main/resources/7752598_www.jyzngc.cn.pfx b/src/main/resources/7752598_www.jyzngc.cn.pfx new file mode 100644 index 0000000..ea1cfc4 Binary files /dev/null and b/src/main/resources/7752598_www.jyzngc.cn.pfx differ diff --git a/src/main/resources/8176203_www.jyshum.cn.pfx b/src/main/resources/8176203_www.jyshum.cn.pfx new file mode 100644 index 0000000..cb95eb8 Binary files /dev/null and b/src/main/resources/8176203_www.jyshum.cn.pfx differ diff --git a/src/main/resources/8608603_www.jy-sh.com.pfx b/src/main/resources/8608603_www.jy-sh.com.pfx new file mode 100644 index 0000000..cb5408f Binary files /dev/null and b/src/main/resources/8608603_www.jy-sh.com.pfx differ diff --git a/src/main/resources/9242211_www.lonsungsh.com.pfx b/src/main/resources/9242211_www.lonsungsh.com.pfx new file mode 100644 index 0000000..7c55f7c Binary files /dev/null and b/src/main/resources/9242211_www.lonsungsh.com.pfx differ diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1eb2287 --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Main-Class: com.jingyi.iotserver.firestationport.FirestationportApplicat + ion + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..2092a16 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,118 @@ +server.port=8083 +server.ssl.protocol=TLS + +#237 +#server.ssl.key-store=classpath:www.genetek.cc.pfx +#server.ssl.key-store-password=d2sigv2y + +#47.103.40.68 +#139.224.47.222 +#server.ssl.key-store=classpath:7752598_www.jyzngc.cn.pfx +#server.ssl.key-store-password=F5l9bqDg + +#58.34.119.162 +#58.34.119.165 +server.ssl.key-store=classpath:lonsungsh.com.pfx +server.ssl.key-store-password=we65ha27 + +#118.190.158.181 +#emc-station.com.pfx +#server.ssl.key-store=classpath:www.emc-station.com.pfx +#server.ssl.key-store-password=1tte3v4e + +#À¼ÖݵçÐÅ +#125.74.48.82 +#server.ssl.key-store=classpath:4343266_corejoyo.com.pfx +#server.ssl.key-store-password=a4cTzc8A + +#Ìì½òÁªÍ¨ +#211.94.218.94 +#server.ssl.key-store=classpath:4512967_tjcups.unicomiot.net.pfx +#server.ssl.key-store-password=d8xLV9aS + +#114.117.201.62 +#server.ssl.key-store=classpath:weairhealth.net.pfx +#server.ssl.key-store-password=8qfq4tc0c69 +#server.ssl.key-store-type=JKS +#server.ssl.enabled=true + +#180.167.126.216 +#server.ssl.key-store=classpath:6131666_www.jyshir.cn.pfx +#server.ssl.key-store-password=urTRfF7c + +#jyshum.cn +#server.ssl.key-store=classpath:8176203_www.jyshum.cn.pfx +#server.ssl.key-store-password=TGfkG684 + +#www.jy-sh.com +#218.78.59.44 +#server.ssl.key-store=classpath:8608603_www.jy-sh.com.pfx +#server.ssl.key-store-password=Nd4oss4V + +#common ssl +#server.ssl.key-store=classpath:8176177_www.genetek.cc.pfx +#server.ssl.key-store-password=4c3y7J7p + +jy.server.config.dataport=true + +#sqlserver +#spring.datasource.url=jdbc:sqlserver://localhost:1433;database=firectrl_station;characterEncoding=UTF-8 +#spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver +#spring.datasource.sqltype=sqlserver +#spring.datasource.username=sa +#spring.datasource.password=?> + + + + \ No newline at end of file diff --git a/src/main/resources/config/logback.xml b/src/main/resources/config/logback.xml new file mode 100644 index 0000000..5091867 --- /dev/null +++ b/src/main/resources/config/logback.xml @@ -0,0 +1,37 @@ + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + ${server.log.location}/log_jyiot.log + + ${server.log.location}/%d{yyyy-MM-dd}_jyiot.log.zip + ${maxHistory} + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/lonsungsh.com.pfx b/src/main/resources/lonsungsh.com.pfx new file mode 100644 index 0000000..49961ec Binary files /dev/null and b/src/main/resources/lonsungsh.com.pfx differ diff --git a/src/main/resources/static/dbinfodefine.xml b/src/main/resources/static/dbinfodefine.xml new file mode 100644 index 0000000..98eeee3 --- /dev/null +++ b/src/main/resources/static/dbinfodefine.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/static/defaultroledefine.xml b/src/main/resources/static/defaultroledefine.xml new file mode 100644 index 0000000..59413ec --- /dev/null +++ b/src/main/resources/static/defaultroledefine.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/static/equipmenttabdefine.xml b/src/main/resources/static/equipmenttabdefine.xml new file mode 100644 index 0000000..b5739e1 --- /dev/null +++ b/src/main/resources/static/equipmenttabdefine.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/static/resinfodefine.xml b/src/main/resources/static/resinfodefine.xml new file mode 100644 index 0000000..70b1215 --- /dev/null +++ b/src/main/resources/static/resinfodefine.xml @@ -0,0 +1,294 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/static/sensortypeconfig.xml b/src/main/resources/static/sensortypeconfig.xml new file mode 100644 index 0000000..24c0e71 --- /dev/null +++ b/src/main/resources/static/sensortypeconfig.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/static/stationexternaldefine.xml b/src/main/resources/static/stationexternaldefine.xml new file mode 100644 index 0000000..3e5ecaf --- /dev/null +++ b/src/main/resources/static/stationexternaldefine.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/main/resources/weairhealth.net.jks b/src/main/resources/weairhealth.net.jks new file mode 100644 index 0000000..c389391 Binary files /dev/null and b/src/main/resources/weairhealth.net.jks differ diff --git a/src/main/resources/weairhealth.net.pfx b/src/main/resources/weairhealth.net.pfx new file mode 100644 index 0000000..5cbe30a Binary files /dev/null and b/src/main/resources/weairhealth.net.pfx differ diff --git a/src/main/resources/www.emc-station.com.pfx b/src/main/resources/www.emc-station.com.pfx new file mode 100644 index 0000000..97acb6c Binary files /dev/null and b/src/main/resources/www.emc-station.com.pfx differ diff --git a/src/main/resources/www.genetek.cc.pfx b/src/main/resources/www.genetek.cc.pfx new file mode 100644 index 0000000..7e970e7 Binary files /dev/null and b/src/main/resources/www.genetek.cc.pfx differ diff --git a/src/main/resources/www.lonsungsh.com.pfx b/src/main/resources/www.lonsungsh.com.pfx new file mode 100644 index 0000000..f50cb07 Binary files /dev/null and b/src/main/resources/www.lonsungsh.com.pfx differ