增加接口

1.获取修改个人信息
2.修改密码
master
pan 5 years ago
parent be9604d869
commit 59194d7e76
  1. 8
      src/main/java/com/share/help/Constants.java
  2. 11
      src/main/java/com/share/help/controller/ActivityController.java
  3. 55
      src/main/java/com/share/help/controller/UserController.java
  4. 8
      src/main/java/com/share/help/dao/UserMapper.java
  5. 23
      src/main/java/com/share/help/entity/UserEntity.java
  6. 32
      src/main/java/com/share/help/form/ModifyPwdForm.java
  7. 103
      src/main/java/com/share/help/form/UpdateUserForm.java
  8. 6
      src/main/java/com/share/help/res/DefaultRes.java
  9. 7
      src/main/java/com/share/help/res/account/ModifyPwdRes.java
  10. 103
      src/main/java/com/share/help/res/account/QueryRes.java
  11. 9
      src/main/java/com/share/help/res/activity/ActivityDetailRes.java
  12. 9
      src/main/java/com/share/help/res/activity/ApplyActivityRes.java
  13. 19
      src/main/java/com/share/help/service/ActivityService.java
  14. 88
      src/main/java/com/share/help/service/UserService.java
  15. 40
      src/main/resources/mapping/UserMapper.xml
  16. 4
      src/test/java/com/share/help/HelpApplicationTests.java
  17. 2
      src/test/resources/clean.sql

@ -33,4 +33,12 @@ public class Constants {
//活动报名接口 //活动报名接口
public static final String ACTIVITY_INTERFACE_APPLY = "/apply"; public static final String ACTIVITY_INTERFACE_APPLY = "/apply";
//用户查询信息接口
public static final String USER_INTERFACE_FIND_ID = USER_INTERFACE_FIND+"/{userId}";
//用户信息更新接口
public static final String USER_INTERFACE_UPDATE = "/update";
//更新密码接口
public static final String USER_INTERFACE_PWD = "/updatePwd";
} }

@ -5,11 +5,10 @@ import com.share.help.entity.ActivityEntity;
import com.share.help.form.ApplyActivityForm; import com.share.help.form.ApplyActivityForm;
import com.share.help.form.FindActivityForm; import com.share.help.form.FindActivityForm;
import com.share.help.form.SendHelpForm; import com.share.help.form.SendHelpForm;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.SendHelpRes; import com.share.help.res.SendHelpRes;
import com.share.help.res.activity.ActivityDetailRes;
import com.share.help.res.activity.ApplyActivityRes;
import com.share.help.res.activity.FindActivityRes; import com.share.help.res.activity.FindActivityRes;
import com.share.help.service.ActivityService; import com.share.help.service.ActivityService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
@ -62,9 +61,9 @@ public class ActivityController {
* @return 返回活动列表 * @return 返回活动列表
*/ */
@GetMapping(Constants.ACTIVITY_INTERFACE_FIND_ID) @GetMapping(Constants.ACTIVITY_INTERFACE_FIND_ID)
public JSONResponse<ActivityDetailRes,ActivityEntity> find(@PathVariable Long activityId){ public JSONResponse<DefaultRes,ActivityEntity> find(@PathVariable Long activityId){
if(activityId==null){ if(activityId==null){
return new JSONResponse<>(ActivityDetailRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}else{ }else{
return activityService.find(activityId); return activityService.find(activityId);
} }
@ -75,12 +74,12 @@ public class ActivityController {
* @return 返回报名结果 * @return 返回报名结果
*/ */
@PostMapping(Constants.ACTIVITY_INTERFACE_APPLY) @PostMapping(Constants.ACTIVITY_INTERFACE_APPLY)
public JSONResponse<ApplyActivityRes,Void> apply(ApplyActivityForm activityForm,@CookieValue(Constants.USER_COOKIE) String userId){ public JSONResponse<DefaultRes,Void> apply(ApplyActivityForm activityForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(activityForm.getActivityId(),activityForm.getActivityStatus())){ if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(activityForm.getActivityId(),activityForm.getActivityStatus())){
activityForm.setUserId(userId); activityForm.setUserId(userId);
return activityService.apply(activityForm); return activityService.apply(activityForm);
}else{ }else{
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }
} }
} }

@ -1,14 +1,11 @@
package com.share.help.controller; package com.share.help.controller;
import com.share.help.Constants; import com.share.help.Constants;
import com.share.help.form.FindUserForm; import com.share.help.form.*;
import com.share.help.form.UserLoginForm; import com.share.help.res.DefaultRes;
import com.share.help.form.UserRegisterForm;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.FindUserRes; import com.share.help.res.account.*;
import com.share.help.res.account.LoginRes;
import com.share.help.res.account.RegisterRes;
import com.share.help.service.UserService; import com.share.help.service.UserService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -71,4 +68,50 @@ public class UserController {
return new JSONResponse<>(FindUserRes.Res.fail,Result.FAIL); return new JSONResponse<>(FindUserRes.Res.fail,Result.FAIL);
} }
} }
/**
* 获取用户信息
* @param userId 用户id
* @return 返回用户信息
*/
@GetMapping(Constants.USER_INTERFACE_FIND_ID)
public JSONResponse<DefaultRes, QueryRes> find(@PathVariable String userId){
if(userId!=null){
return userService.find(userId);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 更新用户信息
* @param updateUserForm 更新用户表单
* @param userId 用户id
* @return 返回更新结果
*/
@PostMapping(Constants.USER_INTERFACE_UPDATE)
public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(userId!=null){
updateUserForm.setUserId(userId);
return userService.update(updateUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 更新用户密码
* @param modifyPwdForm 更新密码表单
* @param userId 用户id
* @return 返回更新结果
*/
@PostMapping(Constants.USER_INTERFACE_PWD)
public JSONResponse<ModifyPwdRes,Void> update(ModifyPwdForm modifyPwdForm, @CookieValue(Constants.USER_COOKIE) String userId){
if(userId!=null){
modifyPwdForm.setUserId(userId);
return userService.update(modifyPwdForm);
}else{
return new JSONResponse<>(ModifyPwdRes.fail,Result.FAIL);
}
}
} }

@ -15,7 +15,10 @@ public interface UserMapper {
* 添加用户 * 添加用户
* @param user 用户信息 * @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})") @Insert("insert into user(user_id,password,name,sex,head_img,address,service_address,user_type,mobile," +
"email,info,time_score,chat_status,age)value(#{userId},#{password},#{name},#{sex}," +
"#{headImg},#{address},#{serviceAddress},#{userType},#{mobile},#{email},#{info}," +
"#{timeScore},#{chatStatus},#{age})")
boolean insert(UserEntity user); boolean insert(UserEntity user);
/** /**
@ -48,8 +51,7 @@ public interface UserMapper {
* *
* @return 返回更新结果 * @return 返回更新结果
*/ */
@Update("update user set password=#{password} where user_id=#{userId}") boolean update(UserEntity userEntity);
boolean updatePassword(@Param("userId") String userId, @Param("password") String password);
/** /**
* 根据用户id判断用户是否存在 * 根据用户id判断用户是否存在

@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.Objects; import java.util.Objects;
public class UserEntity { public class UserEntity {
private String userId; private String userId;
private String password; private String password;
@ -19,6 +18,7 @@ public class UserEntity {
private String info; private String info;
private Integer timeScore; private Integer timeScore;
private Boolean chatStatus; private Boolean chatStatus;
private Integer age;
private Collection<ActivityHistoryEntity> activityHistoriesByUserId; private Collection<ActivityHistoryEntity> activityHistoriesByUserId;
private Collection<ChatHistoryEntity> chatHistoriesByUserId; private Collection<ChatHistoryEntity> chatHistoriesByUserId;
private Collection<ChatHistoryEntity> chatHistoriesByUserId_0; private Collection<ChatHistoryEntity> chatHistoriesByUserId_0;
@ -157,6 +157,14 @@ public class UserEntity {
this.chatStatus = chatStatus; this.chatStatus = chatStatus;
} }
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -174,15 +182,22 @@ public class UserEntity {
Objects.equals(email, that.email) && Objects.equals(email, that.email) &&
Objects.equals(info, that.info) && Objects.equals(info, that.info) &&
Objects.equals(timeScore, that.timeScore) && Objects.equals(timeScore, that.timeScore) &&
Objects.equals(chatStatus, that.chatStatus); Objects.equals(chatStatus, that.chatStatus) &&
Objects.equals(age, that.age) &&
Objects.equals(activityHistoriesByUserId, that.activityHistoriesByUserId) &&
Objects.equals(chatHistoriesByUserId, that.chatHistoriesByUserId) &&
Objects.equals(chatHistoriesByUserId_0, that.chatHistoriesByUserId_0) &&
Objects.equals(friendsByUserId, that.friendsByUserId) &&
Objects.equals(friendsByUserId_0, that.friendsByUserId_0) &&
Objects.equals(leaveWordsByUserId, that.leaveWordsByUserId) &&
Objects.equals(leaveWordsByUserId_0, that.leaveWordsByUserId_0);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(userId, password, name, sex, headImg, address, serviceAddress, userType, mobile, email, info, timeScore, chatStatus); return Objects.hash(userId, password, name, sex, headImg, address, serviceAddress, userType, mobile, email, info, timeScore, chatStatus, age, activityHistoriesByUserId, chatHistoriesByUserId, chatHistoriesByUserId_0, friendsByUserId, friendsByUserId_0, leaveWordsByUserId, leaveWordsByUserId_0);
} }
public Collection<ActivityHistoryEntity> getActivityHistoriesByUserId() { public Collection<ActivityHistoryEntity> getActivityHistoriesByUserId() {
return activityHistoriesByUserId; return activityHistoriesByUserId;
} }

@ -0,0 +1,32 @@
package com.share.help.form;
public class ModifyPwdForm {
private String userId;
private String oldPassword;
private String newPassword;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getOldPassword() {
return oldPassword;
}
public void setOldPassword(String oldPassword) {
this.oldPassword = oldPassword;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
}

@ -0,0 +1,103 @@
package com.share.help.form;
public class UpdateUserForm {
private String userId;
private String name;
private String headImg;
private String address;
private String serviceAddress;
private String userType;
private Long mobile;
private String email;
private String info;
private Integer age;
private String sex;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
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 getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}

@ -0,0 +1,6 @@
package com.share.help.res;
public enum DefaultRes {
ok,
fail
}

@ -0,0 +1,7 @@
package com.share.help.res.account;
public enum ModifyPwdRes {
ok,
pwd_fail,
fail
}

@ -0,0 +1,103 @@
package com.share.help.res.account;
public class QueryRes {
private String userId;
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 age;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
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 getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}

@ -1,9 +0,0 @@
package com.share.help.res.activity;
/**
* 活动详情响应
*/
public enum ActivityDetailRes{
ok,
fail
}

@ -1,9 +0,0 @@
package com.share.help.res.activity;
/**
* 报名活动操作反馈
*/
public enum ApplyActivityRes {
ok,
fail
}

@ -11,12 +11,11 @@ import com.share.help.form.ApplyActivityForm;
import com.share.help.form.FindActivityForm; import com.share.help.form.FindActivityForm;
import com.share.help.form.LeaveWordType; import com.share.help.form.LeaveWordType;
import com.share.help.form.SendHelpForm; import com.share.help.form.SendHelpForm;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.SendHelpRes; import com.share.help.res.SendHelpRes;
import com.share.help.res.activity.ActivityDetailRes;
import com.share.help.res.activity.ActivitySimple; import com.share.help.res.activity.ActivitySimple;
import com.share.help.res.activity.ApplyActivityRes;
import com.share.help.res.activity.FindActivityRes; import com.share.help.res.activity.FindActivityRes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -103,12 +102,12 @@ public class ActivityService{
* @param activityId 活动id * @param activityId 活动id
* @return 返回活动详情信息 * @return 返回活动详情信息
*/ */
public JSONResponse<ActivityDetailRes,ActivityEntity> find(Long activityId){ public JSONResponse<DefaultRes,ActivityEntity> find(Long activityId){
ActivityEntity activityEntity=activityMapper.findOne(activityId); ActivityEntity activityEntity=activityMapper.findOne(activityId);
if(activityEntity==null){ if(activityEntity==null){
return new JSONResponse<>(ActivityDetailRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}else{ }else{
return new JSONResponse<ActivityDetailRes,ActivityEntity>(ActivityDetailRes.ok,Result.OK).setBody(activityEntity); return new JSONResponse<DefaultRes,ActivityEntity>(DefaultRes.ok,Result.OK).setBody(activityEntity);
} }
} }
@ -118,7 +117,7 @@ public class ActivityService{
* @return 返回报名结果 * @return 返回报名结果
*/ */
@Transactional @Transactional
public JSONResponse<ApplyActivityRes,Void> apply(ApplyActivityForm activityForm){ public JSONResponse<DefaultRes,Void> apply(ApplyActivityForm activityForm){
// 保存到活动历史记录 // 保存到活动历史记录
ActivityHistoryEntity activityEntity=new ActivityHistoryEntity(); ActivityHistoryEntity activityEntity=new ActivityHistoryEntity();
activityEntity.setActivityId(activityForm.getActivityId()); activityEntity.setActivityId(activityForm.getActivityId());
@ -127,7 +126,7 @@ public class ActivityService{
activityEntity.setActivityStatus(activityForm.getActivityStatus().name()); activityEntity.setActivityStatus(activityForm.getActivityStatus().name());
if(!activityHistoryMapper.insert(activityEntity)){ if(!activityHistoryMapper.insert(activityEntity)){
logger.error("保存活动历史记录失败"); logger.error("保存活动历史记录失败");
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }
// 给求助用户发送留言 // 给求助用户发送留言
@ -137,16 +136,16 @@ public class ActivityService{
ActivityEntity activity=activityMapper.findOne(activityForm.getActivityId()); ActivityEntity activity=activityMapper.findOne(activityForm.getActivityId());
if(activity==null){ if(activity==null){
logger.error("查询活动记录失败"); logger.error("查询活动记录失败");
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }
leaveWordEntity.setTargetUserId(activity.getUserId()); leaveWordEntity.setTargetUserId(activity.getUserId());
leaveWordEntity.setActivityId(activityForm.getActivityId()); leaveWordEntity.setActivityId(activityForm.getActivityId());
leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis())); leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
if(!leaveWordMapper.insert(leaveWordEntity)){ if(!leaveWordMapper.insert(leaveWordEntity)){
logger.error("保存留言信息失败"); logger.error("保存留言信息失败");
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }
return new JSONResponse<>(ApplyActivityRes.ok,Result.OK); return new JSONResponse<>(DefaultRes.ok,Result.OK);
} }
} }

@ -3,14 +3,11 @@ package com.share.help.service;
import com.share.help.Util; import com.share.help.Util;
import com.share.help.dao.UserMapper; import com.share.help.dao.UserMapper;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.form.FindUserForm; import com.share.help.form.*;
import com.share.help.form.UserLoginForm; import com.share.help.res.DefaultRes;
import com.share.help.form.UserRegisterForm;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.FindUserRes; import com.share.help.res.account.*;
import com.share.help.res.account.LoginRes;
import com.share.help.res.account.RegisterRes;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -57,6 +54,7 @@ public class UserService{
String newPassword=DigestUtils.md5DigestAsHex(userRegisterForm.getPassword().getBytes()); String newPassword=DigestUtils.md5DigestAsHex(userRegisterForm.getPassword().getBytes());
userEntity.setPassword(newPassword); userEntity.setPassword(newPassword);
userEntity.setName(userRegisterForm.getName()); userEntity.setName(userRegisterForm.getName());
userEntity.setAge(userRegisterForm.getAge());
userEntity.setSex(userRegisterForm.getSex()); userEntity.setSex(userRegisterForm.getSex());
//保存头像 //保存头像
String imageName=imageService.saveImg(userRegisterForm.getImgFile()); String imageName=imageService.saveImg(userRegisterForm.getImgFile());
@ -87,6 +85,11 @@ public class UserService{
:new JSONResponse<LoginRes.Res,LoginRes>(LoginRes.Res.ok,Result.OK).setBody(new LoginRes(userEntity)); :new JSONResponse<LoginRes.Res,LoginRes>(LoginRes.Res.ok,Result.OK).setBody(new LoginRes(userEntity));
} }
/**
* 获取志愿者信息
* @param findUserForm 搜索条件表单
* @return 返回志愿者列表
*/
public JSONResponse<FindUserRes.Res,FindUserRes> find(FindUserForm findUserForm){ public JSONResponse<FindUserRes.Res,FindUserRes> find(FindUserForm findUserForm){
FindUserRes findUserRes=userMapper.count(pageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress()); FindUserRes findUserRes=userMapper.count(pageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress());
findUserRes.setPageSize(pageSize); findUserRes.setPageSize(pageSize);
@ -100,4 +103,77 @@ public class UserService{
return new JSONResponse<>(FindUserRes.Res.empty, Result.FAIL); return new JSONResponse<>(FindUserRes.Res.empty, Result.FAIL);
} }
} }
/**
* 获取用户个人信息
* @param userId 用户id
* @return 返回用户信息
*/
public JSONResponse<DefaultRes, QueryRes> find(String userId){
UserEntity userEntity= userMapper.findOne(userId);
if(userEntity!=null){
QueryRes queryRes=new QueryRes();
queryRes.setUserId(userEntity.getUserId());
queryRes.setHeadImg(userEntity.getHeadImg());
queryRes.setName(userEntity.getName());
queryRes.setAge(userEntity.getAge());
queryRes.setMobile(userEntity.getMobile());
queryRes.setEmail(userEntity.getEmail());
queryRes.setServiceAddress(userEntity.getServiceAddress());
queryRes.setInfo(userEntity.getInfo());
queryRes.setUserType(userEntity.getUserType());
queryRes.setSex(userEntity.getSex());
return new JSONResponse<DefaultRes, QueryRes>(DefaultRes.ok,Result.OK).setBody(queryRes);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 更新用户信息
* @param updateUserForm 用户id
* @return 返回更新结果
*/
public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm){
UserEntity userEntity=new UserEntity();
userEntity.setUserId(updateUserForm.getUserId());
userEntity.setName(updateUserForm.getName());
userEntity.setHeadImg(updateUserForm.getHeadImg());
userEntity.setAddress(updateUserForm.getAddress());
userEntity.setServiceAddress(updateUserForm.getServiceAddress());
userEntity.setUserType(updateUserForm.getUserType());
userEntity.setMobile(updateUserForm.getMobile());
userEntity.setEmail(updateUserForm.getEmail());
userEntity.setInfo(updateUserForm.getInfo());
userEntity.setAge(updateUserForm.getAge());
userEntity.setSex(updateUserForm.getSex());
if(userMapper.update(userEntity)){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 更新用户密码
* @param modifyPwdForm 更新密码表单
* @return 返回更新结果
*/
public JSONResponse<ModifyPwdRes,Void> update(ModifyPwdForm modifyPwdForm){
UserEntity userEntity=userMapper.findOne(modifyPwdForm.getUserId());
if(userEntity==null){
return new JSONResponse<>(ModifyPwdRes.fail,Result.FAIL);
}
if(DigestUtils.md5DigestAsHex(modifyPwdForm.getOldPassword().getBytes()).equals(userEntity.getPassword())){
userEntity.setPassword(DigestUtils.md5DigestAsHex(modifyPwdForm.getNewPassword().getBytes()));
if(userMapper.update(userEntity)){
return new JSONResponse<>(ModifyPwdRes.ok,Result.OK);
}else{
return new JSONResponse<>(ModifyPwdRes.fail,Result.FAIL);
}
}else{
return new JSONResponse<>(ModifyPwdRes.pwd_fail,Result.FAIL);
}
}
} }

@ -12,4 +12,44 @@
<result property="timeScore" column="time_score"/> <result property="timeScore" column="time_score"/>
<result property="chatStatus" column="chat_status"/> <result property="chatStatus" column="chat_status"/>
</resultMap> </resultMap>
<update id="update">
update user
<set>
<if test="name!=null and name!=''">
name=#{name},
</if>
<if test="headImg!=null and headImg!=''">
head_img=#{headImg},
</if>
<if test="address!=null and address!=''">
address=#{address},
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
service_address=#{serviceAddress},
</if>
<if test="userType!=null and userType!=''">
user_type=#{userType},
</if>
<if test="mobile!=null">
mobile=#{mobile},
</if>
<if test="email!=null and email!=''">
email=#{email},
</if>
<if test="info!=null and info!=''">
info=#{info},
</if>
<if test="age!=null">
age=#{age},
</if>
<if test="sex!=null and sex!=''">
sex=#{sex},
</if>
<if test="password!=null and password!=''">
password=#{password}
</if>
</set>
where user_id=#{userId}
</update>
</mapper> </mapper>

@ -82,7 +82,7 @@ class HelpApplicationTests {
userEntity.setInfo("自我介绍"); userEntity.setInfo("自我介绍");
userEntity.setTimeScore(0); userEntity.setTimeScore(0);
userEntity.setChatStatus(true); userEntity.setChatStatus(true);
userEntity.setAge(12);
userMapper.insert(userEntity); userMapper.insert(userEntity);
@ -94,7 +94,7 @@ class HelpApplicationTests {
userEntity.setPassword(newPassword); userEntity.setPassword(newPassword);
Assertions.assertTrue(userMapper.updatePassword(userId,newPassword),"更新成功"); Assertions.assertTrue(userMapper.update(userEntity),"更新成功");
userEntity=userMapper.findOne(userId); userEntity=userMapper.findOne(userId);

@ -0,0 +1,2 @@
delete from activity;
delete from user;
Loading…
Cancel
Save