1.fix issue of getUserInfo interface

main
Gary 10 months ago
parent 11c593e243
commit 0fdbf0e1e4

@ -97,7 +97,7 @@ public class AdminController {
@ApiOperation(value = "通过Admin用户ids批量查询Admin用户名称")
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "多个id以','分隔", required = true) })
@GetMapping("/ids/{id}")
@GetMapping("/ids/{ids}")
@GlobalInterceptor(checkAdminLogin=true)
public Result<List<Admin>> findAllById(@PathVariable @VerifyParam(required=true) String ids){
List<String> idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList());

@ -134,10 +134,10 @@ public class LoginController extends BaseController{
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiImplicitParams({
@ApiImplicitParam(name = "deviceId", value = "设备id最长32位", required = true)})
@GetMapping("/imageCheckCode")
@GetMapping("/imageCheckCode/{deviceId}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@VerifyParam(required = true, max = 32) @RequestParam("deviceId") String deviceId)
@VerifyParam(required = true, max = 32) @PathVariable("deviceId") String deviceId)
throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache");

@ -5,6 +5,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Date;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,10 +21,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import constants.Constants;
import controller.BaseController;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.User;
import com.luoo.user.service.UserService;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.UserInfoService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
@ -35,7 +38,6 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import util.DateUtil;
import util.JwtUtil;
import util.ScaleFilter;
import util.StringTools;
@ -43,11 +45,9 @@ import util.StringTools;
@CrossOrigin
@RequestMapping("/my")
@Api(tags = "MyController")
public class MyController {
@Autowired
private JwtUtil jwtUtil;
public class MyController extends BaseController{
@Autowired
private UserService userService;
private UserInfoService userInfoService;
public static String UPLOAD_DIRECTORY = System.getProperty("user.dir") + File.separator+"luoo_uploads"+File.separator;
@ -55,22 +55,17 @@ public class MyController {
@GetMapping("/getUserInfo")
@GlobalInterceptor
public Result getUserInfo(@RequestHeader(value = "token", required = false) String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
UserLoginDto userLoginDto = getUserLoginDto(token);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
UserRespDTO userRespDTO = new UserRespDTO();
if (Constants.TOKEN_ROLE_APP_USER.equals(userLoginDto.getRoles())) {
User user = userService.findById(userLoginDto.getUserId());
BeanUtils.copyProperties(user, userRespDTO);
} else {
userRespDTO.setNickname(userLoginDto.getNickName());
userRespDTO.setId(userLoginDto.getUserId());
}
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
BeanUtils.copyProperties(user, userRespDTO);
return Result.success(userRespDTO);
}
@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),
@ -80,30 +75,32 @@ public class MyController {
public Result<Void> updateUserInfo(@RequestHeader(value = "token", required = false) String token,
@VerifyParam(max = 12) @RequestParam("nickName") String nickName,
@VerifyParam(max = 50) @RequestParam("signature") String signature,
@RequestParam("birthDay") String birthDay, @RequestParam("sex") String sex) {
@RequestParam("birthDay") String birthDay,
@RequestParam("sex") Integer sex) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
User user = userService.findById(userLoginDto.getUserId());
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickname())) {
long count = userService.countByNickName(nickName);
UserLoginDto userLoginDto = getUserLoginDto(token);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) {
long count = userInfoService.countByNickName(nickName);
if (count > 0) {
return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST);
}
}
if (!StringTools.isEmpty(nickName)) {
user.setNickname(nickName);
user.setNickName(nickName);
}
if (!StringTools.isEmpty(signature)) {
user.setPersonality(signature);
user.setSignature(signature);
}
if (!StringTools.isEmpty(birthDay)) {
user.setBirthday(DateUtil.parse(birthDay, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()));
}
if (!StringTools.isEmpty(sex)) {
if (null!=sex) {
user.setSex(sex);
}
userService.update(user);
user.setModifyTime(new Date());
userInfoService.update(user);
return Result.success();
}
@ -112,7 +109,7 @@ public class MyController {
@GlobalInterceptor(checkLogin = true)
public Result<Void> uploadAvatar(@RequestHeader(value = "token", required = false) String token,
@VerifyParam(required = true) MultipartFile file) throws IOException {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
UserLoginDto userLoginDto = getUserLoginDto(token);
String folderName = UPLOAD_DIRECTORY + Constants.FOLDER_AVATAR;
File folder = new File(folderName);
if (!folder.exists()) {
@ -122,10 +119,10 @@ public class MyController {
File avatarFileName = new File(folder.getPath() + "/" + avatarName);
file.transferTo(avatarFileName);
ScaleFilter.createThumbnail(avatarFileName, Constants.LENGTH_70, Constants.LENGTH_70, avatarFileName);
User user = userService.findById(userLoginDto.getUserId());
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
user.setAvatar(Constants.FOLDER_AVATAR + avatarName);
userService.update(user);
userInfoService.update(user);
return Result.success();
}
//待优化
@ -134,7 +131,7 @@ public class MyController {
@GlobalInterceptor(checkLogin = true)
public @ResponseBody byte[] getImage(@RequestHeader(value = "token", required = false) String token)
throws IOException {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
UserLoginDto userLoginDto = getUserLoginDto(token);
String folderName = UPLOAD_DIRECTORY + "avatar";
File folder = new File(folderName);
File avatarFileName = new File(folder.getPath() + File.separator + userLoginDto.getUserId() + ".JPG");

@ -2,16 +2,19 @@ package com.luoo.user.dto.response;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class UserRespDTO {
@ApiModelProperty(value = "ID")
private String id;//ID
@ApiModelProperty(value = "昵称,首次注册登录,登录用户随机为“雀乐-XXXX-XXXX”游客为“游客-XXXX-XXXX”, XXXX 为2~4位中文昵称",example="雀乐-蓉江晨玥^沙顺芊润")
private String nickname;//昵称
@ApiModelProperty(value = "性别0为男1 为女,首次注册登录,留空不显示",example="0")
private String sex;//性别
@ApiModelProperty(value = "头像首次注册登录UI设计默认头像")
private String avatar;//头像
@ApiModelProperty(value = "个性签名,首次注册登录,默认为“无签名”")
private String personality;//个性
@ApiModelProperty(value = "ID")
private String id;
@ApiModelProperty(value = "昵称,首次注册登录,登录用户随机为“雀乐-XXXX-XXXX”游客为“游客-XXXX-XXXX”, XXXX 为2~4位中文昵称", example = "雀乐-蓉江晨玥^沙顺芊润")
private String nickName;
@ApiModelProperty(value = "性别0为男1 为女,首次注册登录,留空不显示", example = "0")
private Integer sex;
@ApiModelProperty(value = "头像首次注册登录UI设计默认头像")
private String avatar;
@ApiModelProperty(value = "个性签名,首次注册登录,默认为“无签名”")
private String signature;
@ApiModelProperty(value = "用户标识,如“贡献者”,“音乐人”")
private String badge;
}

@ -57,7 +57,7 @@ public class UserInfo implements Serializable {
*/
private String email;
/**
* 0:1:
* 0:1: 2:
*/
private Integer sex;
/**

Loading…
Cancel
Save