1.update url for song/image/lyric

main
Gary 10 months ago
parent e8ff3810af
commit c9d913fc61

@ -46,4 +46,6 @@ public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSp
@Query(value = "select * from tb_journal_song where id in ?1 order by field(id,?1)", nativeQuery = true)
public List<JournalSong> orderByField(List<String> idList);
List<JournalSong> findByJournalNoOrderBySongNo(String journalNo);
}

@ -1,5 +1,6 @@
package com.luoo.music.dao;
import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.SongInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -25,5 +26,13 @@ public interface SongInfoDao extends JpaRepository<SongInfo,String>, JpaSpecific
@Query("UPDATE SongInfo s SET s.lyric = :lyric WHERE s.id = :id")
int updateSongLyric(@Param("id") String id, @Param("lyric") String lyric);
@Modifying
@Transactional
@Query("UPDATE SongInfo s SET s.lyric = :lyric,s.lyricUrl = :lyricUrl WHERE s.id = :id")
int updateSongLyricAndUrl(@Param("id") String id, @Param("lyric") String lyric,@Param("lyricUrl") String lyricUrl);
List<SongInfo> findByIdIn(List<String> ids);
@Query(value = "select * from tb_song_info where id in ?1 order by field(id,?1)", nativeQuery = true)
List<SongInfo> orderByField(List<String> objectIds);
}

@ -16,9 +16,9 @@ public class SongMapper {
songRespDTO.setArtist(song.getArtist());
songRespDTO.setId(song.getId());
songRespDTO.setTitle(song.getName());
songRespDTO.setSrc(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl());
songRespDTO.setPic(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".jpg"));
songRespDTO.setLrc(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".lyric"));
songRespDTO.setSrc(Constants.RESOURCE_PREFIX + song.getUrl());
songRespDTO.setPic(Constants.RESOURCE_PREFIX + song.getImage());
songRespDTO.setLrc(Constants.RESOURCE_PREFIX + song.getLyricUrl());
songRespDTO.setSongNo(song.getSongNo());
songRespDTO.setHaveCollect(songCollectSet.contains(songRespDTO.getId()));
return songRespDTO;

@ -53,4 +53,8 @@ public class JournalSong implements Serializable{
* ID
*/
private String songId;
/**
*
*/
private String lyricUrl;
}

@ -88,4 +88,9 @@ public class SongInfo implements Serializable {
*
*/
private String lyric;
/**
*
*/
private String lyricUrl;
}

@ -30,6 +30,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -57,9 +58,9 @@ public class CMSJournalService {
@Autowired
private RedisTemplate redisTemplate;
/**
* +
*
* @param param
* @param page
* @param size
@ -120,6 +121,7 @@ public class CMSJournalService {
/**
*
*
* @param param
* @return
*/
@ -159,6 +161,7 @@ public class CMSJournalService {
/**
*
*
* @param journalNos
* @return
*/
@ -167,8 +170,7 @@ public class CMSJournalService {
if (!CollectionUtils.isEmpty(journalNos)) {
List<Map<String, Long>> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
songCountMap = journalSongCountList.stream()
.collect(Collectors.toMap(
map -> String.valueOf(map.get("journalNo")),
.collect(Collectors.toMap(map -> String.valueOf(map.get("journalNo")),
map -> Long.valueOf(String.valueOf(map.get("songCount")))));
}
return songCountMap;
@ -176,6 +178,7 @@ public class CMSJournalService {
/**
*
*
* @param ids
* @return
*/
@ -204,6 +207,7 @@ public class CMSJournalService {
/**
*
*
* @param param
* @return
*/
@ -229,6 +233,7 @@ public class CMSJournalService {
/**
*
*
* @param param
* @return
*/
@ -246,6 +251,7 @@ public class CMSJournalService {
/**
*
*
* @param id
* @param param
* @param token
@ -270,6 +276,7 @@ public class CMSJournalService {
/**
*
*
* @param journalId
* @param param
*/
@ -317,11 +324,16 @@ public class CMSJournalService {
/**
*
*
* @param id
* @return
*/
public Result<JournalVO> findOne(String id) {
Journal journal = journalDao.findById(id).get();
Optional<Journal> optional=journalDao.findById(id);
if(!optional.isPresent()) {
return Result.failed("无法找到期刊: "+id);
}
Journal journal = optional.get();
JournalVO response = new JournalVO();
response.setId(journal.getId());
response.setJournalNo(journal.getJournalNo());
@ -338,6 +350,7 @@ public class CMSJournalService {
/**
*
*
* @param journalNo
* @return
*/
@ -352,10 +365,10 @@ public class CMSJournalService {
songVO.setArtist(item.getArtist());
songVO.setAlbum(item.getAlbum());
if (StringUtils.isNotBlank(item.getUrl())) {
songVO.setUrl(Constants.MUSIC_RESOURCE_PREFIX + item.getUrl());
songVO.setUrl(Constants.RESOURCE_PREFIX + item.getUrl());
}
if (StringUtils.isNotBlank(item.getImage())) {
songVO.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage());
songVO.setImage(Constants.RESOURCE_PREFIX + item.getImage());
}
list.add(songVO);
}
@ -365,6 +378,7 @@ public class CMSJournalService {
/**
*
*
* @param id
* @param token
* @param param
@ -379,15 +393,75 @@ public class CMSJournalService {
updateJournal(journal, param, token);
journalDao.save(journal);
redisTemplate.opsForValue().set("journal_" + id, journal);
if (!CollectionUtils.isEmpty(param.getTag())) {
journalTagDao.deleteByJournalId(id);
batchUpdateJournalRelatesInfo(id, journal.getJournalNo(), param);
return Result.success();
}
if (!CollectionUtils.isEmpty(param.getSongs())) {
journalSongDao.deleteByJournalNo(id);
private void batchUpdateJournalRelatesInfo(String journalId, String journalNo, JournalAddModel param) {
// 标签信息
List<String> updateTags = param.getTag();
List<String> currentTags = journalTagDao.findTagsByJournalId(journalId);
if (!CollectionUtils.isEmpty(updateTags) && !isCollectionEqual(currentTags, updateTags)) {
// 清理当前journalTag
journalTagDao.deleteByJournalId(journalId);
List<JournalTag> updatedJournalTags = updateTags.stream().map(t -> createJournalTag(t, journalId))
.collect(Collectors.toList());
journalTagDao.saveAll(updatedJournalTags);
}
batchSaveJournalRelatesInfo(id, param);
return Result.success();
// 歌曲信息
List<String> updateSongs = param.getSongs();
if (!CollectionUtils.isEmpty(updateSongs)) {
// 清理当前journalSong
journalSongDao.deleteByJournalNo(journalId);
List<SongInfo> songList = songDao.orderByField(updateSongs);
List<JournalSong> updatedJournalSong = new ArrayList<>();
for (int i = 1; i < songList.size(); i++) {
SongInfo song = songList.get(i);
JournalSong journalSong = new JournalSong();
journalSong.setId(String.valueOf(idWorker.nextId()));
journalSong.setName(song.getName());
journalSong.setAlbum(song.getAlbum());
journalSong.setArtist(song.getArtist());
journalSong.setUrl(Constants.SONG_KEY_PREFIX+song.getUrl());
journalSong.setImage(Constants.SONG_KEY_PREFIX+song.getImage());
journalSong.setLyricUrl(Constants.SONG_KEY_PREFIX+song.getLyricUrl());
journalSong.setSongId(song.getId());
journalSong.setJournalNo(journalNo);
journalSong.setSongNo(i);
updatedJournalSong.add(journalSong);
}
journalSongDao.saveAll(updatedJournalSong);
}
}
private JournalTag createJournalTag(String tagId, String journalId) {
JournalTag journalTag = new JournalTag();
journalTag.setId(String.valueOf(idWorker.nextId()));
journalTag.setJournalId(journalId);
journalTag.setTagId(tagId);
return journalTag;
}
private boolean isCollectionEqual(List<String> current, List<String> update) {
if ((null == current && null == update) || (current.isEmpty() && update.isEmpty())) {
return true;
}
if (current.size() != update.size()) {
return false;
}
Collections.sort(current);
Collections.sort(update);
for (int i = 0; i < current.size(); i++) {
if (!current.get(i).equals(update.get(i))) {
return false;
}
}
return true;
}
private void updateJournal(Journal journal, JournalAddModel param, String token) {
String title = param.getTitle();
if (!StringTools.isEmpty(title)) {
@ -420,7 +494,8 @@ public class CMSJournalService {
}
private String copyJournalImage(String srcKey, String journalNo) {
String destKeySuffix = String.format("%05d/%s", Integer.parseInt(journalNo), srcKey.replace(Constants.TEMP_KEY_PREFIX, ""));
String destKeySuffix = String.format("%05d/%s", Integer.parseInt(journalNo),
srcKey.replace(Constants.TEMP_KEY_PREFIX, ""));
String destKey = Constants.MUSIC_KEY_PREFIX + destKeySuffix;
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
if (copy > 0) {
@ -428,8 +503,10 @@ public class CMSJournalService {
}
return null;
}
/**
*
*
* @param journalId
* @param journalNo
*/
@ -440,6 +517,7 @@ public class CMSJournalService {
/**
*
*
* @param id
* @param queryModel
* @return
@ -461,6 +539,7 @@ public class CMSJournalService {
/**
*
*
* @param id
* @param state
* @return
@ -472,6 +551,7 @@ public class CMSJournalService {
/**
*
*
* @param id
* @return
*/

@ -397,9 +397,9 @@ public class CMSSongService {
result.setLyric(song.getLyric());
} else {
if (StringUtils.isNotBlank(song.getUrl())) {
String url = song.getUrl();
String lyricSuffix = url.substring(0, url.lastIndexOf(Constants.DOT)) + ".lyric";
String lyricUrl = Constants.RESOURCE_PREFIX + Constants.SONG_KEY_PREFIX + lyricSuffix;
//String url = song.getUrl();
//String lyricSuffix = url.substring(0, url.lastIndexOf(Constants.DOT)) + ".lyric";
String lyricUrl = Constants.RESOURCE_PREFIX + Constants.SONG_KEY_PREFIX + song.getLyricUrl();
String lyric = readLyric(lyricUrl);
result.setLyric(lyric);
}
@ -414,17 +414,11 @@ public class CMSSongService {
* @return
*/
public Result updateSongLyric(String id, String lyric) {
songDao.updateSongLyric(id, lyric);
if (StringUtils.isNotBlank(lyric)) {
String key = Constants.SONG_KEY_PREFIX + id + "/00.lyric";
String lyricUrl=id + "/"+idWorker.nextId()+".lyric";
String key = Constants.SONG_KEY_PREFIX + lyricUrl;
songDao.updateSongLyricAndUrl(id, lyric, lyricUrl);
s3Service.uploadText(Constants.BUCKET, key, lyric);
List<JournalSong> bySongId = journalSongDao.findBySongId(id);
for (JournalSong item : bySongId) {
String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo());
String destLyricSuffix = format + ".lyric";
String destLyric = Constants.MUSIC_KEY_PREFIX + destLyricSuffix;
s3Service.copy(Constants.BUCKET, key, destLyric);
}
}
return Result.success();
}

Loading…
Cancel
Save