From 7afe8ac7f76b133cd6d7c7aa7a91caa475951dc4 Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 25 Jan 2024 14:43:19 +0800 Subject: [PATCH] 1.modify avatar file path --- .../src/main/java/constants/Constants.java | 42 +++++++++---------- .../luoo/user/controller/MyController.java | 33 +++++++++------ 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index 66d3619..189c159 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -1,33 +1,31 @@ package constants; public class Constants { - public static final String IMAGE_CHECK_CODE_KEY="image_check_code_key"; - - public static final String REDIS_KEY_IMAGE_CHECK_CODE="redis_key_image_check_code_"; - public static final String REDIS_KEY_MOBILE_CHECK_CODE="redis_key_mobile_check_code_"; - - public static final String TOKEN_ROLE="roles"; - - public static final String TOKEN_ROLE_APP_USER="user"; - public static final String TOKEN_ROLE_ADMIN_USER="admin"; - //public static final String TOKEN_ROLE_TOURIST="tourist"; - - - public static final String FOLDER_AVATAR = "avatar/"; - - public static final String MUSIC_RESOURCE_PREFIX="http://cdn.indie.cn/music/"; + public static final String IMAGE_CHECK_CODE_KEY = "image_check_code_key"; + + public static final String REDIS_KEY_IMAGE_CHECK_CODE = "redis_key_image_check_code_"; + public static final String REDIS_KEY_MOBILE_CHECK_CODE = "redis_key_mobile_check_code_"; + + public static final String TOKEN_ROLE = "roles"; + + public static final String TOKEN_ROLE_APP_USER = "user"; + public static final String TOKEN_ROLE_ADMIN_USER = "admin"; + // public static final String TOKEN_ROLE_TOURIST="tourist"; + + public static final String RESOURCE_PREFIX = "http://cdn.indie.cn/"; + public static final String MUSIC_RESOURCE_PREFIX = RESOURCE_PREFIX + "music/"; - public static final Integer LENGTH_8 = 8; + public static final Integer LENGTH_8 = 8; - public static final Integer LENGTH_10 = 10; + public static final Integer LENGTH_10 = 10; - public static final Integer LENGTH_20 = 20; + public static final Integer LENGTH_20 = 20; - public static final Integer LENGTH_30 = 30; + public static final Integer LENGTH_30 = 30; - public static final Integer LENGTH_50 = 50; + public static final Integer LENGTH_50 = 50; - public static final Integer LENGTH_70 = 70; + public static final Integer LENGTH_70 = 70; - public static final Integer LENGTH_150 = 150; + public static final Integer LENGTH_150 = 150; } 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 15924c7..035a62d 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 @@ -44,6 +44,7 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import util.DateUtil; +import util.IdWorker; import util.ScaleFilter; import util.StringTools; @@ -56,7 +57,8 @@ public class MyController extends BaseController{ private S3Service s3Service; @Autowired private UserInfoService userInfoService; - + @Autowired + private IdWorker idWorker; @Autowired private UserCollectInfoService userCollectInfoService; // private UserCollectService userCollectService; @@ -74,9 +76,7 @@ public class MyController extends BaseController{ } UserRespDTO userRespDTO = new UserRespDTO(); UserInfo user = userInfoService.findById(userLoginDto.getUserId()); - UserCollectInfo userCollectInfo = userCollectInfoService.findByUserId(userLoginDto.getUserId()); - List songList =userCollectInfo.getSongList(); - List journalList = userCollectInfo.getJournalList(); + BeanUtils.copyProperties(user, userRespDTO); //EnumMap map=userCollectService.getUserCollectTypeMap(user.getId()); // int fansCount=userCollectService.getFansCount(user.getId()); @@ -91,15 +91,24 @@ public class MyController extends BaseController{ // userRespDTO.setCommentReplyCount(0); // userRespDTO.setSongCount(songCount); // userRespDTO.setJournalCount(journalCount); - userRespDTO.setJournalList(journalList); - userRespDTO.setSongList(songList); - if(null != songList){ - userRespDTO.setSongCount(songList.size()); + if(null!=userRespDTO.getAvatar()) { + userRespDTO.setAvatar(Constants.RESOURCE_PREFIX+userRespDTO.getAvatar()); } + UserCollectInfo userCollectInfo = userCollectInfoService.findByUserId(userLoginDto.getUserId()); + if(null!=userCollectInfo) { + List songList =userCollectInfo.getSongList(); + List journalList = userCollectInfo.getJournalList(); + userRespDTO.setJournalList(journalList); + userRespDTO.setSongList(songList); + if(null != songList){ + userRespDTO.setSongCount(songList.size()); + } - if(null != journalList) { - userRespDTO.setJournalCount(journalList.size()); + if(null != journalList) { + userRespDTO.setJournalCount(journalList.size()); + } } + if(null!=user.getBirthday()) { userRespDTO.setBirthDay(DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); } @@ -153,7 +162,7 @@ public class MyController extends BaseController{ UserLoginDto userLoginDto = getUserLoginDto(token); byte[] thumbnail =ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70); - String avatarName = userLoginDto.getUserId() + StringTools.getFileSuffix(file.getOriginalFilename()); + String avatarName = userLoginDto.getUserId()+"_"+idWorker.nextId() + StringTools.getFileSuffix(file.getOriginalFilename()); String filePath=UPLOAD_DIRECTORY+avatarName; s3Service.uploadAvatar("indie",filePath,thumbnail); @@ -161,6 +170,6 @@ public class MyController extends BaseController{ user.setAvatar(filePath); userInfoService.update(user); - return Result.success(filePath); + return Result.success(Constants.RESOURCE_PREFIX+filePath); } }