From 9746d3511bd378840157b3900eb11d681559b80c Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 3 Apr 2024 23:23:31 +0800 Subject: [PATCH] fix NPE --- .../comment/controller/CommentController.java | 30 ++++++++++++------- .../src/main/java/constants/Constants.java | 3 +- .../music/controller/JournalController.java | 12 ++++---- .../luoo/music/controller/SongController.java | 12 ++++---- .../dto/response/cms/ArticleRespDTO.java | 6 ++-- .../java/com/luoo/music/util/Constants.java | 15 ++++++---- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index e63a0fb..6d65573 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -244,8 +244,8 @@ public class CommentController extends BaseController { UserInfo commentUserInfo = userInfoService.findById(comment.getUserId()); - comment.setNickName(commentUserInfo.getNickName()); - comment.setAvatar(getAvatar(commentUserInfo)); + + if(StringUtils.isNotEmpty(comment.getReplyToUserId())){ UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId()); @@ -253,20 +253,28 @@ public class CommentController extends BaseController { } CommentResp commentResp = new CommentResp(); BeanUtils.copyProperties(comment,commentResp); - if (StringUtils.isNotEmpty(commentUserInfo.getBadges())){ - Set badgeSet = new HashSet<>(); - Arrays.stream(commentUserInfo.getBadges().split(",")).forEach(b->{ - int code=Integer.valueOf(b.substring(0, 1)); - badgeSet.add(code); - }); - commentResp.setBadgeList(new ArrayList<>(badgeSet)); + if (null != commentUserInfo) { + comment.setNickName(commentUserInfo.getNickName()); + comment.setAvatar(getAvatar(commentUserInfo)); + if (StringUtils.isNotEmpty(commentUserInfo.getBadges())){ + Set badgeSet = new HashSet<>(); + Arrays.stream(commentUserInfo.getBadges().split(",")).forEach(b->{ + int code=Integer.valueOf(b.substring(0, 1)); + badgeSet.add(code); + }); + commentResp.setBadgeList(new ArrayList<>(badgeSet)); + } } + if(comment.getCommentCount()>0){ Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0); UserInfo topCommentUserInfo = userInfoService.findById(topComment.getUserId()); - topComment.setNickName(topCommentUserInfo.getNickName()); - topComment.setAvatar(getAvatar(topCommentUserInfo)); + if(null != topCommentUserInfo) { + topComment.setNickName(topCommentUserInfo.getNickName()); + topComment.setAvatar(getAvatar(topCommentUserInfo)); + } + if(StringUtils.isNotEmpty(topComment.getReplyToUserId())){ UserInfo topReplyUserInfo = userInfoService.findById(topComment.getReplyToUserId()); topComment.setReplyToNickname(topReplyUserInfo.getNickName()); diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index d996823..ab1c4ee 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -40,7 +40,8 @@ public class Constants { public static final String TOKEN_ROLE_ADMIN_USER = "admin"; // public static final String TOKEN_ROLE_TOURIST="tourist"; - public static final String RESOURCE_PREFIX = "http://cdn1.indie.cn:19000/indie/"; +// public static final String RESOURCE_PREFIX = "http://cdn1.indie.cn:19000/indie/"; + public static final String RESOURCE_PREFIX = "https://cdn2.indie.cn/indie/"; public static final String MUSIC_RESOURCE_PREFIX = RESOURCE_PREFIX + "music/"; public static final String SONG_RESOURCE_PREFIX = RESOURCE_PREFIX + "song/"; diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 0e44110..97dae1c 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -78,13 +78,13 @@ public class JournalController { UserLoginDto user = jwtUtil.getUserLoginDto(authorization); updateQuery(user,queryReq); List pageList=journalService.queryJournalByPage(queryReq); - pageList = pageList.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); +// pageList = pageList.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); Set journalCollectSet = getJournalCollectSet(user); updateCollectStatus(pageList,journalCollectSet); return Result.success(new PageResult(Long.valueOf(pageList.size()), pageList)); } - private JournalRespDTO randomCDN(JournalRespDTO journalRespDTO) { + private JournalRespDTO randomCDN1(JournalRespDTO journalRespDTO) { // Random random = new Random(); // int randomNum = random.nextInt(2)+1; @@ -145,7 +145,7 @@ public class JournalController { Set journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds); List list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); - list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); +// list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } @@ -237,7 +237,7 @@ public class JournalController { boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL); journalRespDTO.setHaveCollect(isCollect); - journalRespDTO = randomCDN(journalRespDTO); +// journalRespDTO = randomCDN(journalRespDTO); return Result.success(journalRespDTO); } @@ -257,7 +257,7 @@ public class JournalController { } boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),journalRespDTO.getId(), CollectTypeEnum.JOURNAL); journalRespDTO.setHaveCollect(isCollect); - journalRespDTO = randomCDN(journalRespDTO); +// journalRespDTO = randomCDN(journalRespDTO); return Result.success(journalRespDTO); } private boolean isLatest10(String journalNo) { @@ -289,7 +289,7 @@ public class JournalController { : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); List list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); - list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); +// list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); return Result.success(list); } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index 5af70c2..a928e7a 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -69,14 +69,14 @@ public class SongController { return Result.unauthorized(null); } List results = journalSongService.findByJournalNo(journalNo); - results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); +// results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); Set songCollectSet = getSongCollectSet(results,user); updateCollectStatus(results,songCollectSet); return Result.success(results); } - private SongRespDTO randomCDN(SongRespDTO s){ + private SongRespDTO randomCDN1(SongRespDTO s){ Random random = new Random(); int rate = random.nextInt(100); // int randomNum = random.nextInt(2)+1; @@ -103,7 +103,7 @@ public class SongController { @GlobalInterceptor public Result> getByJournalId(@PathVariable String journalId) { List list = journalSongService.findByJournalId(journalId); - list = list.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); +// list = list.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); return Result.success(list); } @@ -144,7 +144,7 @@ public class SongController { Set songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource); List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) .collect(Collectors.toList()); - results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); +// results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(results.size()), results)); } @@ -182,7 +182,7 @@ public class SongController { List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) .collect(Collectors.toList()); - results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); +// results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); return Result.success(results); } @@ -199,7 +199,7 @@ public class SongController { SongRespDTO songRespDTO=SongMapper.getSongRespDTO(song); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.SONG); songRespDTO.setHaveCollect(isCollect); - songRespDTO = randomCDN(songRespDTO); +// songRespDTO = randomCDN(songRespDTO); return Result.success(songRespDTO); } } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java index 33c56a3..96bbcb0 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java @@ -45,8 +45,8 @@ public class ArticleRespDTO implements Serializable { @ApiModelProperty(value = "是否允许评论 否:0 是:1") private String allowCommit; - @ApiModelProperty(value = "是否自动推送 否:false 是:true") - private Boolean autoPush; + @ApiModelProperty(value = "是否自动推送 否:0 是:1") + private String autoPush; @ApiModelProperty(value = "总评论数,大于99,显示99+") private Long totalCommentReply; @@ -74,7 +74,7 @@ public class ArticleRespDTO implements Serializable { response.setIsScheduled(article.getIsScheduled()); response.setPubTime(article.getPubTime().format(DateTimeFormatter.ISO_DATE_TIME)); response.setAllowCommit(article.getAllowCommit()); - response.setAutoPush("1".equals(article.getAutoPush())?true:false); + response.setAutoPush(article.getAutoPush()); return response; } diff --git a/luoo_music/src/main/java/com/luoo/music/util/Constants.java b/luoo_music/src/main/java/com/luoo/music/util/Constants.java index de1c510..b4e05f5 100644 --- a/luoo_music/src/main/java/com/luoo/music/util/Constants.java +++ b/luoo_music/src/main/java/com/luoo/music/util/Constants.java @@ -13,16 +13,21 @@ public class Constants { public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // 期刊封面前缀 - public static final String MUSIC_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/music/"; +// public static final String MUSIC_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/music/"; + public static final String MUSIC_RESOURCE_PREFIX="https://cdn2.indie.cn/indie/music/"; // 歌曲文件、封面、歌词前缀 - public static final String SONG_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/song/"; - public static final String ARTICLE_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/article/"; +// public static final String SONG_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/song/"; + public static final String SONG_RESOURCE_PREFIX="https://cdn2.indie.cn/indie/song/"; +// public static final String ARTICLE_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/article/"; + public static final String ARTICLE_RESOURCE_PREFIX="https://cdn2.indie.cn/indie/article/"; - public static final String Advertisement_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/ad/"; +// public static final String Advertisement_RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/ad/"; + public static final String Advertisement_RESOURCE_PREFIX="https://cdn2.indie.cn/indie/ad/"; public static final String BUCKET = "indie"; - public static final String RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/"; +// public static final String RESOURCE_PREFIX="http://cdn1.indie.cn:19000/indie/"; + public static final String RESOURCE_PREFIX="https://cdn2.indie.cn/indie/"; public static final String MUSIC_KEY_PREFIX = "music/"; public static final String SONG_KEY_PREFIX = "song/"; public static final String TEMP_KEY_PREFIX = "temp/";