From 59194d7e76f0a19293fba5f816cd3ad327e2a4d4 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Thu, 28 May 2020 05:23:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=201.?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BF=AE=E6=94=B9=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=202.=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/share/help/Constants.java | 8 ++ .../help/controller/ActivityController.java | 11 +- .../share/help/controller/UserController.java | 55 +++++++++- .../java/com/share/help/dao/UserMapper.java | 8 +- .../com/share/help/entity/UserEntity.java | 23 +++- .../com/share/help/form/ModifyPwdForm.java | 32 ++++++ .../com/share/help/form/UpdateUserForm.java | 103 ++++++++++++++++++ .../java/com/share/help/res/DefaultRes.java | 6 + .../share/help/res/account/ModifyPwdRes.java | 7 ++ .../com/share/help/res/account/QueryRes.java | 103 ++++++++++++++++++ .../help/res/activity/ActivityDetailRes.java | 9 -- .../help/res/activity/ApplyActivityRes.java | 9 -- .../share/help/service/ActivityService.java | 19 ++-- .../com/share/help/service/UserService.java | 88 ++++++++++++++- src/main/resources/mapping/UserMapper.xml | 40 +++++++ .../com/share/help/HelpApplicationTests.java | 4 +- src/test/resources/clean.sql | 2 + 17 files changed, 472 insertions(+), 55 deletions(-) create mode 100644 src/main/java/com/share/help/form/ModifyPwdForm.java create mode 100644 src/main/java/com/share/help/form/UpdateUserForm.java create mode 100644 src/main/java/com/share/help/res/DefaultRes.java create mode 100644 src/main/java/com/share/help/res/account/ModifyPwdRes.java create mode 100644 src/main/java/com/share/help/res/account/QueryRes.java delete mode 100644 src/main/java/com/share/help/res/activity/ActivityDetailRes.java delete mode 100644 src/main/java/com/share/help/res/activity/ApplyActivityRes.java create mode 100644 src/test/resources/clean.sql diff --git a/src/main/java/com/share/help/Constants.java b/src/main/java/com/share/help/Constants.java index 4904b65..ac7625f 100644 --- a/src/main/java/com/share/help/Constants.java +++ b/src/main/java/com/share/help/Constants.java @@ -33,4 +33,12 @@ public class Constants { //活动报名接口 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"; } diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index 8de3bdc..db4151a 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.java @@ -5,11 +5,10 @@ import com.share.help.entity.ActivityEntity; import com.share.help.form.ApplyActivityForm; import com.share.help.form.FindActivityForm; import com.share.help.form.SendHelpForm; +import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; 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.service.ActivityService; import org.apache.commons.lang3.ObjectUtils; @@ -62,9 +61,9 @@ public class ActivityController { * @return 返回活动列表 */ @GetMapping(Constants.ACTIVITY_INTERFACE_FIND_ID) - public JSONResponse find(@PathVariable Long activityId){ + public JSONResponse find(@PathVariable Long activityId){ if(activityId==null){ - return new JSONResponse<>(ActivityDetailRes.fail,Result.FAIL); + return new JSONResponse<>(DefaultRes.fail,Result.FAIL); }else{ return activityService.find(activityId); } @@ -75,12 +74,12 @@ public class ActivityController { * @return 返回报名结果 */ @PostMapping(Constants.ACTIVITY_INTERFACE_APPLY) - public JSONResponse apply(ApplyActivityForm activityForm,@CookieValue(Constants.USER_COOKIE) String userId){ + public JSONResponse apply(ApplyActivityForm activityForm,@CookieValue(Constants.USER_COOKIE) String userId){ if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(activityForm.getActivityId(),activityForm.getActivityStatus())){ activityForm.setUserId(userId); return activityService.apply(activityForm); }else{ - return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); + return new JSONResponse<>(DefaultRes.fail,Result.FAIL); } } } diff --git a/src/main/java/com/share/help/controller/UserController.java b/src/main/java/com/share/help/controller/UserController.java index 4ca6ed5..5545677 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -1,14 +1,11 @@ package com.share.help.controller; import com.share.help.Constants; -import com.share.help.form.FindUserForm; -import com.share.help.form.UserLoginForm; -import com.share.help.form.UserRegisterForm; +import com.share.help.form.*; +import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; -import com.share.help.res.account.FindUserRes; -import com.share.help.res.account.LoginRes; -import com.share.help.res.account.RegisterRes; +import com.share.help.res.account.*; import com.share.help.service.UserService; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -71,4 +68,50 @@ public class UserController { return new JSONResponse<>(FindUserRes.Res.fail,Result.FAIL); } } + + /** + * 获取用户信息 + * @param userId 用户id + * @return 返回用户信息 + */ + @GetMapping(Constants.USER_INTERFACE_FIND_ID) + public JSONResponse 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 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 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); + } + } } diff --git a/src/main/java/com/share/help/dao/UserMapper.java b/src/main/java/com/share/help/dao/UserMapper.java index 3aff563..be9463e 100644 --- a/src/main/java/com/share/help/dao/UserMapper.java +++ b/src/main/java/com/share/help/dao/UserMapper.java @@ -15,7 +15,10 @@ 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})") + @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); /** @@ -48,8 +51,7 @@ public interface UserMapper { * * @return 返回更新结果 */ - @Update("update user set password=#{password} where user_id=#{userId}") - boolean updatePassword(@Param("userId") String userId, @Param("password") String password); + boolean update(UserEntity userEntity); /** * 根据用户id判断用户是否存在 diff --git a/src/main/java/com/share/help/entity/UserEntity.java b/src/main/java/com/share/help/entity/UserEntity.java index 0f641ba..1577d6d 100644 --- a/src/main/java/com/share/help/entity/UserEntity.java +++ b/src/main/java/com/share/help/entity/UserEntity.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Objects; - public class UserEntity { private String userId; private String password; @@ -19,6 +18,7 @@ public class UserEntity { private String info; private Integer timeScore; private Boolean chatStatus; + private Integer age; private Collection activityHistoriesByUserId; private Collection chatHistoriesByUserId; private Collection chatHistoriesByUserId_0; @@ -157,6 +157,14 @@ public class UserEntity { this.chatStatus = chatStatus; } + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -174,15 +182,22 @@ public class UserEntity { Objects.equals(email, that.email) && Objects.equals(info, that.info) && 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 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 getActivityHistoriesByUserId() { return activityHistoriesByUserId; } diff --git a/src/main/java/com/share/help/form/ModifyPwdForm.java b/src/main/java/com/share/help/form/ModifyPwdForm.java new file mode 100644 index 0000000..dfbbcf3 --- /dev/null +++ b/src/main/java/com/share/help/form/ModifyPwdForm.java @@ -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; + } +} + diff --git a/src/main/java/com/share/help/form/UpdateUserForm.java b/src/main/java/com/share/help/form/UpdateUserForm.java new file mode 100644 index 0000000..c9ce997 --- /dev/null +++ b/src/main/java/com/share/help/form/UpdateUserForm.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/res/DefaultRes.java b/src/main/java/com/share/help/res/DefaultRes.java new file mode 100644 index 0000000..622ba80 --- /dev/null +++ b/src/main/java/com/share/help/res/DefaultRes.java @@ -0,0 +1,6 @@ +package com.share.help.res; + +public enum DefaultRes { + ok, + fail +} diff --git a/src/main/java/com/share/help/res/account/ModifyPwdRes.java b/src/main/java/com/share/help/res/account/ModifyPwdRes.java new file mode 100644 index 0000000..8d15e54 --- /dev/null +++ b/src/main/java/com/share/help/res/account/ModifyPwdRes.java @@ -0,0 +1,7 @@ +package com.share.help.res.account; + +public enum ModifyPwdRes { + ok, + pwd_fail, + fail +} diff --git a/src/main/java/com/share/help/res/account/QueryRes.java b/src/main/java/com/share/help/res/account/QueryRes.java new file mode 100644 index 0000000..a85591a --- /dev/null +++ b/src/main/java/com/share/help/res/account/QueryRes.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/res/activity/ActivityDetailRes.java b/src/main/java/com/share/help/res/activity/ActivityDetailRes.java deleted file mode 100644 index aa66e72..0000000 --- a/src/main/java/com/share/help/res/activity/ActivityDetailRes.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.share.help.res.activity; - -/** - * 活动详情响应 - */ -public enum ActivityDetailRes{ - ok, - fail -} diff --git a/src/main/java/com/share/help/res/activity/ApplyActivityRes.java b/src/main/java/com/share/help/res/activity/ApplyActivityRes.java deleted file mode 100644 index 20d80f1..0000000 --- a/src/main/java/com/share/help/res/activity/ApplyActivityRes.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.share.help.res.activity; - -/** - * 报名活动操作反馈 - */ -public enum ApplyActivityRes { - ok, - fail -} diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index a082636..c2fc3a6 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -11,12 +11,11 @@ import com.share.help.form.ApplyActivityForm; import com.share.help.form.FindActivityForm; import com.share.help.form.LeaveWordType; import com.share.help.form.SendHelpForm; +import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; 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.ApplyActivityRes; import com.share.help.res.activity.FindActivityRes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,12 +102,12 @@ public class ActivityService{ * @param activityId 活动id * @return 返回活动详情信息 */ - public JSONResponse find(Long activityId){ + public JSONResponse find(Long activityId){ ActivityEntity activityEntity=activityMapper.findOne(activityId); if(activityEntity==null){ - return new JSONResponse<>(ActivityDetailRes.fail,Result.FAIL); + return new JSONResponse<>(DefaultRes.fail,Result.FAIL); }else{ - return new JSONResponse(ActivityDetailRes.ok,Result.OK).setBody(activityEntity); + return new JSONResponse(DefaultRes.ok,Result.OK).setBody(activityEntity); } } @@ -118,7 +117,7 @@ public class ActivityService{ * @return 返回报名结果 */ @Transactional - public JSONResponse apply(ApplyActivityForm activityForm){ + public JSONResponse apply(ApplyActivityForm activityForm){ // 保存到活动历史记录 ActivityHistoryEntity activityEntity=new ActivityHistoryEntity(); activityEntity.setActivityId(activityForm.getActivityId()); @@ -127,7 +126,7 @@ public class ActivityService{ activityEntity.setActivityStatus(activityForm.getActivityStatus().name()); if(!activityHistoryMapper.insert(activityEntity)){ 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()); if(activity==null){ logger.error("查询活动记录失败"); - return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL); + return new JSONResponse<>(DefaultRes.fail,Result.FAIL); } leaveWordEntity.setTargetUserId(activity.getUserId()); leaveWordEntity.setActivityId(activityForm.getActivityId()); leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis())); if(!leaveWordMapper.insert(leaveWordEntity)){ 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); } } diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index e9fef1d..bdba854 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -3,14 +3,11 @@ package com.share.help.service; import com.share.help.Util; import com.share.help.dao.UserMapper; import com.share.help.entity.UserEntity; -import com.share.help.form.FindUserForm; -import com.share.help.form.UserLoginForm; -import com.share.help.form.UserRegisterForm; +import com.share.help.form.*; +import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; -import com.share.help.res.account.FindUserRes; -import com.share.help.res.account.LoginRes; -import com.share.help.res.account.RegisterRes; +import com.share.help.res.account.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -57,6 +54,7 @@ public class UserService{ String newPassword=DigestUtils.md5DigestAsHex(userRegisterForm.getPassword().getBytes()); userEntity.setPassword(newPassword); userEntity.setName(userRegisterForm.getName()); + userEntity.setAge(userRegisterForm.getAge()); userEntity.setSex(userRegisterForm.getSex()); //保存头像 String imageName=imageService.saveImg(userRegisterForm.getImgFile()); @@ -87,6 +85,11 @@ public class UserService{ :new JSONResponse(LoginRes.Res.ok,Result.OK).setBody(new LoginRes(userEntity)); } + /** + * 获取志愿者信息 + * @param findUserForm 搜索条件表单 + * @return 返回志愿者列表 + */ public JSONResponse find(FindUserForm findUserForm){ FindUserRes findUserRes=userMapper.count(pageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress()); findUserRes.setPageSize(pageSize); @@ -100,4 +103,77 @@ public class UserService{ return new JSONResponse<>(FindUserRes.Res.empty, Result.FAIL); } } + + /** + * 获取用户个人信息 + * @param userId 用户id + * @return 返回用户信息 + */ + public JSONResponse 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.ok,Result.OK).setBody(queryRes); + }else{ + return new JSONResponse<>(DefaultRes.fail,Result.FAIL); + } + } + + /** + * 更新用户信息 + * @param updateUserForm 用户id + * @return 返回更新结果 + */ + public JSONResponse 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 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); + } + } } diff --git a/src/main/resources/mapping/UserMapper.xml b/src/main/resources/mapping/UserMapper.xml index 247200a..2256263 100644 --- a/src/main/resources/mapping/UserMapper.xml +++ b/src/main/resources/mapping/UserMapper.xml @@ -12,4 +12,44 @@ + + + update user + + + name=#{name}, + + + head_img=#{headImg}, + + + address=#{address}, + + + service_address=#{serviceAddress}, + + + user_type=#{userType}, + + + mobile=#{mobile}, + + + email=#{email}, + + + info=#{info}, + + + age=#{age}, + + + sex=#{sex}, + + + password=#{password} + + + where user_id=#{userId} + \ No newline at end of file diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index e2e7e74..27c9b63 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -82,7 +82,7 @@ class HelpApplicationTests { userEntity.setInfo("自我介绍"); userEntity.setTimeScore(0); userEntity.setChatStatus(true); - + userEntity.setAge(12); userMapper.insert(userEntity); @@ -94,7 +94,7 @@ class HelpApplicationTests { userEntity.setPassword(newPassword); - Assertions.assertTrue(userMapper.updatePassword(userId,newPassword),"更新成功"); + Assertions.assertTrue(userMapper.update(userEntity),"更新成功"); userEntity=userMapper.findOne(userId); diff --git a/src/test/resources/clean.sql b/src/test/resources/clean.sql new file mode 100644 index 0000000..3fd0108 --- /dev/null +++ b/src/test/resources/clean.sql @@ -0,0 +1,2 @@ +delete from activity; +delete from user; \ No newline at end of file