Commit 7b606d22 by 段启岩

记得加注释,传值太多记得封装

parent 49a8fc46
......@@ -6,11 +6,13 @@ import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.bean.Subject;
import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException;
import cn.meteor.beyondclouds.modules.user.form.UserBaseinfoFrom;
import cn.meteor.beyondclouds.modules.user.form.UserBaseInfoFrom;
import cn.meteor.beyondclouds.modules.user.form.UserRegisterFrom;
import cn.meteor.beyondclouds.modules.user.service.IUserService;
import cn.meteor.beyondclouds.modules.user.vo.UserInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
......@@ -53,14 +55,19 @@ public class UserApi {
@ApiOperation("修改我的基本信息")
@PutMapping("/my/baseinfo")
public Response alterBaseinfo(@RequestBody @Valid UserBaseinfoFrom userBaseinfoFrom, BindingResult result,
public Response alterBaseInfo(@RequestBody @Valid UserBaseInfoFrom userBaseinfoFrom, BindingResult result,
@CurrentSubject Subject subject){
if (result.hasErrors()) {
return Response.fieldError(result.getFieldError());
}
userService.alterBaseinfo(userBaseinfoFrom.getNickName(),userBaseinfoFrom.getUserAvatar(),
userBaseinfoFrom.getGender(),userBaseinfoFrom.getMobile(),userBaseinfoFrom.getSignature(),
userBaseinfoFrom.getQqNumber(),userBaseinfoFrom.getWxNumber(), String.valueOf(subject.getId()));
// 将form转换为user对象
User user = new User();
BeanUtils.copyProperties(userBaseinfoFrom, user);
// 修改基本信息
user.setUserId(user.getUserId());
Please register or sign in to reply
userService.alterBaseInfo(user);
return Response.success();
}
......@@ -84,18 +91,35 @@ public class UserApi {
@ApiOperation(("获取我的基本信息"))
@GetMapping("/my/baseinfo")
public Response myBaseinfo(@CurrentSubject Subject subject){
return Response.success(userService.myBaseinfo(String.valueOf(subject.getId())));
public Response myBaseInfo(@CurrentSubject Subject subject){
// 获取用户信息
User user = userService.getById(subject.getId());
UserInfoVO userInfoVO = new UserInfoVO();
BeanUtils.copyProperties(user, userInfoVO);
// 返回结果
return Response.success(userInfoVO);
}
@Anonymous
@ApiOperation(("获取他人基本信息"))
@GetMapping("/user/{userId}/baseinfo")
public Response otherBaseinfo(@PathVariable(name = "userId") String userId ){
return Response.success(userService.otherBaseinfo(userId));
public Response<UserInfoVO> updateOtherBaseInfo(@PathVariable(name = "userId") String userId ){
}
// 获取用户信息
User user = userService.getById(userId);
UserInfoVO userInfoVO = new UserInfoVO();
BeanUtils.copyProperties(user, userInfoVO);
// 去掉敏感信息
userInfoVO.setMobile(null);
userInfoVO.setWxNumber(null);
userInfoVO.setQqNumber(null);
// 返回结果
return Response.success(userInfoVO);
}
}
......@@ -54,5 +54,4 @@ public class User implements Serializable {
private LocalDateTime updateTime;
}
......@@ -12,7 +12,7 @@ import lombok.Data;
**/
@Data
@ApiModel("用户信息表")
public class UserBaseinfoFrom {
public class UserBaseInfoFrom {
private String nickName;
private String userAvatar;
......
......@@ -35,11 +35,19 @@ public interface IUserService extends IService<User> {
*/
void updateNickName(String userId, String nickName);
void alterBaseinfo(String nickName, String userAvatar, Integer gender, String mobile, String signature, String qqNumber, String wxNumber, String id);
/**
* 修改用户基本信息
* @param user
*/
void alterBaseInfo(User user);
/**
* 修改密码
* @param mobile
* @param password
* @param verifyCode
* @throws UserServiceException
*/
void alterPassword(String mobile, String password, String verifyCode) throws UserServiceException;
User myBaseinfo(String id);
User otherBaseinfo(String nickName);
}
......@@ -89,17 +89,8 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
}
@Override
public void alterBaseinfo(String nickName, String userAvatar, Integer gender, String mobile, String signature, String qqNumber, String wxNumber, String id) {
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("user_id",id);
updateWrapper.set("nick_name", nickName);
updateWrapper.set("user_avatar", userAvatar);
updateWrapper.set("gender", gender);
updateWrapper.set("signature", signature);
updateWrapper.set("mobile", mobile);
updateWrapper.set("wx_number", wxNumber);
updateWrapper.set("qq_number", qqNumber);
update(updateWrapper);
public void alterBaseInfo(User user) {
updateById(user);
}
@Override
......@@ -119,23 +110,4 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
userAuthLocalService.update(updateWrapper);
}
@Override
public User myBaseinfo(String userId) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
System.out.println(userId);
return getOne(queryWrapper);
}
@Override
public User otherBaseinfo(String userId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
return getOne(queryWrapper);
}
}
package cn.meteor.beyondclouds.modules.user.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 用户信息
* @author 段启岩
*/
@Data
public class UserInfoVO {
@ApiModelProperty(value = "用户昵称")
private String nickName;
@ApiModelProperty(value = "用户头像")
private String userAvatar;
@ApiModelProperty(value = "性别")
private Integer gender;
@ApiModelProperty(value = "个性签名")
private String signature;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty(value = "手机号")
private String mobile;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty(value = "微信号")
private String wxNumber;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty(value = "QQ号")
private String qqNumber;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment