diff --git a/luoo_common/src/main/java/api/StatusCode.java b/luoo_common/src/main/java/api/StatusCode.java index bfba28f..e70e7e5 100644 --- a/luoo_common/src/main/java/api/StatusCode.java +++ b/luoo_common/src/main/java/api/StatusCode.java @@ -17,6 +17,7 @@ public enum StatusCode implements IErrorCode { USER_IMAGE_VERIFICATION_CODE_EXPIRED(10004, "图形验证码过期,请重新获取"), USER_IMAGE_VERIFICATION_CODE_MISMATCH(10005, "图形验证码校验失败,请输入正确的验证码"), USER_NICK_NAME_HAS_BEEN_EXIST(10006, "昵称已经存在"), + USER_INVALID_USER_ID(10007, "无效用户id"), // music 模块错误码以20XXX,不足5位补0; diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index af26363..ed267c1 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -59,9 +60,9 @@ import util.StringTools; @CrossOrigin @RequestMapping("/my") @Api(tags = "MyController") -public class MyController extends BaseController{ +public class MyController extends BaseController { @Autowired - private S3Service s3Service; + private S3Service s3Service; @Autowired private UserInfoService userInfoService; @Autowired @@ -70,12 +71,11 @@ public class MyController extends BaseController{ // private UserCollectInfoService userCollectInfoService; private UserCollectService userCollectService; - public static String UPLOAD_DIRECTORY = "user/avatar/"; @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @GetMapping("/getUserInfo") - @GlobalInterceptor + @GlobalInterceptor(checkAppUserLogin = true) public Result getUserInfo(@RequestHeader(value = "token", required = false) String token) { UserLoginDto userLoginDto = getUserLoginDto(token); if (null == userLoginDto) { @@ -85,7 +85,8 @@ public class MyController extends BaseController{ UserInfo user = userInfoService.findById(userLoginDto.getUserId()); BeanUtils.copyProperties(user, userRespDTO); - //EnumMap map=userCollectService.getUserCollectTypeMap(user.getId()); + // EnumMap + // map=userCollectService.getUserCollectTypeMap(user.getId()); // int fansCount=userCollectService.getFansCount(user.getId()); // int followCount=userCollectService.getCount(user.getId(),CollectTypeEnum.FOLLOW.getType()); // int thumbUpCount=userCollectService.getCount(user.getId(),CollectTypeEnum.THUMB_UP.getType()); @@ -98,19 +99,20 @@ public class MyController extends BaseController{ // userRespDTO.setCommentReplyCount(0); // userRespDTO.setSongCount(songCount); // userRespDTO.setJournalCount(journalCount); - if(null!=userRespDTO.getAvatar()) { - userRespDTO.setAvatar(Constants.RESOURCE_PREFIX+userRespDTO.getAvatar()); + if (null != userRespDTO.getAvatar()) { + userRespDTO.setAvatar(Constants.RESOURCE_PREFIX + userRespDTO.getAvatar()); } - - Optional optional=userCollectService.findByUserId(userLoginDto.getUserId()); - if(optional.isPresent()) { - UserCollect userCollect=optional.get(); + + Optional optional = userCollectService.findByUserId(userLoginDto.getUserId()); + if (optional.isPresent()) { + UserCollect userCollect = optional.get(); userRespDTO.setSongCount(userCollect.getSongs().size()); userRespDTO.setJournalCount(userCollect.getJournals().size()); } - - if(null!=user.getBirthday()) { - userRespDTO.setBirthDay(DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); + + if (null != user.getBirthday()) { + userRespDTO.setBirthDay( + DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); } return Result.success(userRespDTO); } @@ -122,7 +124,7 @@ public class MyController extends BaseController{ @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) { UserLoginDto userLoginDto = getUserLoginDto(token); UserInfo user = userInfoService.findById(userLoginDto.getUserId()); - String nickName=userInfoUpdateDto.getNickName(); + String nickName = userInfoUpdateDto.getNickName(); if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) { long count = userInfoService.countByNickName(nickName); if (count > 0) { @@ -137,9 +139,10 @@ public class MyController extends BaseController{ user.setSignature(userInfoUpdateDto.getSignature()); } if (!StringTools.isEmpty(userInfoUpdateDto.getBirthDay())) { - user.setBirthday(DateUtil.parse(userInfoUpdateDto.getBirthDay(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); + user.setBirthday(DateUtil.parse(userInfoUpdateDto.getBirthDay(), + DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); } - if (null!=userInfoUpdateDto.getSex()) { + if (null != userInfoUpdateDto.getSex()) { user.setSex(userInfoUpdateDto.getSex()); } user.setModifyTime(new Date()); @@ -153,16 +156,34 @@ public class MyController extends BaseController{ public Result uploadAvatar(@RequestHeader(value = "token", required = false) String token, @VerifyParam(required = true) MultipartFile file) throws IOException { UserLoginDto userLoginDto = getUserLoginDto(token); - - byte[] thumbnail =ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70); - String avatarName = userLoginDto.getUserId()+"_"+idWorker.nextId() + StringTools.getFileSuffix(file.getOriginalFilename()); - String filePath=UPLOAD_DIRECTORY+avatarName; - s3Service.uploadAvatar("indie",filePath,thumbnail); - + + byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70); + String avatarName = userLoginDto.getUserId() + "_" + idWorker.nextId() + + StringTools.getFileSuffix(file.getOriginalFilename()); + String filePath = UPLOAD_DIRECTORY + avatarName; + s3Service.uploadAvatar("indie", filePath, thumbnail); + UserInfo user = userInfoService.findById(userLoginDto.getUserId()); user.setAvatar(filePath); userInfoService.update(user); - return Result.success(Constants.RESOURCE_PREFIX+filePath); + return Result.success(Constants.RESOURCE_PREFIX + filePath); + } + + @ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息") + @GetMapping("/getOtherUserInfo/{userId}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result getOtherUserInfo(@RequestHeader(value = "token", required = false) String token, + @VerifyParam(required = true) @PathVariable String userId) { + UserInfo user = userInfoService.findById(userId); + if (null == user) { + return Result.failed(StatusCode.USER_INVALID_USER_ID); + } + UserRespDTO userRespDTO = new UserRespDTO(); + BeanUtils.copyProperties(user, userRespDTO); + if (null != userRespDTO.getAvatar()) { + userRespDTO.setAvatar(Constants.RESOURCE_PREFIX + userRespDTO.getAvatar()); + } + return Result.success(userRespDTO); } }