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 e08725b..d11d67c 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 @@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import util.IdWorker; @@ -53,7 +54,8 @@ public class CMSJournalService { private SongInfoDao songDao; @Autowired private UserClient userClient; - + @Autowired + private RedisTemplate redisTemplate; /** @@ -376,6 +378,7 @@ public class CMSJournalService { Journal journal=optional.get(); updateJournal(journal, param, token); journalDao.save(journal); + redisTemplate.opsForValue().set("journal_"+id,journal); if (!CollectionUtils.isEmpty(param.getTag())) { journalTagDao.deleteByJournalId(id); } @@ -409,13 +412,22 @@ public class CMSJournalService { 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)) { + String image = copyJournalImage(srcKey, journal.getJournalNo()); + if (null!=image) { journal.setImage(image); } } } + private String copyJournalImage(String srcKey, String journalNo) { + 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) { + return destKeySuffix; + } + return null; + } /** * 删除期刊的标签、音乐信息 * @param journalId diff --git a/luoo_music/src/test/java/com/luoo/music/service/CMSJournalServiceTest.java b/luoo_music/src/test/java/com/luoo/music/service/CMSJournalServiceTest.java new file mode 100644 index 0000000..5aaadd3 --- /dev/null +++ b/luoo_music/src/test/java/com/luoo/music/service/CMSJournalServiceTest.java @@ -0,0 +1,19 @@ +package com.luoo.music.service; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.luoo.music.util.Constants; + +public class CMSJournalServiceTest { + + @Test + public void testUpdateImage() { + String srcKey="temp/1755154941737046016.png"; + + String destKeySuffix = String.format("%05d/%s", 20, srcKey.replace(Constants.TEMP_KEY_PREFIX, "")); + System.out.println(destKeySuffix); + } + +}