1.fix journal image update issue

main
Gary 10 months ago
parent 604476f6d0
commit 6d67d4d60b

@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import util.IdWorker; import util.IdWorker;
@ -53,7 +54,8 @@ public class CMSJournalService {
private SongInfoDao songDao; private SongInfoDao songDao;
@Autowired @Autowired
private UserClient userClient; private UserClient userClient;
@Autowired
private RedisTemplate redisTemplate;
/** /**
@ -376,6 +378,7 @@ public class CMSJournalService {
Journal journal=optional.get(); Journal journal=optional.get();
updateJournal(journal, param, token); updateJournal(journal, param, token);
journalDao.save(journal); journalDao.save(journal);
redisTemplate.opsForValue().set("journal_"+id,journal);
if (!CollectionUtils.isEmpty(param.getTag())) { if (!CollectionUtils.isEmpty(param.getTag())) {
journalTagDao.deleteByJournalId(id); journalTagDao.deleteByJournalId(id);
} }
@ -409,13 +412,22 @@ public class CMSJournalService {
String tempImage=param.getImage(); String tempImage=param.getImage();
if(!StringTools.isEmpty(tempImage)&&tempImage.contains(Constants.TEMP_KEY_PREFIX)) { if(!StringTools.isEmpty(tempImage)&&tempImage.contains(Constants.TEMP_KEY_PREFIX)) {
String srcKey=param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX)); String srcKey=param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX));
String image = moveJournalImage(srcKey, param); String image = copyJournalImage(srcKey, journal.getJournalNo());
if (!StringUtils.isBlank(image)) { if (null!=image) {
journal.setImage(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 * @param journalId

@ -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);
}
}
Loading…
Cancel
Save