├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── pds │ │ └── access │ │ ├── AccessApplication.java │ │ ├── controller │ │ └── AccessManagementCtrl.java │ │ ├── domain │ │ ├── base │ │ │ ├── CommonRequest.java │ │ │ └── CommonResponse.java │ │ ├── request │ │ │ ├── AccessReq.java │ │ │ ├── SearchReq.java │ │ │ └── UserReq.java │ │ └── response │ │ │ ├── AccessRes.java │ │ │ └── UserRes.java │ │ ├── entity │ │ ├── PdsAccessManagementEntity.java │ │ └── PdsUserManagementEntity.java │ │ ├── mapper │ │ ├── PdsAccessManagementMapper.java │ │ └── PdsUserManagementMapper.java │ │ └── service │ │ ├── AccessManagementService.java │ │ └── impl │ │ └── AccessManagementServiceImpl.java └── resources │ ├── application.properties │ ├── logback.xml │ ├── mapper │ ├── PdsUserManagementMapper.xml │ ├── extend │ │ ├── PdsAccessManagementExtendMapper.xml │ │ └── PdsUserManagementExtendMapper.xml │ └── pdsAccessManagementMapper.xml │ └── mybatis-config.xml └── test └── java └── com └── pds └── access └── AccessApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | import java.nio.channels.*; 20 | import java.util.Properties; 21 | 22 | public class MavenWrapperDownloader { 23 | 24 | private static final String WRAPPER_VERSION = "0.5.6"; 25 | /** 26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 33 | * use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 36 | ".mvn/wrapper/maven-wrapper.properties"; 37 | 38 | /** 39 | * Path where the maven-wrapper.jar will be saved to. 40 | */ 41 | private static final String MAVEN_WRAPPER_JAR_PATH = 42 | ".mvn/wrapper/maven-wrapper.jar"; 43 | 44 | /** 45 | * Name of the property which should be used to override the default download url for the wrapper. 46 | */ 47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 48 | 49 | public static void main(String args[]) { 50 | System.out.println("- Downloader started"); 51 | File baseDirectory = new File(args[0]); 52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 53 | 54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacRylynn/accessControl/a93da6c474a9c6c3588b870906e0364050b6c063/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # accessControl 2 | 疫情期间,小区进出管理系统,实例系统中没有区分小区,欢迎拉分支自行改造!!! 3 | 4 | # 后端管理系统 5 | ## 1. 基于SpringBoot+MyBatis搭建 6 | SpringBoot:可以理解为一个整合了所有框架的框架,使用这个框架可以很方便的调用其他的框架,不需要考虑很多兼容性问题。简单来说,就是让开发人员的重点放在开发本身上。 7 | 8 | MyBatis:是一个对象映射框架(ORM),简单来说就是把数据库中一条一条的数据,映射成代码中的对象,因为Java是面向对象的开发语言。 9 | 10 | ## 2. 开发流程 11 | 12 | ### 2.1 根据业务流程设计数据库 13 | 以本系统为例,小区进出管理系统设计了两个数据模型,第一个是住户模型,其DDL如下: 14 | ``` 15 | CREATE TABLE `pds_user_management` ( 16 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', 17 | `user_code` varchar(200) COLLATE utf8_bin NOT NULL COMMENT '用户号(门牌号)', 18 | `registered_time` datetime DEFAULT NULL COMMENT '注册时间', 19 | `times_in` int(64) DEFAULT NULL COMMENT '进小区次数', 20 | `times_out` int(64) DEFAULT NULL COMMENT '出小区次数', 21 | `user_type` int(1) DEFAULT NULL COMMENT '用户类型 (0 表示正常 1表示禁止)', 22 | PRIMARY KEY (`id`) USING BTREE, 23 | UNIQUE KEY `user_code` (`user_code`) 24 | ) ENGINE=InnoDB AUTO_INCREMENT=89 DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC COMMENT='住户模型'; 25 | ``` 26 | 住户模型主要用来保存住户的基本信息、统计住户进出总次数。 27 | 第二个是进出详情模型,其DDL如下: 28 | ``` 29 | CREATE TABLE `pds_access_management` ( 30 | `id` int(32) NOT NULL AUTO_INCREMENT COMMENT '主键', 31 | `user_code` varchar(200) COLLATE utf8_bin NOT NULL COMMENT '用户号(门牌号)', 32 | `access_type` varchar(8) COLLATE utf8_bin DEFAULT NULL COMMENT '进出类型', 33 | `access_time` datetime DEFAULT NULL COMMENT '进出时间', 34 | PRIMARY KEY (`id`) USING BTREE 35 | ) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC COMMENT='进出详情模型'; 36 | ``` 37 | 进出详情模型主要用来保存住户的进出详情。住户模型使用user_code字段与进出详情模型关联,这两个模型之间是一对多的关系。 38 | 39 | ### 2.2 根据数据库使用MyBatis框架映射 40 | 使用 https://github.com/MacRylynn/mybatisGenerator 工程可以将数据直接从数据库映射成对象,并且生成一些CURD方法,供服务调用。其参数和使用方法在工程中有说明。 41 | 42 | ### 2.3 工程中的包和类的说明 43 | 44 | #### 2.3.1 pom.xml 45 | 这个文件是系统中用到的所有Maven依赖,需要用到什么工具,就将这个工具的依赖导入进来。 46 | 举例:以C++为例,假如代码中要用到OpenCV,首先需要去下载OpenCV,然后安装、添加环境变量、在VS中配置、在工程中#include......非常麻烦, 在Spring项目中只需要在pom.xml中添加如下类似依赖(示例依赖并不是OpenCV): 47 | ``` 48 | 49 | mysql 50 | mysql-connector-java 51 | runtime 52 | 53 | ``` 54 | 系统会自动从网络Maven库中加载该依赖包,就可以使用mysql于Java之间的连接方法了。 55 | 56 | #### 2.3.2 application.properties 57 | 是系统的总配置,包括数据库地址、网络端口号等等,很多参数可以自行百度。 58 | 59 | #### 2.3.3 logback.xml 60 | 系统日志的配置,使用日志可以观察系统的运行状态,很多参数可以自行百度。 61 | 62 | #### 2.3.4 mybatis-config.xml 63 | MyBatis从数据库映射到对象的配置,很多参数可以自行百度,在pom.xml文件中引用。 64 | 65 | #### 2.3.5 entity包 66 | 包中的所有类,都是使用2.2中的工程生成的,是数据库对应生成的Java类 67 | 68 | #### 2.3.5 mapper包 69 | 两个mapper包都是使用2.2中的工程生成的(带有注释的是手动写的,主要适应不同的业务需求)。main中的mapper包中的类,是操作数据库的方法申明,resource中的mapper包是main中mapper包中方法的实现。 70 | resource中的mapper包下的extend包是手动写的sql(带有注释的那些方法的实现) 71 | 72 | #### 2.3.6 service包 73 | 包中是主要的业务方法的申明和实现。接口中是业务流程会用到的所有方法的申明。service包中的impl包是接口的实现,主要体现Java面向接口编程,不对外暴露任何业务细节的思想。 74 | 75 | #### 2.3.7 domain包 76 | 包中的类是与Web直接交互的类,包括请求类、响应类等,是对数据进行了包装,称之为数据传输层。因为在实际项目中,考虑到安全性,往往不会将数据库映射出来的entity直接与Web进行交互。 77 | 78 | #### 2.3.8 controller包 79 | 可以理解为连接前端和后端的方式。类的最上方的注解@RequestMapping("/web/wx")表示根路径,使用一下方法得到所有住户的信息。 80 | ``` 81 | @PostMapping("/getallrecords") 82 | public CommonResponse> getAllRecords() { 83 | logger.info("AccessManagementCtrl|getAllRecords,查询所有用户进出信息"); 84 | CommonResponse> res = new CommonResponse<>(); 85 | List result = accessManagementService.getAllRecords(); 86 | res.setResultData(result); 87 | return res; 88 | } 89 | ``` 90 | @PostMapping("/getallrecords")表示使用post方法,并且在根路径中加分路径,即前端使用电脑ip和application.properties的端口号+根路径+分路径就能访问这个方法,比如:http//:127.0.0.1:8088/web/wx/getallrecords。具体使用的时候均使用post方法,保证一定的安全性。 91 | 整个实现方法中入参为空,返回有所的住户信息。 92 | 93 | #### 2.3.9 AccessAplication类 94 | 是整个项目的启动类,如果需要打包并且在tomcat运行,则需要继承SpringBootServletInitializer类,详情可以自行百度。 95 | 96 | ## 3. 使用流程 97 | 编码:设计数据库-> 数据库映射为对象-> 业务中操作对象-> 与前端交互 98 | 访问:前端请求-> controller层-> 调用service中的方法-> 调用mapper中的方法-> 实现数据库的增删改查 99 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.4.RELEASE 9 | 10 | 11 | com.pds 12 | access 13 | 0.0.1-SNAPSHOT 14 | war 15 | access 16 | Demo project for Spring Boot 17 | 18 | 19 | 1.8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.mybatis.spring.boot 29 | mybatis-spring-boot-starter 30 | 2.1.1 31 | 32 | 33 | mysql 34 | mysql-connector-java 35 | runtime 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-tomcat 40 | provided 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | org.junit.vintage 49 | junit-vintage-engine 50 | 51 | 52 | 53 | 54 | 55 | 56 | com.fasterxml.jackson.core 57 | jackson-annotations 58 | 2.9.5 59 | 60 | 61 | 62 | com.fasterxml.jackson.core 63 | jackson-databind 64 | 2.9.5 65 | 66 | 67 | 68 | org.codehaus.jackson 69 | jackson-mapper-asl 70 | 1.9.13 71 | 72 | 73 | 74 | 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-maven-plugin 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/AccessApplication.java: -------------------------------------------------------------------------------- 1 | package com.pds.access; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 6 | 7 | @SpringBootApplication 8 | public class AccessApplication extends SpringBootServletInitializer { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(AccessApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/controller/AccessManagementCtrl.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.controller; 2 | 3 | import com.pds.access.domain.base.CommonRequest; 4 | import com.pds.access.domain.base.CommonResponse; 5 | import com.pds.access.domain.request.AccessReq; 6 | import com.pds.access.domain.request.SearchReq; 7 | import com.pds.access.domain.request.UserReq; 8 | import com.pds.access.domain.response.AccessRes; 9 | import com.pds.access.domain.response.UserRes; 10 | import com.pds.access.service.AccessManagementService; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import javax.annotation.Resource; 16 | import java.util.List; 17 | 18 | /** 19 | * @Author: lijiao 20 | * @Date: Create in 13:57 2020/2/9 21 | * @version: 1.0 22 | */ 23 | @RestController 24 | @RequestMapping("/web/wx") 25 | public class AccessManagementCtrl { 26 | private static final Logger logger = LoggerFactory.getLogger(AccessManagementCtrl.class); 27 | 28 | @Resource 29 | private AccessManagementService accessManagementService; 30 | 31 | @GetMapping("/index") 32 | public String testSystem() { 33 | return "系统正常"; 34 | } 35 | 36 | @PostMapping("/adduser") 37 | public CommonResponse insertUser(@RequestBody CommonRequest commonRequest) { 38 | logger.info("AccessManagementCtrl|insertUser,增加用户信息,入参为:{}", commonRequest.toString()); 39 | CommonResponse res = new CommonResponse<>(); 40 | UserReq req = commonRequest.getRequestData(); 41 | if (req == null) { 42 | logger.info("AccessManagementCtrl|insertUser,请求参数为空"); 43 | return null; 44 | } 45 | String result = accessManagementService.insertUser(req); 46 | res.setResultData(result); 47 | return res; 48 | } 49 | 50 | @PostMapping("/inorout") 51 | public CommonResponse inOrOut(@RequestBody CommonRequest commonRequest) { 52 | logger.info("AccessManagementCtrl|inOrOut,增加用户进出信息,入参为:{}", commonRequest.toString()); 53 | CommonResponse res = new CommonResponse<>(); 54 | AccessReq req = commonRequest.getRequestData(); 55 | if (req == null) { 56 | logger.info("AccessManagementCtrl|inOrOut,请求参数为空"); 57 | return null; 58 | } 59 | Boolean result = accessManagementService.inOrOut(req); 60 | if (!result){ 61 | res.setResultMsg("该用户已被禁止出入,或者进出类型输入错误"); 62 | } 63 | res.setResultData(result); 64 | return res; 65 | } 66 | 67 | @PostMapping("/getallrecords") 68 | public CommonResponse> getAllRecords() { 69 | logger.info("AccessManagementCtrl|getAllRecords,查询所有用户进出信息"); 70 | CommonResponse> res = new CommonResponse<>(); 71 | List result = accessManagementService.getAllRecords(); 72 | res.setResultData(result); 73 | return res; 74 | } 75 | 76 | @PostMapping("/getonerecords") 77 | public CommonResponse> getRecordByCode(@RequestBody CommonRequest commonRequest) { 78 | logger.info("AccessManagementCtrl|getRecordByCode,查询单家用户的进出记录,入参为:{}", commonRequest.toString()); 79 | CommonResponse> res = new CommonResponse<>(); 80 | UserReq req = commonRequest.getRequestData(); 81 | if (req == null) { 82 | logger.info("AccessManagementCtrl|getRecordByCode,请求参数为空"); 83 | return null; 84 | } 85 | List result = accessManagementService.getRecordByCode(req.getUserCode()); 86 | res.setResultData(result); 87 | return res; 88 | } 89 | 90 | 91 | @PostMapping("/delete") 92 | public CommonResponse deleteAccessRecords(@RequestBody CommonRequest commonRequest) { 93 | logger.info("AccessManagementCtrl|deleteAccessRecords,删除住户,入参为:{}", commonRequest.toString()); 94 | CommonResponse res = new CommonResponse<>(); 95 | UserReq req = commonRequest.getRequestData(); 96 | if (req == null) { 97 | logger.info("AccessManagementCtrl|deleteAccessRecords,请求参数为空"); 98 | return null; 99 | } 100 | Boolean result = accessManagementService.deleteAccessRecords(req.getUserCode()); 101 | res.setResultData(result); 102 | return res; 103 | } 104 | 105 | @PostMapping("/search") 106 | public CommonResponse> selectBySearch(@RequestBody CommonRequest commonRequest) { 107 | logger.info("AccessManagementCtrl|selectBySearch,按照条件查询住户,入参为:{}", commonRequest.toString()); 108 | CommonResponse> res = new CommonResponse<>(); 109 | SearchReq req = commonRequest.getRequestData(); 110 | if (req == null) { 111 | logger.info("AccessManagementCtrl|selectBySearch,请求参数为空"); 112 | return null; 113 | } 114 | List result = accessManagementService.selectBySearch(req); 115 | res.setResultData(result); 116 | return res; 117 | } 118 | 119 | @PostMapping("/change") 120 | public CommonResponse changeUserType(@RequestBody CommonRequest commonRequest) { 121 | logger.info("AccessManagementCtrl|changeUserType,修改住户状态,入参为:{}", commonRequest.toString()); 122 | CommonResponse res = new CommonResponse<>(); 123 | UserReq req = commonRequest.getRequestData(); 124 | if (req == null) { 125 | logger.info("AccessManagementCtrl|changeUserType,请求参数为空"); 126 | return null; 127 | } 128 | Boolean result = accessManagementService.changeUserType(req.getUserCode()); 129 | res.setResultData(result); 130 | return res; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/base/CommonRequest.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.base; 2 | 3 | /** 4 | * @ClassName CommonRequest 5 | * @Description 公共请求参数 6 | * @Author: lijiao73 7 | * @Date: 2019/11/14 9:10 8 | */ 9 | public class CommonRequest { 10 | private T requestData; 11 | 12 | public T getRequestData() { 13 | return requestData; 14 | } 15 | 16 | public void setRequestData(T requestData) { 17 | this.requestData = requestData; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "CommonRequest{" + 23 | "requestData=" + requestData + 24 | '}'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/base/CommonResponse.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.base; 2 | 3 | /** 4 | * @ClassName CommonResponse 5 | * @Description 公共返回参数 6 | * @Author: lijiao73 7 | * @Date: 2019/11/14 9:10 8 | */ 9 | public class CommonResponse { 10 | private static final String SUCCESS = "0000"; 11 | 12 | private static final String FAILED = "0001"; 13 | 14 | /** 15 | * 返回码 16 | */ 17 | private String resultCode = "0000"; 18 | 19 | /** 20 | * 返回信息 21 | */ 22 | private String resultMsg = "请求成功"; 23 | 24 | /** 25 | * 返回数据 26 | */ 27 | private T resultData; 28 | 29 | public CommonResponse() { 30 | } 31 | 32 | public CommonResponse(String resultCode, String resultMsg) { 33 | this.resultCode = resultCode; 34 | this.resultMsg = resultMsg; 35 | } 36 | 37 | public CommonResponse(String code, T data) { 38 | this.resultCode = code; 39 | this.resultData = data; 40 | } 41 | 42 | public static CommonResponse success() { 43 | return success(null); 44 | } 45 | 46 | public static CommonResponse success(T data) { 47 | return new CommonResponse<>(CommonResponse.SUCCESS, data); 48 | } 49 | 50 | public static CommonResponse failed(String msg) { 51 | return new CommonResponse<>(CommonResponse.FAILED, msg); 52 | } 53 | 54 | 55 | public static CommonResponse fail(String code, String msg) { 56 | return new CommonResponse<>(code, msg); 57 | } 58 | 59 | public String getResultCode() { 60 | return resultCode; 61 | } 62 | 63 | public void setResultCode(String resultCode) { 64 | this.resultCode = resultCode; 65 | } 66 | 67 | public String getResultMsg() { 68 | return resultMsg; 69 | } 70 | 71 | public void setResultMsg(String resultMsg) { 72 | this.resultMsg = resultMsg; 73 | } 74 | 75 | public T getResultData() { 76 | return resultData; 77 | } 78 | 79 | public void setResultData(T resultData) { 80 | this.resultData = resultData; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/request/AccessReq.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.request; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * @Author: lijiao 8 | * @Date: Create in 14:09 2020/2/9 9 | * @version: 1.0 10 | */ 11 | public class AccessReq implements Serializable { 12 | /** 13 | * 主键 14 | */ 15 | private Integer id; 16 | 17 | /** 18 | * 用户号(门牌号+当前毫秒数) 19 | */ 20 | private String userCode; 21 | 22 | /** 23 | * 进出类型 24 | */ 25 | private String accessType; 26 | 27 | /** 28 | * 进出时间 29 | */ 30 | private Date accessTime; 31 | 32 | public Integer getId() { 33 | return id; 34 | } 35 | 36 | public void setId(Integer id) { 37 | this.id = id; 38 | } 39 | 40 | public String getUserCode() { 41 | return userCode; 42 | } 43 | 44 | public void setUserCode(String userCode) { 45 | this.userCode = userCode == null ? null : userCode.trim(); 46 | } 47 | 48 | public String getAccessType() { 49 | return accessType; 50 | } 51 | 52 | public void setAccessType(String accessType) { 53 | this.accessType = accessType == null ? null : accessType.trim(); 54 | } 55 | 56 | public Date getAccessTime() { 57 | return accessTime; 58 | } 59 | 60 | public void setAccessTime(Date accessTime) { 61 | this.accessTime = accessTime; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | StringBuilder sb = new StringBuilder(); 67 | sb.append(getClass().getSimpleName()); 68 | sb.append(" ["); 69 | sb.append("Hash = ").append(hashCode()); 70 | sb.append(", id=").append(id); 71 | sb.append(", userCode=").append(userCode); 72 | sb.append(", accessType=").append(accessType); 73 | sb.append(", accessTime=").append(accessTime); 74 | sb.append("]"); 75 | return sb.toString(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/request/SearchReq.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.request; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @Author: lijiao 7 | * @Date: Create in 10:52 2020/2/14 8 | * @version: 1.0 9 | */ 10 | public class SearchReq implements Serializable { 11 | //搜索的最小值 12 | private int min; 13 | 14 | //搜索的最大值 15 | private int max; 16 | 17 | public int getMin() { 18 | return min; 19 | } 20 | 21 | public void setMin(int min) { 22 | this.min = min; 23 | } 24 | 25 | public int getMax() { 26 | return max; 27 | } 28 | 29 | public void setMax(int max) { 30 | this.max = max; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "SearchReq{" + 36 | "min=" + min + 37 | ", max=" + max + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/request/UserReq.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.request; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * @Author: lijiao 8 | * @Date: Create in 14:09 2020/2/9 9 | * @version: 1.0 10 | */ 11 | public class UserReq implements Serializable { 12 | /** 13 | * 主键 14 | */ 15 | private Integer id; 16 | 17 | /** 18 | * 用户号(门牌号+当前毫秒数) 19 | */ 20 | private String userCode; 21 | 22 | /** 23 | * 注册时间 24 | */ 25 | private Date registeredTime; 26 | 27 | /** 28 | * 进小区次数 29 | */ 30 | private Integer timesIn; 31 | 32 | /** 33 | * 出小区次数 34 | */ 35 | private Integer timesOut; 36 | 37 | public Integer getUserType() { 38 | return userType; 39 | } 40 | 41 | public void setUserType(Integer userType) { 42 | this.userType = userType; 43 | } 44 | 45 | /** 46 | * 用户类型 (0 表示正常 1表示禁止) 47 | */ 48 | private Integer userType; 49 | 50 | public Integer getId() { 51 | return id; 52 | } 53 | 54 | public void setId(Integer id) { 55 | this.id = id; 56 | } 57 | 58 | public String getUserCode() { 59 | return userCode; 60 | } 61 | 62 | public void setUserCode(String userCode) { 63 | this.userCode = userCode == null ? null : userCode.trim(); 64 | } 65 | 66 | public Date getRegisteredTime() { 67 | return registeredTime; 68 | } 69 | 70 | public void setRegisteredTime(Date registeredTime) { 71 | this.registeredTime = registeredTime; 72 | } 73 | 74 | public Integer getTimesIn() { 75 | return timesIn; 76 | } 77 | 78 | public void setTimesIn(Integer timesIn) { 79 | this.timesIn = timesIn; 80 | } 81 | 82 | public Integer getTimesOut() { 83 | return timesOut; 84 | } 85 | 86 | public void setTimesOut(Integer timesOut) { 87 | this.timesOut = timesOut; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return "UserReq{" + 93 | "id=" + id + 94 | ", userCode='" + userCode + '\'' + 95 | ", registeredTime=" + registeredTime + 96 | ", timesIn=" + timesIn + 97 | ", timesOut=" + timesOut + 98 | ", userType=" + userType + 99 | '}'; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/response/AccessRes.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.response; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | 9 | /** 10 | * @Author: lijiao 11 | * @Date: Create in 14:09 2020/2/9 12 | * @version: 1.0 13 | */ 14 | public class AccessRes implements Serializable { 15 | /** 16 | * 主键 17 | */ 18 | private Integer id; 19 | 20 | /** 21 | * 用户号(门牌号+当前毫秒数) 22 | */ 23 | private String userCode; 24 | 25 | /** 26 | * 进出类型 27 | */ 28 | private String accessType; 29 | 30 | /** 31 | * 进出时间 32 | */ 33 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 34 | private Date accessTime; 35 | 36 | public Integer getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Integer id) { 41 | this.id = id; 42 | } 43 | 44 | public String getUserCode() { 45 | return userCode; 46 | } 47 | 48 | public void setUserCode(String userCode) { 49 | this.userCode = userCode == null ? null : userCode.trim(); 50 | } 51 | 52 | public String getAccessType() { 53 | return accessType; 54 | } 55 | 56 | public void setAccessType(String accessType) { 57 | this.accessType = accessType == null ? null : accessType.trim(); 58 | } 59 | 60 | public Date getAccessTime() { 61 | return accessTime; 62 | } 63 | 64 | public void setAccessTime(Date accessTime) { 65 | this.accessTime = accessTime; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | StringBuilder sb = new StringBuilder(); 71 | sb.append(getClass().getSimpleName()); 72 | sb.append(" ["); 73 | sb.append("Hash = ").append(hashCode()); 74 | sb.append(", id=").append(id); 75 | sb.append(", userCode=").append(userCode); 76 | sb.append(", accessType=").append(accessType); 77 | sb.append(", accessTime=").append(accessTime); 78 | sb.append("]"); 79 | return sb.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/domain/response/UserRes.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.domain.response; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | 9 | /** 10 | * @Author: lijiao 11 | * @Date: Create in 14:09 2020/2/9 12 | * @version: 1.0 13 | */ 14 | public class UserRes implements Serializable { 15 | /** 16 | * 主键 17 | */ 18 | private Integer id; 19 | 20 | /** 21 | * 用户号(门牌号+当前毫秒数) 22 | */ 23 | private String userCode; 24 | 25 | /** 26 | * 注册时间 27 | */ 28 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 29 | private Date registeredTime; 30 | 31 | /** 32 | * 进小区次数 33 | */ 34 | private Integer timesIn; 35 | 36 | /** 37 | * 出小区次数 38 | */ 39 | private Integer timesOut; 40 | 41 | 42 | /** 43 | * 用户类型 (0 表示正常 1表示禁止) 44 | */ 45 | private Integer userType; 46 | 47 | public Integer getUserType() { 48 | return userType; 49 | } 50 | 51 | public void setUserType(Integer userType) { 52 | this.userType = userType; 53 | } 54 | 55 | public Integer getId() { 56 | return id; 57 | } 58 | 59 | public void setId(Integer id) { 60 | this.id = id; 61 | } 62 | 63 | public String getUserCode() { 64 | return userCode; 65 | } 66 | 67 | public void setUserCode(String userCode) { 68 | this.userCode = userCode == null ? null : userCode.trim(); 69 | } 70 | 71 | public Date getRegisteredTime() { 72 | return registeredTime; 73 | } 74 | 75 | public void setRegisteredTime(Date registeredTime) { 76 | this.registeredTime = registeredTime; 77 | } 78 | 79 | public Integer getTimesIn() { 80 | return timesIn; 81 | } 82 | 83 | public void setTimesIn(Integer timesIn) { 84 | this.timesIn = timesIn; 85 | } 86 | 87 | public Integer getTimesOut() { 88 | return timesOut; 89 | } 90 | 91 | public void setTimesOut(Integer timesOut) { 92 | this.timesOut = timesOut; 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return "UserRes{" + 98 | "id=" + id + 99 | ", userCode='" + userCode + '\'' + 100 | ", registeredTime=" + registeredTime + 101 | ", timesIn=" + timesIn + 102 | ", timesOut=" + timesOut + 103 | ", userType=" + userType + 104 | '}'; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/entity/PdsAccessManagementEntity.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.entity; 2 | 3 | import java.util.Date; 4 | 5 | public class PdsAccessManagementEntity { 6 | /** 7 | * 主键 8 | */ 9 | private Integer id; 10 | 11 | /** 12 | * 用户号(门牌号+当前毫秒数) 13 | */ 14 | private String userCode; 15 | 16 | /** 17 | * 进出类型 18 | */ 19 | private String accessType; 20 | 21 | /** 22 | * 进出时间 23 | */ 24 | private Date accessTime; 25 | 26 | public Integer getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Integer id) { 31 | this.id = id; 32 | } 33 | 34 | public String getUserCode() { 35 | return userCode; 36 | } 37 | 38 | public void setUserCode(String userCode) { 39 | this.userCode = userCode == null ? null : userCode.trim(); 40 | } 41 | 42 | public String getAccessType() { 43 | return accessType; 44 | } 45 | 46 | public void setAccessType(String accessType) { 47 | this.accessType = accessType == null ? null : accessType.trim(); 48 | } 49 | 50 | public Date getAccessTime() { 51 | return accessTime; 52 | } 53 | 54 | public void setAccessTime(Date accessTime) { 55 | this.accessTime = accessTime; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | StringBuilder sb = new StringBuilder(); 61 | sb.append(getClass().getSimpleName()); 62 | sb.append(" ["); 63 | sb.append("Hash = ").append(hashCode()); 64 | sb.append(", id=").append(id); 65 | sb.append(", userCode=").append(userCode); 66 | sb.append(", accessType=").append(accessType); 67 | sb.append(", accessTime=").append(accessTime); 68 | sb.append("]"); 69 | return sb.toString(); 70 | } 71 | } -------------------------------------------------------------------------------- /src/main/java/com/pds/access/entity/PdsUserManagementEntity.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.entity; 2 | 3 | import java.util.Date; 4 | 5 | public class PdsUserManagementEntity { 6 | /** 7 | * 主键 8 | */ 9 | private Integer id; 10 | 11 | /** 12 | * 用户号(门牌号+当前毫秒数) 13 | */ 14 | private String userCode; 15 | 16 | /** 17 | * 注册时间 18 | */ 19 | private Date registeredTime; 20 | 21 | /** 22 | * 进小区次数 23 | */ 24 | private Integer timesIn; 25 | 26 | /** 27 | * 出小区次数 28 | */ 29 | private Integer timesOut; 30 | 31 | /** 32 | * 用户类型 (0 表示正常 1表示禁止) 33 | */ 34 | private Integer userType; 35 | 36 | public Integer getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Integer id) { 41 | this.id = id; 42 | } 43 | 44 | public String getUserCode() { 45 | return userCode; 46 | } 47 | 48 | public void setUserCode(String userCode) { 49 | this.userCode = userCode == null ? null : userCode.trim(); 50 | } 51 | 52 | public Date getRegisteredTime() { 53 | return registeredTime; 54 | } 55 | 56 | public void setRegisteredTime(Date registeredTime) { 57 | this.registeredTime = registeredTime; 58 | } 59 | 60 | public Integer getTimesIn() { 61 | return timesIn; 62 | } 63 | 64 | public void setTimesIn(Integer timesIn) { 65 | this.timesIn = timesIn; 66 | } 67 | 68 | public Integer getTimesOut() { 69 | return timesOut; 70 | } 71 | 72 | public void setTimesOut(Integer timesOut) { 73 | this.timesOut = timesOut; 74 | } 75 | 76 | public Integer getUserType() { 77 | return userType; 78 | } 79 | 80 | public void setUserType(Integer userType) { 81 | this.userType = userType; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | StringBuilder sb = new StringBuilder(); 87 | sb.append(getClass().getSimpleName()); 88 | sb.append(" ["); 89 | sb.append("Hash = ").append(hashCode()); 90 | sb.append(", id=").append(id); 91 | sb.append(", userCode=").append(userCode); 92 | sb.append(", registeredTime=").append(registeredTime); 93 | sb.append(", timesIn=").append(timesIn); 94 | sb.append(", timesOut=").append(timesOut); 95 | sb.append(", userType=").append(userType); 96 | sb.append("]"); 97 | return sb.toString(); 98 | } 99 | } -------------------------------------------------------------------------------- /src/main/java/com/pds/access/mapper/PdsAccessManagementMapper.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.mapper; 2 | 3 | import com.pds.access.entity.PdsAccessManagementEntity; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface PdsAccessManagementMapper { 11 | int deleteByPrimaryKey(Integer id); 12 | 13 | int insert(PdsAccessManagementEntity record); 14 | 15 | int insertSelective(PdsAccessManagementEntity record); 16 | 17 | PdsAccessManagementEntity selectByPrimaryKey(Integer id); 18 | 19 | int updateByPrimaryKeySelective(PdsAccessManagementEntity record); 20 | 21 | int updateByPrimaryKey(PdsAccessManagementEntity record); 22 | 23 | /** 24 | * 根据用户号找寻数据库中的一系列数据 25 | * 26 | * @param userCode 27 | * @return 28 | */ 29 | List selectByCode(@Param("userCode") String userCode); 30 | 31 | 32 | /** 33 | * 根据住户号删除住户进出记录 34 | * @param userCode 35 | * @return 36 | */ 37 | int deleteByUserCode(@Param("userCode") String userCode); 38 | } -------------------------------------------------------------------------------- /src/main/java/com/pds/access/mapper/PdsUserManagementMapper.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.mapper; 2 | 3 | import com.pds.access.entity.PdsUserManagementEntity; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface PdsUserManagementMapper { 11 | int deleteByPrimaryKey(Integer id); 12 | 13 | int insert(PdsUserManagementEntity record); 14 | 15 | int insertSelective(PdsUserManagementEntity record); 16 | 17 | PdsUserManagementEntity selectByPrimaryKey(Integer id); 18 | 19 | int updateByPrimaryKeySelective(PdsUserManagementEntity record); 20 | 21 | int updateByPrimaryKey(PdsUserManagementEntity record); 22 | 23 | /** 24 | * 根据用户号找寻数据库中的相应一条数据 25 | * 26 | * @param userCode 27 | * @return 28 | */ 29 | PdsUserManagementEntity selectByCode(@Param("userCode") String userCode); 30 | 31 | /** 32 | * 查询所有住户进出信息 33 | * @return 34 | */ 35 | List selectAll(); 36 | 37 | /** 38 | * 根据住户号删除住户信息 39 | * @param userCode 40 | * @return 41 | */ 42 | int deleteByUserCode(@Param("userCode") String userCode); 43 | 44 | /** 45 | * 根据前端传入进来的数字查询满足条件的住户 46 | * @param min 47 | * @param max 48 | * @return 49 | */ 50 | List selectBySearch(@Param("min") Integer min,@Param("max") Integer max); 51 | } -------------------------------------------------------------------------------- /src/main/java/com/pds/access/service/AccessManagementService.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.service; 2 | 3 | import com.pds.access.domain.request.AccessReq; 4 | import com.pds.access.domain.request.SearchReq; 5 | import com.pds.access.domain.request.UserReq; 6 | import com.pds.access.domain.response.AccessRes; 7 | import com.pds.access.domain.response.UserRes; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @Author: lijiao 13 | * @Date: Create in 13:58 2020/2/9 14 | * @version: 1.0 15 | */ 16 | public interface AccessManagementService { 17 | 18 | /** 19 | * 添加用户,会返回一个userCode,存在二维码中 20 | * 21 | * @param req 22 | * @return 23 | */ 24 | String insertUser(UserReq req); 25 | 26 | /** 27 | * 添加进出记录 28 | * 29 | * @param req 30 | * @return 31 | */ 32 | Boolean inOrOut(AccessReq req); 33 | 34 | /** 35 | * 得到所有进出记录数据 36 | * 37 | * @return 38 | */ 39 | List getAllRecords(); 40 | 41 | /** 42 | * 根据用户号获取当前用户的进出记录 43 | * 44 | * @param userCode 45 | * @return 46 | */ 47 | List getRecordByCode(String userCode); 48 | 49 | /** 50 | * 删除此住户信息和此住户信息下的所有进出记录 51 | * @param userCode 52 | * @return 53 | */ 54 | Boolean deleteAccessRecords(String userCode); 55 | 56 | /** 57 | * 按照前端的进出条件搜索住户 58 | * @param req 59 | * @return 60 | */ 61 | List selectBySearch(SearchReq req); 62 | 63 | /** 64 | * 更改住户状态 65 | * @param userCode 66 | * @return 67 | */ 68 | Boolean changeUserType(String userCode); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/pds/access/service/impl/AccessManagementServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.pds.access.service.impl; 2 | 3 | 4 | import com.pds.access.domain.request.AccessReq; 5 | import com.pds.access.domain.request.SearchReq; 6 | import com.pds.access.domain.request.UserReq; 7 | import com.pds.access.domain.response.AccessRes; 8 | import com.pds.access.domain.response.UserRes; 9 | import com.pds.access.entity.PdsAccessManagementEntity; 10 | import com.pds.access.entity.PdsUserManagementEntity; 11 | import com.pds.access.mapper.PdsAccessManagementMapper; 12 | import com.pds.access.mapper.PdsUserManagementMapper; 13 | import com.pds.access.service.AccessManagementService; 14 | import org.springframework.beans.BeanUtils; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | 19 | import javax.annotation.Resource; 20 | import java.util.ArrayList; 21 | import java.util.Date; 22 | import java.util.List; 23 | 24 | /** 25 | * @Author: lijiao 26 | * @Date: Create in 13:58 2020/2/9 27 | * @version: 1.0 28 | */ 29 | @Service 30 | public class AccessManagementServiceImpl implements AccessManagementService { 31 | @Resource 32 | private PdsAccessManagementMapper pdsAccessManagementMapper; 33 | @Resource 34 | private PdsUserManagementMapper pdsUserManagementMapper; 35 | 36 | @Override 37 | @Transactional(rollbackFor = Exception.class) 38 | public String insertUser(UserReq req) { 39 | PdsUserManagementEntity pdsUserManagementEntity = new PdsUserManagementEntity(); 40 | pdsUserManagementEntity.setRegisteredTime(new Date()); 41 | //初始化进小区的次数为0 42 | pdsUserManagementEntity.setTimesIn(0); 43 | //初始化出小区的次数为0 44 | pdsUserManagementEntity.setTimesOut(0); 45 | //初始化用户号 46 | pdsUserManagementEntity.setUserCode(req.getUserCode()); 47 | //初始化用户状态 0 表示正常用户 48 | pdsUserManagementEntity.setUserType(0); 49 | //插入数据,成功则返回用户号 50 | int sign = 0; 51 | try { 52 | sign = pdsUserManagementMapper.insertSelective(pdsUserManagementEntity); 53 | } catch (Exception e) { 54 | System.out.println(e.toString()); 55 | } 56 | if (sign == 1) 57 | return req.getUserCode(); 58 | return "Duplicate registration"; 59 | } 60 | 61 | @Override 62 | @Transactional(rollbackFor = Exception.class) 63 | public Boolean inOrOut(AccessReq req) { 64 | String userCode = req.getUserCode(); 65 | // 1. 总表数据修改 66 | PdsUserManagementEntity pdsUserManagementEntity = pdsUserManagementMapper.selectByCode(userCode); 67 | // 2. 如果用户没有被禁止 68 | if (pdsUserManagementEntity.getUserType() == 0) { 69 | int mark = 0; 70 | if (req.getAccessType().equals("IN")) { 71 | int in = pdsUserManagementEntity.getTimesIn(); 72 | pdsUserManagementEntity.setTimesIn(in + 1); 73 | mark = pdsUserManagementMapper.updateByPrimaryKeySelective(pdsUserManagementEntity); 74 | } 75 | if (req.getAccessType().equals("OUT")) { 76 | int out = pdsUserManagementEntity.getTimesOut(); 77 | pdsUserManagementEntity.setTimesOut(out + 1); 78 | mark = pdsUserManagementMapper.updateByPrimaryKeySelective(pdsUserManagementEntity); 79 | } 80 | // 3. 明细表增加 81 | int sign = 0; 82 | if (mark == 1) { 83 | PdsAccessManagementEntity pdsAccessManagementEntity = new PdsAccessManagementEntity(); 84 | pdsAccessManagementEntity.setAccessTime(new Date()); 85 | pdsAccessManagementEntity.setAccessType(req.getAccessType()); 86 | pdsAccessManagementEntity.setUserCode(req.getUserCode()); 87 | sign = pdsAccessManagementMapper.insertSelective(pdsAccessManagementEntity); 88 | } 89 | return sign == 1; 90 | } else { 91 | return false; 92 | } 93 | } 94 | 95 | @Override 96 | public List getAllRecords() { 97 | List pdsUserList = pdsUserManagementMapper.selectAll(); 98 | List list = new ArrayList<>(); 99 | for (PdsUserManagementEntity pdsUserManagementEntity : pdsUserList) { 100 | UserRes userRes = new UserRes(); 101 | BeanUtils.copyProperties(pdsUserManagementEntity, userRes); 102 | list.add(userRes); 103 | } 104 | if (list.isEmpty()) 105 | return null; 106 | return list; 107 | } 108 | 109 | @Override 110 | public List getRecordByCode(String userCode) { 111 | List pdsAccessList = pdsAccessManagementMapper.selectByCode(userCode); 112 | List list = new ArrayList<>(); 113 | for (PdsAccessManagementEntity pdsAccessManagementEntity : pdsAccessList) { 114 | AccessRes accessRes = new AccessRes(); 115 | BeanUtils.copyProperties(pdsAccessManagementEntity, accessRes); 116 | list.add(accessRes); 117 | } 118 | if (list.isEmpty()) 119 | return null; 120 | return list; 121 | } 122 | 123 | @Override 124 | public Boolean deleteAccessRecords(String userCode) { 125 | // 1. 删除住户信息 126 | pdsUserManagementMapper.deleteByUserCode(userCode); 127 | // 2. 删除住户信息下的所有进出记录 128 | pdsAccessManagementMapper.deleteByUserCode(userCode); 129 | return true; 130 | } 131 | 132 | @Override 133 | public List selectBySearch(SearchReq req) { 134 | List list = new ArrayList<>(); 135 | Integer min = req.getMin(); 136 | Integer max = req.getMax(); 137 | if (min > max) { 138 | return list; 139 | } 140 | List resList = pdsUserManagementMapper.selectBySearch(min, max); 141 | resList.forEach(item -> { 142 | UserRes userRes = new UserRes(); 143 | BeanUtils.copyProperties(item, userRes); 144 | list.add(userRes); 145 | }); 146 | return list; 147 | } 148 | 149 | @Override 150 | public Boolean changeUserType(String userCode) { 151 | PdsUserManagementEntity pdsUserManagementEntity = pdsUserManagementMapper.selectByCode(userCode); 152 | if (pdsUserManagementEntity.getUserType() == 0) { 153 | pdsUserManagementEntity.setUserType(1); 154 | pdsUserManagementMapper.updateByPrimaryKeySelective(pdsUserManagementEntity); 155 | return true; 156 | } 157 | if (pdsUserManagementEntity.getUserType() == 1) { 158 | pdsUserManagementEntity.setUserType(0); 159 | pdsUserManagementMapper.updateByPrimaryKeySelective(pdsUserManagementEntity); 160 | return true; 161 | } 162 | return false; 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | #spring.datasource.url=jdbc:mysql://120.77.221.43:3306/accesscontrol?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai 3 | spring.datasource.url=jdbc:mysql://localhost:3306/accesscontrol?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai 4 | spring.datasource.username=root 5 | spring.datasource.password=83862973 6 | 7 | server.port=8088 8 | server.tomcat.protocol_header=x-forwarded-proto 9 | server.address=127.0.0.1 10 | mybatis.config-location=classpath:mybatis-config.xml 11 | mybatis.type-aliases-package=com.pds.access.entity 12 | mybatis.mapper-locations=classpath:mapper/*.xml,classpath:mapper/extend/*.xml 13 | spring.session.store-type=none 14 | spring.thymeleaf.cache=false 15 | spring.thymeleaf.mode=LEGACYHTML5 16 | spring.devtools.restart.enabled=false -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0} %X{ServiceId} - %m%n 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${APP}_detail.log 14 | 15 | %d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0} %X{ServiceId} - %m%n 16 | 17 | 18 | ${LOG_HOME}/${APP}_detail.log.%d{yyyyMMdd} 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/mapper/PdsUserManagementMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 23 | id, user_code, registered_time, times_in, times_out, user_type 24 | 25 | 36 | 37 | 42 | delete from pds_user_management 43 | where id = #{id,jdbcType=INTEGER} 44 | 45 | 46 | 51 | insert into pds_user_management (id, user_code, registered_time, 52 | times_in, times_out, user_type 53 | ) 54 | values (#{id,jdbcType=INTEGER}, #{userCode,jdbcType=VARCHAR}, #{registeredTime,jdbcType=TIMESTAMP}, 55 | #{timesIn,jdbcType=INTEGER}, #{timesOut,jdbcType=INTEGER}, #{userType,jdbcType=INTEGER} 56 | ) 57 | 58 | 59 | 64 | insert into pds_user_management 65 | 66 | 67 | id, 68 | 69 | 70 | user_code, 71 | 72 | 73 | registered_time, 74 | 75 | 76 | times_in, 77 | 78 | 79 | times_out, 80 | 81 | 82 | user_type, 83 | 84 | 85 | 86 | 87 | #{id,jdbcType=INTEGER}, 88 | 89 | 90 | #{userCode,jdbcType=VARCHAR}, 91 | 92 | 93 | #{registeredTime,jdbcType=TIMESTAMP}, 94 | 95 | 96 | #{timesIn,jdbcType=INTEGER}, 97 | 98 | 99 | #{timesOut,jdbcType=INTEGER}, 100 | 101 | 102 | #{userType,jdbcType=INTEGER}, 103 | 104 | 105 | 106 | 107 | 112 | update pds_user_management 113 | 114 | 115 | user_code = #{userCode,jdbcType=VARCHAR}, 116 | 117 | 118 | registered_time = #{registeredTime,jdbcType=TIMESTAMP}, 119 | 120 | 121 | times_in = #{timesIn,jdbcType=INTEGER}, 122 | 123 | 124 | times_out = #{timesOut,jdbcType=INTEGER}, 125 | 126 | 127 | user_type = #{userType,jdbcType=INTEGER}, 128 | 129 | 130 | where id = #{id,jdbcType=INTEGER} 131 | 132 | 133 | 138 | update pds_user_management 139 | set user_code = #{userCode,jdbcType=VARCHAR}, 140 | registered_time = #{registeredTime,jdbcType=TIMESTAMP}, 141 | times_in = #{timesIn,jdbcType=INTEGER}, 142 | times_out = #{timesOut,jdbcType=INTEGER}, 143 | user_type = #{userType,jdbcType=INTEGER} 144 | where id = #{id,jdbcType=INTEGER} 145 | 146 | -------------------------------------------------------------------------------- /src/main/resources/mapper/extend/PdsAccessManagementExtendMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 21 | delete from pds_access_management 22 | where user_code = #{userCode,jdbcType=VARCHAR} 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/mapper/extend/PdsUserManagementExtendMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 26 | 27 | 28 | 33 | delete from pds_user_management 34 | where user_code = #{userCode,jdbcType=VARCHAR} 35 | 36 | 37 | 52 | -------------------------------------------------------------------------------- /src/main/resources/mapper/pdsAccessManagementMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | id, user_code, access_type, access_time 22 | 23 | 34 | 35 | 40 | delete from pds_access_management 41 | where id = #{id,jdbcType=INTEGER} 42 | 43 | 44 | 49 | insert into pds_access_management (id, user_code, access_type, 50 | access_time) 51 | values (#{id,jdbcType=INTEGER}, #{userCode,jdbcType=VARCHAR}, #{accessType,jdbcType=VARCHAR}, 52 | #{accessTime,jdbcType=TIMESTAMP}) 53 | 54 | 55 | 60 | insert into pds_access_management 61 | 62 | 63 | id, 64 | 65 | 66 | user_code, 67 | 68 | 69 | access_type, 70 | 71 | 72 | access_time, 73 | 74 | 75 | 76 | 77 | #{id,jdbcType=INTEGER}, 78 | 79 | 80 | #{userCode,jdbcType=VARCHAR}, 81 | 82 | 83 | #{accessType,jdbcType=VARCHAR}, 84 | 85 | 86 | #{accessTime,jdbcType=TIMESTAMP}, 87 | 88 | 89 | 90 | 91 | 96 | update pds_access_management 97 | 98 | 99 | user_code = #{userCode,jdbcType=VARCHAR}, 100 | 101 | 102 | access_type = #{accessType,jdbcType=VARCHAR}, 103 | 104 | 105 | access_time = #{accessTime,jdbcType=TIMESTAMP}, 106 | 107 | 108 | where id = #{id,jdbcType=INTEGER} 109 | 110 | 111 | 116 | update pds_access_management 117 | set user_code = #{userCode,jdbcType=VARCHAR}, 118 | access_type = #{accessType,jdbcType=VARCHAR}, 119 | access_time = #{accessTime,jdbcType=TIMESTAMP} 120 | where id = #{id,jdbcType=INTEGER} 121 | 122 | -------------------------------------------------------------------------------- /src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/test/java/com/pds/access/AccessApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.pds.access; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AccessApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------