From 604476f6d00f78430d269d4aef166cd9934560fc Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 7 Feb 2024 15:50:41 +0800 Subject: [PATCH] 1.remove unused class 2.enhance journal upload logic --- .../java/com/luoo/music/pojo/UserCollect.java | 37 ---------- .../luoo/music/service/CMSJournalService.java | 70 +++++++++++-------- .../com/luoo/music/service/S3Service.java | 60 ++++++++-------- .../user/controller/CMSAdminController.java | 17 +++++ 4 files changed, 88 insertions(+), 96 deletions(-) delete mode 100644 luoo_music/src/main/java/com/luoo/music/pojo/UserCollect.java diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/UserCollect.java b/luoo_music/src/main/java/com/luoo/music/pojo/UserCollect.java deleted file mode 100644 index dbec8a7..0000000 --- a/luoo_music/src/main/java/com/luoo/music/pojo/UserCollect.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.luoo.music.pojo; - -import lombok.Getter; -import lombok.Setter; - -import java.util.LinkedList; - -import org.springframework.data.annotation.Id; -import java.io.Serializable; - -/** - * 用户收藏 - */ -@Getter -@Setter -public class UserCollect implements Serializable { - private static final long serialVersionUID = 1L; - /** - * 用户ID - */ - @Id - private String userId; - - /** - * 主体ID 期刊ID,歌曲ID - */ - private String objectId; - - /** - * 0:为歌曲,1:期刊 - */ - private Integer collectType; - - private LinkedList journals; - - private LinkedList songs; -} 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 0830de0..e08725b 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 @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import util.IdWorker; import util.JwtUtil; +import util.StringTools; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -368,41 +369,52 @@ public class CMSJournalService { * @return */ public Result update(String id, String token, JournalAddModel param) { - Journal oldJournal = journalDao.findById(id).get(); - List byJournalNo = journalDao.findByJournalNo(param.getJournalNo()); - if (!oldJournal.getJournalNo().equals(param.getJournalNo()) && byJournalNo.size() > 0) { - return Result.failed("更新失败,期刊编号已存在"); + Optional optional = journalDao.findById(id); + if(!optional.isPresent()) { + return Result.failed("找不到期刊: "+id); } - Journal journal = buildJournal(id, param, token); - String srcKey = null; - if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) { - srcKey = param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX)); - } else { - if (!oldJournal.getJournalNo().equals(param.getJournalNo())) { - srcKey = param.getImage().substring(param.getImage().indexOf(Constants.MUSIC_KEY_PREFIX)); - } + Journal journal=optional.get(); + updateJournal(journal, param, token); + journalDao.save(journal); + if (!CollectionUtils.isEmpty(param.getTag())) { + journalTagDao.deleteByJournalId(id); } - if (StringUtils.isNotBlank(srcKey)) { - String image = moveJournalImage(srcKey, param); - if (StringUtils.isBlank(image)) { - return Result.failed("更新失败"); - } - journal.setImage(image); - } else { - journal.setImage(oldJournal.getImage()); + if (!CollectionUtils.isEmpty(param.getSongs())) { + journalSongDao.deleteByJournalNo(id); } - 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); return Result.success(); } + private void updateJournal(Journal journal, JournalAddModel param, String token) { + String title=param.getTitle(); + if(!StringTools.isEmpty(title)) { + journal.setTitle(title); + } + + String content=param.getContent(); + if(!StringTools.isEmpty(content)) { + journal.setContent(content); + } + + String userId=param.getUserId(); + if(!StringTools.isEmpty(userId)) { + UserInfo userInfo = userClient.queryUserInfoById(userId); + if (!Objects.isNull(userInfo)) { + journal.setUserId(userInfo.getId()); + journal.setUserName(userInfo.getName()); + journal.setUserType(userInfo.getType()); + } + } + + String tempImage=param.getImage(); + if(!StringTools.isEmpty(tempImage)&&tempImage.contains(Constants.TEMP_KEY_PREFIX)) { + String srcKey=param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX)); + String image = moveJournalImage(srcKey, param); + if (!StringUtils.isBlank(image)) { + journal.setImage(image); + } + } + } /** * 删除期刊的标签、音乐信息 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 bcca2c8..3011882 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 @@ -36,41 +36,41 @@ public class S3Service { * @param journalSongList */ public void fromSongToMusic(List journalSongList) { - for (JournalSong item : journalSongList) { - String tempLyric = null; - String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo()); - if (StringUtils.isNotBlank(item.getUrl())) { - String srcUrl = Constants.SONG_KEY_PREFIX + item.getUrl(); - String destUrlSuffix = format + srcUrl.substring(srcUrl.lastIndexOf(Constants.DOT)); - String destUrl = Constants.MUSIC_KEY_PREFIX + destUrlSuffix; - item.setUrl(destUrlSuffix); - int copy = copy(Constants.BUCKET, srcUrl, destUrl); - if (copy == -1) { - item.setUrl(null); - } - tempLyric = srcUrl; + journalSongList.parallelStream().forEach(this::fromSongToMusic); + } + private void fromSongToMusic(JournalSong item) { + String tempLyric = null; + String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo()); + if (StringUtils.isNotBlank(item.getUrl())) { + String srcUrl = Constants.SONG_KEY_PREFIX + item.getUrl(); + String destUrlSuffix = format + srcUrl.substring(srcUrl.lastIndexOf(Constants.DOT)); + String destUrl = Constants.MUSIC_KEY_PREFIX + destUrlSuffix; + item.setUrl(destUrlSuffix); + int copy = copy(Constants.BUCKET, srcUrl, destUrl); + if (copy == -1) { + item.setUrl(null); } - if (StringUtils.isNotBlank(item.getImage())) { - String srcImage = Constants.SONG_KEY_PREFIX + item.getImage(); - String destImageSuffix = format + srcImage.substring(srcImage.lastIndexOf(Constants.DOT)); - String destImage = Constants.MUSIC_KEY_PREFIX + destImageSuffix; - item.setImage(destImageSuffix); - int copy = copy(Constants.BUCKET, srcImage, destImage); - if (copy == -1) { - item.setImage(null); - } + tempLyric = srcUrl; + } + if (StringUtils.isNotBlank(item.getImage())) { + String srcImage = Constants.SONG_KEY_PREFIX + item.getImage(); + String destImageSuffix = format + srcImage.substring(srcImage.lastIndexOf(Constants.DOT)); + String destImage = Constants.MUSIC_KEY_PREFIX + destImageSuffix; + item.setImage(destImageSuffix); + 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"; - if (checkFileExist(Constants.BUCKET, srcLyric)) { - String destLyricSuffix = format + srcLyric.substring(srcLyric.lastIndexOf(Constants.DOT)); - String destLyric = Constants.MUSIC_KEY_PREFIX + destLyricSuffix; - copy(Constants.BUCKET, srcLyric, destLyric); - } + } + if (StringUtils.isNotBlank(tempLyric)) { + String srcLyric = tempLyric.substring(0, tempLyric.lastIndexOf(Constants.DOT)) + ".lyric"; + if (checkFileExist(Constants.BUCKET, srcLyric)) { + String destLyricSuffix = format + srcLyric.substring(srcLyric.lastIndexOf(Constants.DOT)); + String destLyric = Constants.MUSIC_KEY_PREFIX + destLyricSuffix; + copy(Constants.BUCKET, srcLyric, destLyric); } } } - /** * @param file * @return diff --git a/luoo_user/src/main/java/com/luoo/user/controller/CMSAdminController.java b/luoo_user/src/main/java/com/luoo/user/controller/CMSAdminController.java index 50288ed..3fd7038 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/CMSAdminController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/CMSAdminController.java @@ -71,6 +71,23 @@ public class CMSAdminController { } } + + @PostMapping("/login2/{username}/{password}") + public Result login2(@PathVariable String username,@PathVariable String password) { + + Admin admin = adminService.findByLoginnameAndPassword(username,password); + if (admin !=null) { + //生成token + String token = jwtUtil.createJWT(admin.getId(),admin.getLoginname(),"admin",""); + Map map = new HashMap<>(); + map.put("token",token); + map.put("roles","admin"); + map.put("name",admin.getLoginname()); + return Result.success(map); + } else { + return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED); + } + } /** * 查询全部数据 * @return