增加用户注册接口

master
pan 5 years ago
commit 8d56591cf5
  1. 34
      .gitignore
  2. 24
      HELP.md
  3. 34
      build.gradle
  4. 1
      gradle.properties
  5. BIN
      gradle/wrapper/gradle-wrapper.jar
  6. 6
      gradle/wrapper/gradle-wrapper.properties
  7. 183
      gradlew
  8. 103
      gradlew.bat
  9. 11
      settings.gradle
  10. 15
      src/main/java/com/share/help/Constants.java
  11. 16
      src/main/java/com/share/help/HelpApplication.java
  12. 30
      src/main/java/com/share/help/config/CrosConfiguration.java
  13. 44
      src/main/java/com/share/help/controller/UserController.java
  14. 78
      src/main/java/com/share/help/dao/UserMapper.java
  15. 138
      src/main/java/com/share/help/entity/ActivityEntity.java
  16. 127
      src/main/java/com/share/help/entity/ActivityHistoryEntity.java
  17. 103
      src/main/java/com/share/help/entity/ChatHistoryEntity.java
  18. 67
      src/main/java/com/share/help/entity/FriendEntity.java
  19. 43
      src/main/java/com/share/help/entity/FriendEntityPK.java
  20. 113
      src/main/java/com/share/help/entity/LeaveWordEntity.java
  21. 44
      src/main/java/com/share/help/entity/ManagerEntity.java
  22. 247
      src/main/java/com/share/help/entity/UserEntity.java
  23. 20
      src/main/java/com/share/help/form/UserRegisterForm.java
  24. 5
      src/main/java/com/share/help/res/CustomInterface.java
  25. 54
      src/main/java/com/share/help/res/JSONResponse.java
  26. 9
      src/main/java/com/share/help/res/Result.java
  27. 12
      src/main/java/com/share/help/res/account/RegisterRes.java
  28. 53
      src/main/java/com/share/help/service/ImageService.java
  29. 56
      src/main/java/com/share/help/service/UserService.java
  30. 27
      src/main/resources/application.yaml
  31. 41
      src/main/resources/logback-spring.xml
  32. 15
      src/main/resources/mapping/UserMapper.xml
  33. 17
      src/test/java/com/share/help/DefaultTest.java
  34. 113
      src/test/java/com/share/help/HelpApplicationTests.java

34
.gitignore vendored

@ -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/

@ -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)

@ -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()
}

@ -0,0 +1 @@
org.gradle.caching=true

Binary file not shown.

@ -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

183
gradlew vendored

@ -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" "$@"

103
gradlew.bat vendored

@ -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

@ -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'

@ -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";
}

@ -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);
}
}

@ -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> corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin(allowOrigin);
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/api/**", config);
FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
}

@ -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<RegisterRes,Void> 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);
}
}
}

@ -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<UserEntity> getAll();
/**
* 分页查询用户
* @param start 起始索引
* @param count 查询个数
* @return 返回用户列表
*/
@Select("select * from user limit #{start},#{count}")
@ResultMap("userMap")
List<UserEntity> getPage(@Param("start") long start,@Param("count") long count);
}

@ -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<ActivityHistoryEntity> activityHistoriesByActivityId;
private Collection<LeaveWordEntity> 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<ActivityHistoryEntity> getActivityHistoriesByActivityId() {
return activityHistoriesByActivityId;
}
public void setActivityHistoriesByActivityId(Collection<ActivityHistoryEntity> activityHistoriesByActivityId) {
this.activityHistoriesByActivityId = activityHistoriesByActivityId;
}
public Collection<LeaveWordEntity> getLeaveWordsByActivityId() {
return leaveWordsByActivityId;
}
public void setLeaveWordsByActivityId(Collection<LeaveWordEntity> leaveWordsByActivityId) {
this.leaveWordsByActivityId = leaveWordsByActivityId;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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);
}
}

@ -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;
}
}

@ -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);
}
}

@ -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<ActivityHistoryEntity> activityHistoriesByUserId;
private Collection<ChatHistoryEntity> chatHistoriesByUserId;
private Collection<ChatHistoryEntity> chatHistoriesByUserId_0;
private Collection<FriendEntity> friendsByUserId;
private Collection<FriendEntity> friendsByUserId_0;
private Collection<LeaveWordEntity> leaveWordsByUserId;
private Collection<LeaveWordEntity> 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<ActivityHistoryEntity> getActivityHistoriesByUserId() {
return activityHistoriesByUserId;
}
public void setActivityHistoriesByUserId(Collection<ActivityHistoryEntity> activityHistoriesByUserId) {
this.activityHistoriesByUserId = activityHistoriesByUserId;
}
public Collection<ChatHistoryEntity> getChatHistoriesByUserId() {
return chatHistoriesByUserId;
}
public void setChatHistoriesByUserId(Collection<ChatHistoryEntity> chatHistoriesByUserId) {
this.chatHistoriesByUserId = chatHistoriesByUserId;
}
public Collection<ChatHistoryEntity> getChatHistoriesByUserId_0() {
return chatHistoriesByUserId_0;
}
public void setChatHistoriesByUserId_0(Collection<ChatHistoryEntity> chatHistoriesByUserId_0) {
this.chatHistoriesByUserId_0 = chatHistoriesByUserId_0;
}
public Collection<FriendEntity> getFriendsByUserId() {
return friendsByUserId;
}
public void setFriendsByUserId(Collection<FriendEntity> friendsByUserId) {
this.friendsByUserId = friendsByUserId;
}
public Collection<FriendEntity> getFriendsByUserId_0() {
return friendsByUserId_0;
}
public void setFriendsByUserId_0(Collection<FriendEntity> friendsByUserId_0) {
this.friendsByUserId_0 = friendsByUserId_0;
}
public Collection<LeaveWordEntity> getLeaveWordsByUserId() {
return leaveWordsByUserId;
}
public void setLeaveWordsByUserId(Collection<LeaveWordEntity> leaveWordsByUserId) {
this.leaveWordsByUserId = leaveWordsByUserId;
}
public Collection<LeaveWordEntity> getLeaveWordsByUserId_0() {
return leaveWordsByUserId_0;
}
public void setLeaveWordsByUserId_0(Collection<LeaveWordEntity> leaveWordsByUserId_0) {
this.leaveWordsByUserId_0 = leaveWordsByUserId_0;
}
}

@ -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;
}
}

@ -0,0 +1,5 @@
package com.share.help.res;
public interface CustomInterface {
}

@ -0,0 +1,54 @@
package com.share.help.res;
/**
* 响应json
* @param <E>
* @param <L>
*/
public class JSONResponse<E extends Enum<E>,L> {
/**
* 响应信息
*/
private Enum<E> customResult;
/**
* 响应状态
*/
private Result result;
/**
* 响应数据
*/
private L body;
public Enum<E> getCustomResult() {
return customResult;
}
public void setCustomResult(Enum<E> 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<E> customResult, Result result) {
this.customResult = customResult;
this.result = result;
}
}

@ -0,0 +1,9 @@
package com.share.help.res;
/**
* 响应结果
*/
public enum Result {
OK,
FAIL
}

@ -0,0 +1,12 @@
package com.share.help.res.account;
public enum RegisterRes {
//注册成功
ok,
//系统异常,注册失败
fail,
//用户id重复
user_repeat,
//表单解析错误
form_parse_error
}

@ -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;
}
}
}

@ -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<RegisterRes,Void> 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);
}
}

@ -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

@ -0,0 +1,41 @@
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="APP_NAME" value="Logback"/>
<property name="LOG_HOME_PATH" value="logs"/>
<property name="DEBUG_LOG_FILE" value="${LOG_HOME_PATH}/debug/${APP_NAME}_debug" />
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}" />
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${DEBUG_LOG_FILE}.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>60</MaxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
<root level="DEBUG">
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.share.help.dao.UserMapper">
<resultMap id="userMap" type="com.share.help.entity.UserEntity">
<id property="userId" column="user_id"/>
<result property="userId" column="user_id"/>
<result property="headImg" column="head_img"/>
<result property="serviceAddress" column="service_address"/>
<result property="userType" column="user_type"/>
<result property="timeScore" column="time_score"/>
<result property="chatStatus" column="chat_status"/>
</resultMap>
</mapper>

@ -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()+"");
}
}

@ -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<UserEntity> 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());
}
}
Loading…
Cancel
Save