1.update post @RequestParam to @RequestBody

main
Gary 10 months ago
parent e94411c6d8
commit e4a6d6ba56

@ -18,6 +18,7 @@ import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -27,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
import constants.Constants; import constants.Constants;
import controller.BaseController; import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.S3Service; import com.luoo.user.service.S3Service;
@ -116,20 +118,13 @@ public class MyController extends BaseController{
} }
@ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息") @ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "nickName", value = "昵称最多12个字符", required = false),
@ApiImplicitParam(name = "signature", value = "签名最多50个字符", required = false),
@ApiImplicitParam(name = "birthDay", value = "生日,格式为: yyyy.MM.dd", required = false),
@ApiImplicitParam(name = "sex", value = "性别4个值0为男1 为女2为保密不填为空", required = false) })
@PostMapping("/updateUserInfo") @PostMapping("/updateUserInfo")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> updateUserInfo(@RequestHeader(value = "token", required = false) String token, public Result<Void> updateUserInfo(@RequestHeader(value = "token", required = false) String token,
@VerifyParam(max = 12) @RequestParam("nickName") String nickName, @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) {
@VerifyParam(max = 50) @RequestParam("signature") String signature,
@RequestParam("birthDay") String birthDay,
@RequestParam("sex") Integer sex) {
UserLoginDto userLoginDto = getUserLoginDto(token); UserLoginDto userLoginDto = getUserLoginDto(token);
UserInfo user = userInfoService.findById(userLoginDto.getUserId()); UserInfo user = userInfoService.findById(userLoginDto.getUserId());
String nickName=userInfoUpdateDto.getNickName();
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) { if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) {
long count = userInfoService.countByNickName(nickName); long count = userInfoService.countByNickName(nickName);
if (count > 0) { if (count > 0) {
@ -140,14 +135,14 @@ public class MyController extends BaseController{
if (!StringTools.isEmpty(nickName)) { if (!StringTools.isEmpty(nickName)) {
user.setNickName(nickName); user.setNickName(nickName);
} }
if (!StringTools.isEmpty(signature)) { if (!StringTools.isEmpty(userInfoUpdateDto.getSignature())) {
user.setSignature(signature); user.setSignature(userInfoUpdateDto.getSignature());
} }
if (!StringTools.isEmpty(birthDay)) { if (!StringTools.isEmpty(userInfoUpdateDto.getBirthDay())) {
user.setBirthday(DateUtil.parse(birthDay, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); user.setBirthday(DateUtil.parse(userInfoUpdateDto.getBirthDay(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
} }
if (null!=sex) { if (null!=userInfoUpdateDto.getSex()) {
user.setSex(sex); user.setSex(userInfoUpdateDto.getSex());
} }
user.setModifyTime(new Date()); user.setModifyTime(new Date());
userInfoService.update(user); userInfoService.update(user);

@ -0,0 +1,19 @@
package com.luoo.user.dto;
import annotation.VerifyParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class UserInfoUpdateDto {
@VerifyParam(max = 12)
@ApiModelProperty(value = "昵称最多12个字符", example = "雀乐-蓉江晨玥^沙顺芊润")
private String nickName;
@ApiModelProperty(value = "性别4个值0为男1 为女2为保密不填为空", example = "0")
private Integer sex;
@ApiModelProperty(value = "签名最多50个字符")
@VerifyParam(max = 50)
private String signature;
@ApiModelProperty(value = "生日,格式为: yyyy.MM.dd")
private String birthDay;
}
Loading…
Cancel
Save