diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java index fd3629f..447863d 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java @@ -41,7 +41,7 @@ public class CMSJournalController { @ApiOperation(value = "新增期刊", notes = "新增期刊") @RequestMapping(value = "/add", method = RequestMethod.POST) - public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token, + public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "期刊信息", required = true) @Valid @RequestBody JournalAddModel addModel){ return journalService.add(token, addModel); } @@ -55,7 +55,7 @@ public class CMSJournalController { @ApiOperation(value = "更新期刊", notes = "更新期刊") @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public Result update(@ApiParam(value = "期刊ID", required = true) @PathVariable String id, - @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token, + @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel){ return journalService.update(id, token, updateModel); } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java index d6a77fa..103e82b 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java @@ -38,7 +38,7 @@ public class CMSSongController { @ApiOperation(value = "新增歌曲", notes = "新增歌曲") @RequestMapping(value = "/add", method = RequestMethod.POST) - public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token, + public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel addModel){ return songService.add(token, addModel); } @@ -51,7 +51,7 @@ public class CMSSongController { @ApiOperation(value = "更新歌曲信息", notes = "更新歌曲信息") @RequestMapping(value = "/{id}", method = RequestMethod.PUT) - public Result update(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token, + public Result update(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "歌曲ID", required = true) @PathVariable String id, @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel updateModel){ return songService.update(id, token, updateModel); @@ -92,7 +92,8 @@ public class CMSSongController { @ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲") @RequestMapping(value = "/batch", method = RequestMethod.POST) - public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List files) { - return songService.batchUpload(files); + public Result batchUpload(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, + @ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List files) { + return songService.batchUpload(files, token); } } diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java index 02ea6c1..030216b 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java @@ -95,7 +95,9 @@ public class CMSJournalService { response.setJournalNo(item.getJournalNo()); response.setTitle(item.getTitle()); response.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage()); - response.setCreateTime(item.getCreateTime().format(Constants.formatter)); + if (!Objects.isNull(item.getCreateTime())) { + response.setCreateTime(item.getCreateTime().format(Constants.formatter)); + } response.setState(item.getState()); response.setIsPublish(item.getIsPublish()); if (!Objects.isNull(item.getPubTime())) { @@ -380,15 +382,19 @@ public class CMSJournalService { if (StringUtils.isNotBlank(srcKey)) { String image = moveJournalImage(srcKey, param); if (StringUtils.isBlank(image)) { - Result.failed("更新失败"); + return Result.failed("更新失败"); } journal.setImage(image); + } else { + journal.setImage(oldJournal.getImage()); } journal.setState(oldJournal.getState()); journal.setIsPublish(oldJournal.getIsPublish()); journal.setIsScheduled(oldJournal.getIsScheduled()); journal.setVisits(oldJournal.getVisits()); journal.setComment(oldJournal.getComment()); + journal.setCreateTime(oldJournal.getCreateTime()); + journal.setPubTime(oldJournal.getPubTime()); journalDao.save(journal); batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo()); batchSaveJournalRelatesInfo(id, param); diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java index 43492ab..28e5423 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java @@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -66,9 +67,9 @@ public class CMSSongService { */ public Result> search(SongQueryModel param, int page, int size) { List result = new ArrayList<>(); - // Sort sort = new Sort(Sort.Direction.DESC, "create_time"); - // PageRequest pageRequest = PageRequest.of(page - 1, size, sort); - PageRequest pageRequest = PageRequest.of(page - 1, size); + Sort sort = new Sort(Sort.Direction.DESC, "id"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + // PageRequest pageRequest = PageRequest.of(page - 1, size); Page songPage; if (!Objects.isNull(param)) { Specification songSpecification = buildSearchSpecification(param); @@ -90,14 +91,19 @@ public class CMSSongService { response.setArtist(item.getArtist()); response.setAlbum(item.getAlbum()); response.setTags(songTagMap.get(id)); - response.setImage(Constants.SONG_RESOURCE_PREFIX + item.getImage()); + if (StringUtils.isNotBlank(item.getImage())) { + response.setImage(Constants.SONG_RESOURCE_PREFIX + item.getImage()); + } response.setSize(CommonUtil.formatSongSize(item.getSize())); response.setDuration(CommonUtil.formatSongDuration(item.getDuration())); response.setJournal(songJournalMap.get(id)); response.setUpdateTime(item.getUpdateTime().format(Constants.formatter)); response.setState(item.getState()); response.setUserId(item.getUserId()); - response.setUrl(Constants.SONG_RESOURCE_PREFIX + item.getUrl()); + response.setUserName(item.getUserName()); + if (StringUtils.isNotBlank(item.getUrl())) { + response.setUrl(Constants.SONG_RESOURCE_PREFIX + item.getUrl()); + } result.add(response); } } @@ -228,10 +234,9 @@ public class CMSSongService { song.setName(param.getName()); song.setArtist(param.getArtist()); song.setAlbum(param.getAlbum()); - song.setSize(param.getSize()); - song.setDuration(param.getDuration()); - if (StringUtils.isNotBlank(token)) { - UserLoginDto user = jwtUtil.getUserLoginDto(token); + song.setLyric(param.getLyric()); + UserLoginDto user = getUserInfoByToken(token); + if (!Objects.isNull(user)) { song.setUserId(user.getUserId()); song.setUserName(user.getNickName()); song.setUserType(user.getRoles()); @@ -284,15 +289,6 @@ public class CMSSongService { } } - /** - * 更新期刊中歌曲的信息 - * @param id - * @param param - */ - private void batchSaveSongJournalInfo(String id, SongAddModel param) { - // TODO - } - /** * 查询曲目详情 * @param id @@ -339,19 +335,41 @@ public class CMSSongService { if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) { image = moveSongImage(id, param); if (StringUtils.isBlank(image)) { - Result.failed("更新失败"); + return Result.failed("更新失败"); } song.setImage(image); } else { song.setImage(oldSong.getImage()); } song.setState(oldSong.getState()); + song.setCreateTime(oldSong.getCreateTime()); songDao.save(song); songTagDao.deleteBySongId(id); batchSaveSongTagInfo(id, param); + batchUpdateJournalSongInfo(id, song); return Result.success(); } + /** + * 更新期刊歌曲表中歌曲的信息 + * @param id + * @param song + */ + private void batchUpdateJournalSongInfo(String id, SongInfo song) { + List journalSongList = journalSongDao.findBySongId(id); + if (journalSongList.size() > 0) { + for (JournalSong item : journalSongList) { + item.setName(song.getName()); + item.setArtist(song.getArtist()); + item.setAlbum(song.getAlbum()); + item.setUrl(song.getUrl()); + item.setImage(song.getImage()); + } + s3Service.fromSongToMusic(journalSongList); + journalSongDao.saveAll(journalSongList); + } + } + /** * 更新歌曲状态 * @param id @@ -427,17 +445,18 @@ public class CMSSongService { } /** - * 批量上传歌曲 + * 批量上传歌曲,获取不到歌曲的歌手乐队、专辑 * @param files * @return */ - public Result batchUpload(List files) { - for (MultipartFile file : files) { + public Result batchUpload(List files, String token) { + UserLoginDto user = getUserInfoByToken(token); + for (MultipartFile file : files) if (!file.isEmpty()) { String id = String.valueOf(idWorker.nextId()); String originalFilename = file.getOriginalFilename(); String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT)); - String keySuffix = id + "/00" + suffix; + String keySuffix = id + "/00" + suffix; String key = Constants.SONG_KEY_PREFIX + keySuffix; int upload = s3Service.upload(Constants.BUCKET, key, file); if (upload > 0) { @@ -447,13 +466,40 @@ public class CMSSongService { song.setUrl(keySuffix); song.setSize(file.isEmpty() ? 0L : file.getSize()); song.setDuration(CommonUtil.getSongDuration(file)); + if (!Objects.isNull(user)) { + song.setUserId(user.getUserId()); + song.setUserName(user.getNickName()); + song.setUserType(user.getRoles()); + } songDao.save(song); } } - } return Result.success(); } + /** + * 根据 token 获取用户信息 + * @param token + * @return + */ + private UserLoginDto getUserInfoByToken(String token) { + if (StringUtils.isNotBlank(token)) { + try { + UserLoginDto user = jwtUtil.getUserLoginDto(token); + if (!Objects.isNull(user)) { + return user; + } + } catch (Exception e) { + } + } + return null; + } + + /** + * 读取歌词文件 + * @param lyricUrl + * @return + */ private String readLyric(String lyricUrl) { try { // 创建 URL 对象 diff --git a/luoo_music/src/main/java/com/luoo/music/service/S3Service.java b/luoo_music/src/main/java/com/luoo/music/service/S3Service.java index a10d69d..09122aa 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/S3Service.java +++ b/luoo_music/src/main/java/com/luoo/music/service/S3Service.java @@ -43,7 +43,10 @@ public class S3Service { String destUrlSuffix = format + srcUrl.substring(srcUrl.lastIndexOf(Constants.DOT)); String destUrl = Constants.MUSIC_KEY_PREFIX + destUrlSuffix; item.setUrl(destUrlSuffix); - copy(Constants.BUCKET, srcUrl, destUrl); + int copy = copy(Constants.BUCKET, srcUrl, destUrl); + if (copy == -1) { + item.setUrl(null); + } tempLyric = srcUrl; } if (StringUtils.isNotBlank(item.getImage())) { @@ -51,7 +54,10 @@ public class S3Service { String destImageSuffix = format + srcImage.substring(srcImage.lastIndexOf(Constants.DOT)); String destImage = Constants.MUSIC_KEY_PREFIX + destImageSuffix; item.setImage(destImageSuffix); - copy(Constants.BUCKET, srcImage, destImage); + int copy = copy(Constants.BUCKET, srcImage, destImage); + if (copy == -1) { + item.setImage(null); + } } if (StringUtils.isNotBlank(tempLyric)) { String srcLyric = tempLyric.substring(0, tempLyric.lastIndexOf(Constants.DOT)) + ".lyric";