commit 8d56591cf52d083e0ae18396648895003eee30de Author: pan <1029559041@qq.com> Date: Wed May 27 03:17:30 2020 +0800 增加用户注册接口 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29004ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ +/lib/ +/logs/ diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..4a049a8 --- /dev/null +++ b/HELP.md @@ -0,0 +1,24 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/gradle-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/gradle-plugin/reference/html/#build-image) +* [Spring Web](https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications) +* [MyBatis Framework](https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) +* [MyBatis Quick Start](https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..76c2b65 --- /dev/null +++ b/build.gradle @@ -0,0 +1,34 @@ +plugins { + id 'org.springframework.boot' version '2.3.0.RELEASE' + id 'io.spring.dependency-management' version '1.0.9.RELEASE' + id 'java' +} + + +group = 'com.share' +version = '0.0.1-SNAPSHOT' + +repositories { + maven {url 'https://maven.aliyun.com/repository/public'} + maven {url 'https://maven.aliyun.com/repository/jcenter'} + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.2' + implementation group: 'commons-io', name: 'commons-io', version: '2.6' + implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.20' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '2.3.0.RELEASE' + // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 + implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } +} + + + +test { + useJUnitPlatform() +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..5f1ed7b --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +org.gradle.caching=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f3d88b1 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ec24e0f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat May 16 23:11:09 CST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..2fe81a7 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +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 +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +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 + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..62bd9b9 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..ea54d3d --- /dev/null +++ b/settings.gradle @@ -0,0 +1,11 @@ +//plugins{ +// id "com.gradle.enterprise" version "3.2" +//} +//gradleEnterprise { +// buildScan { +// termsOfServiceUrl = 'https://gradle.com/terms-of-service' +// termsOfServiceAgree = 'yes' +// allowUntrustedServer = true +// } +//} +rootProject.name = 'help' \ No newline at end of file diff --git a/src/main/java/com/share/help/Constants.java b/src/main/java/com/share/help/Constants.java new file mode 100644 index 0000000..f312671 --- /dev/null +++ b/src/main/java/com/share/help/Constants.java @@ -0,0 +1,15 @@ +package com.share.help; + +/** + * 常量 + */ +public class Constants { + + //用户接口前缀 + public static final String USER_INTERFACE="/api/user"; + + //用户注册接口 + public static final String USER_INTERFACE_REGISTER="/register"; + + +} diff --git a/src/main/java/com/share/help/HelpApplication.java b/src/main/java/com/share/help/HelpApplication.java new file mode 100644 index 0000000..bcb8fdd --- /dev/null +++ b/src/main/java/com/share/help/HelpApplication.java @@ -0,0 +1,16 @@ +package com.share.help; + +import org.mybatis.spring.annotation.MapperScan; +import org.mybatis.spring.annotation.MapperScans; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScans(@MapperScan("com.share.help.dao")) +public class HelpApplication { + + public static void main(String[] args) { + SpringApplication.run(HelpApplication.class, args); + } + +} diff --git a/src/main/java/com/share/help/config/CrosConfiguration.java b/src/main/java/com/share/help/config/CrosConfiguration.java new file mode 100644 index 0000000..8801bb7 --- /dev/null +++ b/src/main/java/com/share/help/config/CrosConfiguration.java @@ -0,0 +1,30 @@ +package com.share.help.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +@Configuration +public class CrosConfiguration { + + @Value("${cros.allow-origin}") + private String allowOrigin; + + @Bean + public FilterRegistrationBean corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin(allowOrigin); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + source.registerCorsConfiguration("/api/**", config); + FilterRegistrationBean bean = new FilterRegistrationBean<>(new CorsFilter(source)); + bean.setOrder(0); + return bean; + } +} diff --git a/src/main/java/com/share/help/controller/UserController.java b/src/main/java/com/share/help/controller/UserController.java new file mode 100644 index 0000000..2464331 --- /dev/null +++ b/src/main/java/com/share/help/controller/UserController.java @@ -0,0 +1,44 @@ +package com.share.help.controller; + +import com.share.help.Constants; +import com.share.help.form.UserRegisterForm; +import com.share.help.res.JSONResponse; +import com.share.help.res.Result; +import com.share.help.res.account.RegisterRes; +import com.share.help.service.UserService; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 用户接口 + */ +@RestController +@RequestMapping(Constants.USER_INTERFACE) +public class UserController { + + @Autowired + private UserService userService; + + /** + * 注册 + * @param userRegisterForm 注册表单 + * @return 响应注册结果 + */ + @PutMapping(Constants.USER_INTERFACE_REGISTER) + public JSONResponse register(UserRegisterForm userRegisterForm){ + if(StringUtils.isNoneEmpty(userRegisterForm.getUserId(),userRegisterForm.getPassword(), + userRegisterForm.getName(),userRegisterForm.getSex(),userRegisterForm.getAddress(), + userRegisterForm.getServiceAddress(),userRegisterForm.getUserType(), + userRegisterForm.getEmail(),userRegisterForm.getInfo())&& + ObjectUtils.allNotNull(userRegisterForm.getMobile(),userRegisterForm.getImgFile())){ + return userService.register(userRegisterForm); + }else { + return new JSONResponse<>(RegisterRes.ok, Result.OK); + } + + } +} diff --git a/src/main/java/com/share/help/dao/UserMapper.java b/src/main/java/com/share/help/dao/UserMapper.java new file mode 100644 index 0000000..14f01a6 --- /dev/null +++ b/src/main/java/com/share/help/dao/UserMapper.java @@ -0,0 +1,78 @@ +package com.share.help.dao; + +import com.share.help.entity.UserEntity; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +/** + * 用户数据接口 + */ +public interface UserMapper { + + /** + * 添加用户 + * @param user 用户信息 + */ + @Insert("insert into user(user_id,password,name,sex,head_img,address,service_address,user_type,mobile,email,info,time_score,chat_status)value(#{userId},#{password},#{name},#{sex},#{headImg},#{address},#{serviceAddress},#{userType},#{mobile},#{email},#{info},#{timeScore},#{chatStatus})") + boolean insert(UserEntity user); + + /** + * 根据用户账号删除用户 + * @param userId 用户账号 + */ + @Delete("delete from user where user_id=#{userId}") + boolean delete(@Param("userId") String userId); + + /** + * 根据用户账号查找用户 + * @param userId 用户id + * @return 返回用户 + */ + @Select("select * from user where user_id=#{userId}") + @ResultMap("userMap") + UserEntity findOne(@Param("userId") String userId); + + /** + * 根据用户账号密码查找用户 + * @param userId 用户id + * @param password 密码 + * @return 返回用户 + */ + @Select("select * from user where user_id=#{userId} and password=#{password}") + @ResultMap("userMap") + UserEntity findOneWithPwd(@Param("userId") String userId, @Param("password") String password); + + /** + * + * @param userEntity 更新用户 + * @return 返回更新结果 + */ + @Update("update user set password=#{password} where user_id=#{userId}") + boolean update(UserEntity userEntity); + + /** + * 根据用户id判断用户是否存在 + * @param userId 用户id + * @return true存在,false不存在 + */ + @Select("select count(*) from user where user_id=#{userId}") + boolean hasUser(@Param("userId") String userId); + /** + * + * @return 获取所有用户 + */ + @Select("select * from user") + @ResultMap("userMap") + List getAll(); + + /** + * 分页查询用户 + * @param start 起始索引 + * @param count 查询个数 + * @return 返回用户列表 + */ + @Select("select * from user limit #{start},#{count}") + @ResultMap("userMap") + List getPage(@Param("start") long start,@Param("count") long count); +} diff --git a/src/main/java/com/share/help/entity/ActivityEntity.java b/src/main/java/com/share/help/entity/ActivityEntity.java new file mode 100644 index 0000000..ac06424 --- /dev/null +++ b/src/main/java/com/share/help/entity/ActivityEntity.java @@ -0,0 +1,138 @@ +package com.share.help.entity; + +import java.sql.Timestamp; +import java.util.Collection; +import java.util.Objects; + + + +public class ActivityEntity { + private Long activityId; + private String title; + private String content; + private Timestamp seekHelpTime; + private Timestamp activityStartTime; + private Timestamp activityEndTime; + private String activityImg; + private String serviceAddress; + private Collection activityHistoriesByActivityId; + private Collection leaveWordsByActivityId; + + + + public Long getActivityId() { + return activityId; + } + + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + + + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + + + public Timestamp getSeekHelpTime() { + return seekHelpTime; + } + + public void setSeekHelpTime(Timestamp seekHelpTime) { + this.seekHelpTime = seekHelpTime; + } + + + + public Timestamp getActivityStartTime() { + return activityStartTime; + } + + public void setActivityStartTime(Timestamp activityStartTime) { + this.activityStartTime = activityStartTime; + } + + + + public Timestamp getActivityEndTime() { + return activityEndTime; + } + + public void setActivityEndTime(Timestamp activityEndTime) { + this.activityEndTime = activityEndTime; + } + + + + public String getActivityImg() { + return activityImg; + } + + public void setActivityImg(String activityImg) { + this.activityImg = activityImg; + } + + + + public String getServiceAddress() { + return serviceAddress; + } + + public void setServiceAddress(String serviceAddress) { + this.serviceAddress = serviceAddress; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ActivityEntity that = (ActivityEntity) o; + return Objects.equals(activityId, that.activityId) && + Objects.equals(title, that.title) && + Objects.equals(content, that.content) && + Objects.equals(seekHelpTime, that.seekHelpTime) && + Objects.equals(activityStartTime, that.activityStartTime) && + Objects.equals(activityEndTime, that.activityEndTime) && + Objects.equals(activityImg, that.activityImg) && + Objects.equals(serviceAddress, that.serviceAddress); + } + + @Override + public int hashCode() { + return Objects.hash(activityId, title, content, seekHelpTime, activityStartTime, activityEndTime, activityImg, serviceAddress); + } + + + public Collection getActivityHistoriesByActivityId() { + return activityHistoriesByActivityId; + } + + public void setActivityHistoriesByActivityId(Collection activityHistoriesByActivityId) { + this.activityHistoriesByActivityId = activityHistoriesByActivityId; + } + + + public Collection getLeaveWordsByActivityId() { + return leaveWordsByActivityId; + } + + public void setLeaveWordsByActivityId(Collection leaveWordsByActivityId) { + this.leaveWordsByActivityId = leaveWordsByActivityId; + } +} diff --git a/src/main/java/com/share/help/entity/ActivityHistoryEntity.java b/src/main/java/com/share/help/entity/ActivityHistoryEntity.java new file mode 100644 index 0000000..935cbe0 --- /dev/null +++ b/src/main/java/com/share/help/entity/ActivityHistoryEntity.java @@ -0,0 +1,127 @@ +package com.share.help.entity; + +import java.sql.Timestamp; +import java.util.Objects; + + + +public class ActivityHistoryEntity { + private Long historyId; + private Long activityId; + private String userId; + private String activityStatus; + private Timestamp createTime; + private Long activityScore; + private Integer timeScore; + private ActivityEntity activityByActivityId; + private UserEntity userByUserId; + + + + public Long getHistoryId() { + return historyId; + } + + public void setHistoryId(Long historyId) { + this.historyId = historyId; + } + + + + public Long getActivityId() { + return activityId; + } + + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + + + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + + + public String getActivityStatus() { + return activityStatus; + } + + public void setActivityStatus(String activityStatus) { + this.activityStatus = activityStatus; + } + + + + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + + + public Long getActivityScore() { + return activityScore; + } + + public void setActivityScore(Long activityScore) { + this.activityScore = activityScore; + } + + + + public Integer getTimeScore() { + return timeScore; + } + + public void setTimeScore(Integer timeScore) { + this.timeScore = timeScore; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ActivityHistoryEntity that = (ActivityHistoryEntity) o; + return Objects.equals(historyId, that.historyId) && + Objects.equals(activityId, that.activityId) && + Objects.equals(userId, that.userId) && + Objects.equals(activityStatus, that.activityStatus) && + Objects.equals(createTime, that.createTime) && + Objects.equals(activityScore, that.activityScore) && + Objects.equals(timeScore, that.timeScore); + } + + @Override + public int hashCode() { + return Objects.hash(historyId, activityId, userId, activityStatus, createTime, activityScore, timeScore); + } + + + + public ActivityEntity getActivityByActivityId() { + return activityByActivityId; + } + + public void setActivityByActivityId(ActivityEntity activityByActivityId) { + this.activityByActivityId = activityByActivityId; + } + + + + public UserEntity getUserByUserId() { + return userByUserId; + } + + public void setUserByUserId(UserEntity userByUserId) { + this.userByUserId = userByUserId; + } +} diff --git a/src/main/java/com/share/help/entity/ChatHistoryEntity.java b/src/main/java/com/share/help/entity/ChatHistoryEntity.java new file mode 100644 index 0000000..687507f --- /dev/null +++ b/src/main/java/com/share/help/entity/ChatHistoryEntity.java @@ -0,0 +1,103 @@ +package com.share.help.entity; + +import java.sql.Timestamp; +import java.util.Objects; + + + +public class ChatHistoryEntity { + private Long chatId; + private String sourceUserId; + private String targetUserId; + private Timestamp sendTime; + private String content; + private UserEntity userBySourceUserId; + private UserEntity userByTargetUserId; + + + + public Long getChatId() { + return chatId; + } + + public void setChatId(Long chatId) { + this.chatId = chatId; + } + + + + public String getSourceUserId() { + return sourceUserId; + } + + public void setSourceUserId(String sourceUserId) { + this.sourceUserId = sourceUserId; + } + + + + public String getTargetUserId() { + return targetUserId; + } + + public void setTargetUserId(String targetUserId) { + this.targetUserId = targetUserId; + } + + + + public Timestamp getSendTime() { + return sendTime; + } + + public void setSendTime(Timestamp sendTime) { + this.sendTime = sendTime; + } + + + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChatHistoryEntity that = (ChatHistoryEntity) o; + return Objects.equals(chatId, that.chatId) && + Objects.equals(sourceUserId, that.sourceUserId) && + Objects.equals(targetUserId, that.targetUserId) && + Objects.equals(sendTime, that.sendTime) && + Objects.equals(content, that.content); + } + + @Override + public int hashCode() { + return Objects.hash(chatId, sourceUserId, targetUserId, sendTime, content); + } + + + + public UserEntity getUserBySourceUserId() { + return userBySourceUserId; + } + + public void setUserBySourceUserId(UserEntity userBySourceUserId) { + this.userBySourceUserId = userBySourceUserId; + } + + + + public UserEntity getUserByTargetUserId() { + return userByTargetUserId; + } + + public void setUserByTargetUserId(UserEntity userByTargetUserId) { + this.userByTargetUserId = userByTargetUserId; + } +} diff --git a/src/main/java/com/share/help/entity/FriendEntity.java b/src/main/java/com/share/help/entity/FriendEntity.java new file mode 100644 index 0000000..00df084 --- /dev/null +++ b/src/main/java/com/share/help/entity/FriendEntity.java @@ -0,0 +1,67 @@ +package com.share.help.entity; + +import java.util.Objects; + + + + +public class FriendEntity { + private String sourceUserId; + private String targetUserId; + private UserEntity userBySourceUserId; + private UserEntity userByTargetUserId; + + + + public String getSourceUserId() { + return sourceUserId; + } + + public void setSourceUserId(String sourceUserId) { + this.sourceUserId = sourceUserId; + } + + + + public String getTargetUserId() { + return targetUserId; + } + + public void setTargetUserId(String targetUserId) { + this.targetUserId = targetUserId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FriendEntity that = (FriendEntity) o; + return Objects.equals(sourceUserId, that.sourceUserId) && + Objects.equals(targetUserId, that.targetUserId); + } + + @Override + public int hashCode() { + return Objects.hash(sourceUserId, targetUserId); + } + + + + public UserEntity getUserBySourceUserId() { + return userBySourceUserId; + } + + public void setUserBySourceUserId(UserEntity userBySourceUserId) { + this.userBySourceUserId = userBySourceUserId; + } + + + + public UserEntity getUserByTargetUserId() { + return userByTargetUserId; + } + + public void setUserByTargetUserId(UserEntity userByTargetUserId) { + this.userByTargetUserId = userByTargetUserId; + } +} diff --git a/src/main/java/com/share/help/entity/FriendEntityPK.java b/src/main/java/com/share/help/entity/FriendEntityPK.java new file mode 100644 index 0000000..cb2d78f --- /dev/null +++ b/src/main/java/com/share/help/entity/FriendEntityPK.java @@ -0,0 +1,43 @@ +package com.share.help.entity; + +import java.io.Serializable; +import java.util.Objects; + +public class FriendEntityPK implements Serializable { + private String sourceUserId; + private String targetUserId; + + + + public String getSourceUserId() { + return sourceUserId; + } + + public void setSourceUserId(String sourceUserId) { + this.sourceUserId = sourceUserId; + } + + + + public String getTargetUserId() { + return targetUserId; + } + + public void setTargetUserId(String targetUserId) { + this.targetUserId = targetUserId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FriendEntityPK that = (FriendEntityPK) o; + return Objects.equals(sourceUserId, that.sourceUserId) && + Objects.equals(targetUserId, that.targetUserId); + } + + @Override + public int hashCode() { + return Objects.hash(sourceUserId, targetUserId); + } +} diff --git a/src/main/java/com/share/help/entity/LeaveWordEntity.java b/src/main/java/com/share/help/entity/LeaveWordEntity.java new file mode 100644 index 0000000..97e64f6 --- /dev/null +++ b/src/main/java/com/share/help/entity/LeaveWordEntity.java @@ -0,0 +1,113 @@ +package com.share.help.entity; + +import java.util.Objects; + + + +public class LeaveWordEntity { + private Long leaveWordId; + private String type; + private String sourceUserId; + private String targetUserId; + private Long activityId; + private UserEntity userBySourceUserId; + private UserEntity userByTargetUserId; + private ActivityEntity activityByActivityId; + + + + public Long getLeaveWordId() { + return leaveWordId; + } + + public void setLeaveWordId(Long leaveWordId) { + this.leaveWordId = leaveWordId; + } + + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + + + public String getSourceUserId() { + return sourceUserId; + } + + public void setSourceUserId(String sourceUserId) { + this.sourceUserId = sourceUserId; + } + + + + public String getTargetUserId() { + return targetUserId; + } + + public void setTargetUserId(String targetUserId) { + this.targetUserId = targetUserId; + } + + + + public Long getActivityId() { + return activityId; + } + + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LeaveWordEntity that = (LeaveWordEntity) o; + return Objects.equals(leaveWordId, that.leaveWordId) && + Objects.equals(type, that.type) && + Objects.equals(sourceUserId, that.sourceUserId) && + Objects.equals(targetUserId, that.targetUserId) && + Objects.equals(activityId, that.activityId); + } + + @Override + public int hashCode() { + return Objects.hash(leaveWordId, type, sourceUserId, targetUserId, activityId); + } + + + + public UserEntity getUserBySourceUserId() { + return userBySourceUserId; + } + + public void setUserBySourceUserId(UserEntity userBySourceUserId) { + this.userBySourceUserId = userBySourceUserId; + } + + + + public UserEntity getUserByTargetUserId() { + return userByTargetUserId; + } + + public void setUserByTargetUserId(UserEntity userByTargetUserId) { + this.userByTargetUserId = userByTargetUserId; + } + + + + public ActivityEntity getActivityByActivityId() { + return activityByActivityId; + } + + public void setActivityByActivityId(ActivityEntity activityByActivityId) { + this.activityByActivityId = activityByActivityId; + } +} diff --git a/src/main/java/com/share/help/entity/ManagerEntity.java b/src/main/java/com/share/help/entity/ManagerEntity.java new file mode 100644 index 0000000..fb08d6f --- /dev/null +++ b/src/main/java/com/share/help/entity/ManagerEntity.java @@ -0,0 +1,44 @@ +package com.share.help.entity; + +import java.util.Objects; + + + +public class ManagerEntity { + private String managerId; + private String password; + + + + public String getManagerId() { + return managerId; + } + + public void setManagerId(String managerId) { + this.managerId = managerId; + } + + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ManagerEntity that = (ManagerEntity) o; + return Objects.equals(managerId, that.managerId) && + Objects.equals(password, that.password); + } + + @Override + public int hashCode() { + return Objects.hash(managerId, password); + } +} diff --git a/src/main/java/com/share/help/entity/UserEntity.java b/src/main/java/com/share/help/entity/UserEntity.java new file mode 100644 index 0000000..0f641ba --- /dev/null +++ b/src/main/java/com/share/help/entity/UserEntity.java @@ -0,0 +1,247 @@ +package com.share.help.entity; + +import java.util.Collection; +import java.util.Objects; + + + +public class UserEntity { + private String userId; + private String password; + private String name; + private String sex; + private String headImg; + private String address; + private String serviceAddress; + private String userType; + private Long mobile; + private String email; + private String info; + private Integer timeScore; + private Boolean chatStatus; + private Collection activityHistoriesByUserId; + private Collection chatHistoriesByUserId; + private Collection chatHistoriesByUserId_0; + private Collection friendsByUserId; + private Collection friendsByUserId_0; + private Collection leaveWordsByUserId; + private Collection leaveWordsByUserId_0; + + + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + + + public String getHeadImg() { + return headImg; + } + + public void setHeadImg(String headImg) { + this.headImg = headImg; + } + + + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + + + public String getServiceAddress() { + return serviceAddress; + } + + public void setServiceAddress(String serviceAddress) { + this.serviceAddress = serviceAddress; + } + + + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + + + public Long getMobile() { + return mobile; + } + + public void setMobile(Long mobile) { + this.mobile = mobile; + } + + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + + + public Integer getTimeScore() { + return timeScore; + } + + public void setTimeScore(Integer timeScore) { + this.timeScore = timeScore; + } + + + + public Boolean getChatStatus() { + return chatStatus; + } + + public void setChatStatus(Boolean chatStatus) { + this.chatStatus = chatStatus; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UserEntity that = (UserEntity) o; + return Objects.equals(userId, that.userId) && + Objects.equals(password, that.password) && + Objects.equals(name, that.name) && + Objects.equals(sex, that.sex) && + Objects.equals(headImg, that.headImg) && + Objects.equals(address, that.address) && + Objects.equals(serviceAddress, that.serviceAddress) && + Objects.equals(userType, that.userType) && + Objects.equals(mobile, that.mobile) && + Objects.equals(email, that.email) && + Objects.equals(info, that.info) && + Objects.equals(timeScore, that.timeScore) && + Objects.equals(chatStatus, that.chatStatus); + } + + @Override + public int hashCode() { + return Objects.hash(userId, password, name, sex, headImg, address, serviceAddress, userType, mobile, email, info, timeScore, chatStatus); + } + + + public Collection getActivityHistoriesByUserId() { + return activityHistoriesByUserId; + } + + public void setActivityHistoriesByUserId(Collection activityHistoriesByUserId) { + this.activityHistoriesByUserId = activityHistoriesByUserId; + } + + + public Collection getChatHistoriesByUserId() { + return chatHistoriesByUserId; + } + + public void setChatHistoriesByUserId(Collection chatHistoriesByUserId) { + this.chatHistoriesByUserId = chatHistoriesByUserId; + } + + + public Collection getChatHistoriesByUserId_0() { + return chatHistoriesByUserId_0; + } + + public void setChatHistoriesByUserId_0(Collection chatHistoriesByUserId_0) { + this.chatHistoriesByUserId_0 = chatHistoriesByUserId_0; + } + + + public Collection getFriendsByUserId() { + return friendsByUserId; + } + + public void setFriendsByUserId(Collection friendsByUserId) { + this.friendsByUserId = friendsByUserId; + } + + + public Collection getFriendsByUserId_0() { + return friendsByUserId_0; + } + + public void setFriendsByUserId_0(Collection friendsByUserId_0) { + this.friendsByUserId_0 = friendsByUserId_0; + } + + + public Collection getLeaveWordsByUserId() { + return leaveWordsByUserId; + } + + public void setLeaveWordsByUserId(Collection leaveWordsByUserId) { + this.leaveWordsByUserId = leaveWordsByUserId; + } + + + public Collection getLeaveWordsByUserId_0() { + return leaveWordsByUserId_0; + } + + public void setLeaveWordsByUserId_0(Collection leaveWordsByUserId_0) { + this.leaveWordsByUserId_0 = leaveWordsByUserId_0; + } +} diff --git a/src/main/java/com/share/help/form/UserRegisterForm.java b/src/main/java/com/share/help/form/UserRegisterForm.java new file mode 100644 index 0000000..76da3d6 --- /dev/null +++ b/src/main/java/com/share/help/form/UserRegisterForm.java @@ -0,0 +1,20 @@ +package com.share.help.form; + +import com.share.help.entity.UserEntity; +import org.springframework.web.multipart.MultipartFile; + +/** + * 注册表单 + */ +public class UserRegisterForm extends UserEntity { + //头像文件 + private MultipartFile imgFile; + + public MultipartFile getImgFile() { + return imgFile; + } + + public void setImgFile(MultipartFile imgFile) { + this.imgFile = imgFile; + } +} diff --git a/src/main/java/com/share/help/res/CustomInterface.java b/src/main/java/com/share/help/res/CustomInterface.java new file mode 100644 index 0000000..aa55f10 --- /dev/null +++ b/src/main/java/com/share/help/res/CustomInterface.java @@ -0,0 +1,5 @@ +package com.share.help.res; + +public interface CustomInterface { + +} diff --git a/src/main/java/com/share/help/res/JSONResponse.java b/src/main/java/com/share/help/res/JSONResponse.java new file mode 100644 index 0000000..fe37d7f --- /dev/null +++ b/src/main/java/com/share/help/res/JSONResponse.java @@ -0,0 +1,54 @@ +package com.share.help.res; + +/** + * 响应json + * @param + * @param + */ +public class JSONResponse,L> { + /** + * 响应信息 + */ + private Enum customResult; + + /** + * 响应状态 + */ + private Result result; + + /** + * 响应数据 + */ + private L body; + + public Enum getCustomResult() { + return customResult; + } + + public void setCustomResult(Enum customResult) { + this.customResult = customResult; + } + + public Result getResult() { + return result; + } + + public void setResult(Result result) { + this.result = result; + } + + public L getBody() { + return body; + } + + public void setBody(L body) { + this.body = body; + } + + public JSONResponse(Enum customResult, Result result) { + this.customResult = customResult; + this.result = result; + } +} + + diff --git a/src/main/java/com/share/help/res/Result.java b/src/main/java/com/share/help/res/Result.java new file mode 100644 index 0000000..86a98e2 --- /dev/null +++ b/src/main/java/com/share/help/res/Result.java @@ -0,0 +1,9 @@ +package com.share.help.res; + +/** + * 响应结果 + */ +public enum Result { + OK, + FAIL +} \ No newline at end of file diff --git a/src/main/java/com/share/help/res/account/RegisterRes.java b/src/main/java/com/share/help/res/account/RegisterRes.java new file mode 100644 index 0000000..e12077f --- /dev/null +++ b/src/main/java/com/share/help/res/account/RegisterRes.java @@ -0,0 +1,12 @@ +package com.share.help.res.account; + +public enum RegisterRes { + //注册成功 + ok, + //系统异常,注册失败 + fail, + //用户id重复 + user_repeat, + //表单解析错误 + form_parse_error +} diff --git a/src/main/java/com/share/help/service/ImageService.java b/src/main/java/com/share/help/service/ImageService.java new file mode 100644 index 0000000..7f09d90 --- /dev/null +++ b/src/main/java/com/share/help/service/ImageService.java @@ -0,0 +1,53 @@ +package com.share.help.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +enum ImageType{ + jpg, + jpeg, + png +} + +public abstract class ImageService { + private Logger logger = LoggerFactory.getLogger(ImageService.class); + + @Value("${spring.resources.static-locations}") + private String imgPath; + /** + * 保存头像文件到本地 + * @param file 头像文件 + * @return 返回头像文件名 + */ + protected String saveImg(MultipartFile file){ + String fileName; + //判断图片类型 + if(file.getContentType()==null){ + return null; + }else if(file.getContentType().contains(ImageType.jpg.name())){ + fileName= UUID.randomUUID()+"."+ImageType.jpg.name(); + }else if(file.getContentType().contains(ImageType.jpeg.name())){ + fileName= UUID.randomUUID()+"."+ImageType.jpeg.name(); + }else if (file.getContentType().contains(ImageType.png.name())) { + fileName= UUID.randomUUID()+"."+ImageType.png.name(); + } else { + return null; + } + + File loadFile = new File(getClass().getResource("/").getFile() + imgPath.replace("classpath:/", ""), fileName); + try { + file.transferTo(loadFile); + return fileName; + } catch (IOException e) { + e.printStackTrace(); + logger.error(String.valueOf(e)); + return null; + } + } +} diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java new file mode 100644 index 0000000..aa0c7ab --- /dev/null +++ b/src/main/java/com/share/help/service/UserService.java @@ -0,0 +1,56 @@ +package com.share.help.service; + +import com.share.help.dao.UserMapper; +import com.share.help.entity.UserEntity; +import com.share.help.form.UserRegisterForm; +import com.share.help.res.JSONResponse; +import com.share.help.res.Result; +import com.share.help.res.account.RegisterRes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.DigestUtils; + +@Service +public class UserService extends ImageService{ + + @Autowired + private UserMapper userMapper; + + @Value("${user.register.time-score}") + private int timeScore; + + /** + * 注册 + * @param userRegisterForm 注册表单 + * @return 返回注册结果 + */ + public JSONResponse register(UserRegisterForm userRegisterForm){ + if(userMapper.hasUser(userRegisterForm.getUserId())){ + return new JSONResponse<>(RegisterRes.user_repeat,Result.FAIL); + } + + UserEntity userEntity=new UserEntity(); + userEntity.setUserId(userRegisterForm.getUserId()); + //MD5密码 + String newPassword=DigestUtils.md5DigestAsHex(userRegisterForm.getPassword().getBytes()); + userEntity.setPassword(newPassword); + userEntity.setName(userRegisterForm.getName()); + userEntity.setSex(userRegisterForm.getSex()); + //保存头像 + String imageName=saveImg(userRegisterForm.getImgFile()); + if(imageName==null){ + return new JSONResponse<>(RegisterRes.fail, Result.FAIL); + } + userEntity.setHeadImg(imageName); + userEntity.setAddress(userRegisterForm.getAddress()); + userEntity.setServiceAddress(userRegisterForm.getServiceAddress()); + userEntity.setUserType(userRegisterForm.getUserType()); + userEntity.setMobile(userRegisterForm.getMobile()); + userEntity.setEmail(userRegisterForm.getEmail()); + userEntity.setInfo(userRegisterForm.getInfo()); + userEntity.setTimeScore(timeScore); + userEntity.setChatStatus(false); + return userMapper.insert(userEntity)?new JSONResponse<>(RegisterRes.ok, Result.OK):new JSONResponse<>(RegisterRes.fail, Result.FAIL); + } +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 0000000..182824c --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,27 @@ +spring: + #数据库配置 + datasource: + username: sukura + password: 123456 + url: jdbc:mysql://localhost:3306/help + #静态资源目录 + mvc: + static-path-pattern: /image/** + resources: + static-locations: classpath:/resources/static/image +#mybatis配置 +mybatis: + mapper-locations: classpath:mapping/*.xml +#日志配置 +logging: + level: + root: info +#跨域配置 +cros: + allow-origin: 'http://localhost:3000' +#用户 +user: + #注册 + register: + #初始时间币 + time-score: 20 diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..b236f75 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + ${FILE_LOG_PATTERN} + + + + ${DEBUG_LOG_FILE}.%d{yyyy-MM-dd}.log + 60 + + + + DEBUG + + + + + + ${FILE_LOG_PATTERN} + + + + INFO + + + + + + + + + diff --git a/src/main/resources/mapping/UserMapper.xml b/src/main/resources/mapping/UserMapper.xml new file mode 100644 index 0000000..247200a --- /dev/null +++ b/src/main/resources/mapping/UserMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/share/help/DefaultTest.java b/src/test/java/com/share/help/DefaultTest.java new file mode 100644 index 0000000..a71ad70 --- /dev/null +++ b/src/test/java/com/share/help/DefaultTest.java @@ -0,0 +1,17 @@ +package com.share.help; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.UUID; + +public class DefaultTest { + + private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); + + @Test + public void test() { + logger.info(UUID.randomUUID().toString().length()+""); + } +} diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java new file mode 100644 index 0000000..9192af8 --- /dev/null +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -0,0 +1,113 @@ +package com.share.help; + +import com.share.help.dao.UserMapper; +import com.share.help.entity.UserEntity; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mybatis.spring.annotation.MapperScan; +import org.mybatis.spring.annotation.MapperScans; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.List; +import java.util.UUID; + +@SpringBootTest +@MapperScans(@MapperScan("com.share.help.dao")) +class HelpApplicationTests { + + @Autowired + private WebApplicationContext context; + + protected MockMvc mvc; + + @Autowired + private UserMapper userMapper; + + private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); + + @BeforeEach + public void setUp() { + mvc = MockMvcBuilders.webAppContextSetup(context).build(); + } + + @Test + void contextLoads() { + + } + + @Test + public void testAnsi(){ + logger.info(UUID.randomUUID().toString().length()+""); + } + + /** + *测试增删查改 + */ + @Test + public void testUser(){ + String userId="fff"; + String password="123456"; + UserEntity userEntity=new UserEntity(); + userEntity.setUserId(userId); + userEntity.setPassword(password); + userEntity.setName("张三"); + userEntity.setSex("男"); + userEntity.setHeadImg("/test.jpg"); + userEntity.setAddress("广州"); + userEntity.setServiceAddress("广州"); + userEntity.setUserType("服务发起者"); + userEntity.setMobile(15920722180L); + userEntity.setEmail("admin@qq.com"); + userEntity.setInfo("自我介绍"); + userEntity.setTimeScore(0); + userEntity.setChatStatus(true); + + + userMapper.insert(userEntity); + + userEntity=userMapper.findOne(userId); + + Assertions.assertEquals(password,userEntity.getPassword(),"添加成功"); + + String newPassword="22222"; + + userEntity.setPassword(newPassword); + + Assertions.assertTrue(userMapper.update(userEntity),"更新成功"); + + userEntity=userMapper.findOne(userId); + + Assertions.assertEquals(newPassword,userEntity.getPassword()); + + userEntity=userMapper.findOneWithPwd(userId,newPassword); + + Assertions.assertNotNull(userEntity); + + List u=userMapper.getAll(); + + Assertions.assertEquals(1,u.size()); + + Assertions.assertTrue(userMapper.hasUser(userId)); + + Assertions.assertTrue(userMapper.delete(userId),"删除成功"); + } + + /** + * 测试用户接口 + */ + @Test + public void testUserRegisterInterface() throws Exception { + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post(Constants.USER_INTERFACE+Constants.USER_INTERFACE_REGISTER); + mvc.perform(builder).andDo(MockMvcResultHandlers.print()); + } +}