|
|
@ -8,8 +8,9 @@ import com.luoo.music.request.cms.JournalAddModel;
|
|
|
|
import com.luoo.music.request.cms.JournalQueryModel;
|
|
|
|
import com.luoo.music.request.cms.JournalQueryModel;
|
|
|
|
import com.luoo.music.response.cms.JournalVO;
|
|
|
|
import com.luoo.music.response.cms.JournalVO;
|
|
|
|
import com.luoo.music.response.cms.SongVO;
|
|
|
|
import com.luoo.music.response.cms.SongVO;
|
|
|
|
import com.luoo.music.util.CommonUtil;
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
import com.luoo.music.util.UploadUtil;
|
|
|
|
import com.luoo.music.util.UploadUtil;
|
|
|
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
@ -18,13 +19,14 @@ import org.springframework.data.domain.Sort;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import util.IdWorker;
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
@ -36,6 +38,8 @@ import java.util.stream.Collectors;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class CMSJournalService {
|
|
|
|
public class CMSJournalService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private S3Service s3Service;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IdWorker idWorker;
|
|
|
|
private IdWorker idWorker;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
@ -48,6 +52,8 @@ public class CMSJournalService {
|
|
|
|
private TagDao tagDao;
|
|
|
|
private TagDao tagDao;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SongInfoDao songDao;
|
|
|
|
private SongInfoDao songDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
@ -78,32 +84,27 @@ public class CMSJournalService {
|
|
|
|
List<Journal> content = journalPage.getContent();
|
|
|
|
List<Journal> content = journalPage.getContent();
|
|
|
|
if (!CollectionUtils.isEmpty(content)) {
|
|
|
|
if (!CollectionUtils.isEmpty(content)) {
|
|
|
|
List<String> ids = content.stream().map(Journal::getId).collect(Collectors.toList());
|
|
|
|
List<String> ids = content.stream().map(Journal::getId).collect(Collectors.toList());
|
|
|
|
Map<String, Long> songCountMap = songCountInfo(ids);
|
|
|
|
|
|
|
|
Map<String, List<String>> journalTagMap = tagInfo(ids);
|
|
|
|
Map<String, List<String>> journalTagMap = tagInfo(ids);
|
|
|
|
|
|
|
|
List<String> journalNos = content.stream().map(Journal::getJournalNo).collect(Collectors.toList());
|
|
|
|
|
|
|
|
Map<String, Long> songCountMap = songCountInfo(journalNos);
|
|
|
|
for (Journal item : content) {
|
|
|
|
for (Journal item : content) {
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
response.setId(item.getId());
|
|
|
|
response.setId(item.getId());
|
|
|
|
response.setNumber(item.getNumber());
|
|
|
|
response.setJournalNo(Constants.JOURNAL_NO_PREF + item.getJournalNo());
|
|
|
|
response.setName(item.getName());
|
|
|
|
response.setTitle(item.getTitle());
|
|
|
|
response.setCoverPhoto(item.getCoverPhoto());
|
|
|
|
response.setImage(item.getImage());
|
|
|
|
response.setCreateTime(item.getCreateTime().format(formatter));
|
|
|
|
response.setCreateTime(item.getCreateTime().format(formatter));
|
|
|
|
response.setState(item.getState());
|
|
|
|
response.setState(item.getState());
|
|
|
|
response.setStatus(item.getStatus());
|
|
|
|
response.setIsPublish(item.getIsPublish());
|
|
|
|
if (!Objects.isNull(item.getPubTime())) {
|
|
|
|
if (!Objects.isNull(item.getPubTime())) {
|
|
|
|
response.setPubTime(item.getPubTime().format(formatter));
|
|
|
|
response.setPubTime(item.getPubTime().format(formatter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO 编号文字转换
|
|
|
|
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
response.setSongCount(songCountMap.get(item.getId()));
|
|
|
|
response.setSongCount(songCountMap.get(item.getId()));
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
if (!"1".equals(param.getTab())) {
|
|
|
|
response.setVisits(item.getVisits());
|
|
|
|
response.setPlayCount(0);
|
|
|
|
response.setComment(item.getComment());
|
|
|
|
response.setCommentCount(0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// TODO 播放 评论 数
|
|
|
|
|
|
|
|
response.setPlayCount(0);
|
|
|
|
|
|
|
|
response.setCommentCount(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result.add(response);
|
|
|
|
result.add(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,30 +120,30 @@ public class CMSJournalService {
|
|
|
|
return (Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
|
|
|
|
return (Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
if("1".equals(param.getTab())) {
|
|
|
|
if("1".equals(param.getTab())) {
|
|
|
|
Predicate state = builder.equal(root.get("state"), "1");
|
|
|
|
predicateList.add(builder.equal(root.get("isPublish"), "1"));
|
|
|
|
Predicate status = builder.equal(root.get("status"), "1");
|
|
|
|
|
|
|
|
predicateList.add(builder.and(state, status));
|
|
|
|
|
|
|
|
} else if ("2".equals(param.getTab())) {
|
|
|
|
} else if ("2".equals(param.getTab())) {
|
|
|
|
predicateList.add(builder.equal(root.get("state"), "0"));
|
|
|
|
predicateList.add(builder.equal(root.get("state"), "0"));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Predicate state = builder.equal(root.get("state"), "1");
|
|
|
|
Predicate state = builder.equal(root.get("state"), "1");
|
|
|
|
Predicate status = builder.equal(root.get("status"), "0");
|
|
|
|
Predicate isPublish = builder.equal(root.get("isPublish"), "0");
|
|
|
|
predicateList.add(builder.and(state, status));
|
|
|
|
predicateList.add(builder.and(state, isPublish));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(param.getUserId())) {
|
|
|
|
if(StringUtils.isNotBlank(param.getUserId())) {
|
|
|
|
predicateList.add(builder.equal(root.get("userId"), param.getUserId()));
|
|
|
|
predicateList.add(builder.equal(root.get("userId"), param.getUserId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) {
|
|
|
|
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) {
|
|
|
|
predicateList.add(builder.between(root.get("createTime"), param.getStart(), param.getEnd()));
|
|
|
|
LocalDateTime start = LocalDateTime.parse(param.getStart() + "T00:00:00");
|
|
|
|
|
|
|
|
LocalDateTime end = LocalDateTime.parse(param.getEnd() + "T00:00:00");
|
|
|
|
|
|
|
|
predicateList.add(builder.between(root.get("createTime"), start, end));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!CollectionUtils.isEmpty(ids)) {
|
|
|
|
if (!CollectionUtils.isEmpty(ids)) {
|
|
|
|
predicateList.add(root.get("id").in(ids));
|
|
|
|
predicateList.add(root.get("journalNo").in(ids));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(param.getKeyword())) {
|
|
|
|
if(StringUtils.isNotBlank(param.getKeyword())) {
|
|
|
|
String likeExpression = "%" + param.getKeyword() + "%";
|
|
|
|
String likeExpression = "%" + param.getKeyword() + "%";
|
|
|
|
Predicate name = builder.like(root.get("number"), likeExpression);
|
|
|
|
Predicate journalNo = builder.like(root.get("journalNo"), likeExpression);
|
|
|
|
Predicate summary = builder.like(root.get("name"), likeExpression);
|
|
|
|
Predicate title = builder.like(root.get("title"), likeExpression);
|
|
|
|
predicateList.add(builder.or(name, summary));
|
|
|
|
predicateList.add(builder.or(journalNo, title));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return builder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
return builder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -150,14 +151,14 @@ public class CMSJournalService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 期刊的音乐数量
|
|
|
|
* 期刊的音乐数量
|
|
|
|
* @param ids
|
|
|
|
* @param journalNos
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Map<String, Long> songCountInfo(List<String> ids) {
|
|
|
|
private Map<String, Long> songCountInfo(List<String> journalNos) {
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
if (!CollectionUtils.isEmpty(ids)) {
|
|
|
|
if (!CollectionUtils.isEmpty(journalNos)) {
|
|
|
|
List<JournalSongCount> journalSongCountList = journalSongDao.findSongCountByJournalIds(ids);
|
|
|
|
List<JournalSongCount> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
|
|
|
|
songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalId, JournalSongCount::getSongCount));
|
|
|
|
songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalNo, JournalSongCount::getSongCount));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return songCountMap;
|
|
|
|
return songCountMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -193,56 +194,107 @@ public class CMSJournalService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 新增期刊
|
|
|
|
* 新增期刊
|
|
|
|
* @param param
|
|
|
|
* @param param
|
|
|
|
* @param image
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result add(JournalAddModel param, MultipartFile image) {
|
|
|
|
public Result add(String token, JournalAddModel param) {
|
|
|
|
String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR);
|
|
|
|
List<Journal> byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
|
|
|
|
Journal journal = buildJournal(null, param);
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
|
|
|
|
return Result.failed("保存失败,期刊编号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String image = moveJournalImage(param);
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(image)) {
|
|
|
|
|
|
|
|
Journal journal = buildJournal(null, param, token);
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
journal.setId(id);
|
|
|
|
journal.setId(id);
|
|
|
|
journal.setCoverPhoto(imagePath);
|
|
|
|
journal.setImage(image);
|
|
|
|
journalDao.save(journal);
|
|
|
|
journalDao.save(journal);
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Result.failed("保存失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 移动对象
|
|
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String moveJournalImage(JournalAddModel param) {
|
|
|
|
|
|
|
|
String image = param.getImage();
|
|
|
|
|
|
|
|
String srcKey = image.substring(image.indexOf(Constants.TEMP_KEY_PREFIX));
|
|
|
|
|
|
|
|
String suffix = image.substring(image.lastIndexOf(Constants.DOT));
|
|
|
|
|
|
|
|
String format = String.format("%05d", param.getJournalNo());
|
|
|
|
|
|
|
|
String destKeySuffix = format + "/00" + suffix;
|
|
|
|
|
|
|
|
String destKey = Constants.IMAGE_KEY_PREFIX + destKeySuffix;
|
|
|
|
|
|
|
|
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
|
|
|
|
|
|
|
|
if (copy > 0) {
|
|
|
|
|
|
|
|
return destKeySuffix;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Journal buildJournal(String id, JournalAddModel param) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 构建对象
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
|
|
* @param token
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Journal buildJournal(String id, JournalAddModel param, String token) {
|
|
|
|
Journal journal = new Journal();
|
|
|
|
Journal journal = new Journal();
|
|
|
|
if (!StringUtils.isBlank(id)) {
|
|
|
|
if (!StringUtils.isBlank(id)) {
|
|
|
|
journal.setId(id);
|
|
|
|
journal.setId(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
journal.setNumber(param.getNumber());
|
|
|
|
journal.setJournalNo(param.getJournalNo());
|
|
|
|
journal.setName(param.getName());
|
|
|
|
journal.setTitle(param.getTitle());
|
|
|
|
journal.setUserId(param.getUserId());
|
|
|
|
journal.setContent(param.getContent());
|
|
|
|
journal.setSummary(param.getSummary());
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
journal.setUserId(user.getUserId());
|
|
|
|
|
|
|
|
journal.setUserName(user.getNickName());
|
|
|
|
|
|
|
|
journal.setUserType(user.getRoles());
|
|
|
|
return journal;
|
|
|
|
return journal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 保存期刊的标签、音乐信息
|
|
|
|
* 保存期刊的标签、音乐信息
|
|
|
|
* @param id
|
|
|
|
* @param journalId
|
|
|
|
* @param param
|
|
|
|
* @param param
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void batchSaveJournalRelatesInfo(String id, JournalAddModel param) {
|
|
|
|
private void batchSaveJournalRelatesInfo(String journalId, JournalAddModel param) {
|
|
|
|
|
|
|
|
// 标签信息
|
|
|
|
if (!CollectionUtils.isEmpty(param.getTags())) {
|
|
|
|
if (!CollectionUtils.isEmpty(param.getTags())) {
|
|
|
|
List<JournalTag> journalTagList = new ArrayList<>();
|
|
|
|
List<JournalTag> journalTagList = new ArrayList<>();
|
|
|
|
for (String item : param.getTags()) {
|
|
|
|
for (String item : param.getTags()) {
|
|
|
|
JournalTag journalTag = new JournalTag();
|
|
|
|
JournalTag journalTag = new JournalTag();
|
|
|
|
journalTag.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
journalTag.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
journalTag.setJournalId(id);
|
|
|
|
journalTag.setJournalId(journalId);
|
|
|
|
journalTag.setTagId(item);
|
|
|
|
journalTag.setTagId(item);
|
|
|
|
journalTagList.add(journalTag);
|
|
|
|
journalTagList.add(journalTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
journalTagDao.saveAll(journalTagList);
|
|
|
|
journalTagDao.saveAll(journalTagList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 歌曲信息
|
|
|
|
if (!CollectionUtils.isEmpty(param.getSongs())) {
|
|
|
|
if (!CollectionUtils.isEmpty(param.getSongs())) {
|
|
|
|
|
|
|
|
List<SongInfo> songList = songDao.findByIdIn(param.getSongs());
|
|
|
|
|
|
|
|
Map<String, SongInfo> idSongMap = songList.stream().collect(Collectors.toMap(SongInfo::getId, obj -> obj));
|
|
|
|
List<JournalSong> journalSongList = new ArrayList<>();
|
|
|
|
List<JournalSong> journalSongList = new ArrayList<>();
|
|
|
|
|
|
|
|
int num = 0;
|
|
|
|
for (String item : param.getSongs()) {
|
|
|
|
for (String item : param.getSongs()) {
|
|
|
|
|
|
|
|
if (idSongMap.containsKey(item)) {
|
|
|
|
|
|
|
|
SongInfo song = idSongMap.get(item);
|
|
|
|
JournalSong journalSong = new JournalSong();
|
|
|
|
JournalSong journalSong = new JournalSong();
|
|
|
|
journalSong.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
journalSong.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
journalSong.setJournalId(id);
|
|
|
|
journalSong.setName(song.getName());
|
|
|
|
|
|
|
|
journalSong.setArtist(song.getArtist());
|
|
|
|
|
|
|
|
journalSong.setUrl(song.getUrl());
|
|
|
|
|
|
|
|
journalSong.setImage(song.getImage());
|
|
|
|
journalSong.setSongId(item);
|
|
|
|
journalSong.setSongId(item);
|
|
|
|
|
|
|
|
journalSong.setJournalNo(param.getJournalNo());
|
|
|
|
|
|
|
|
journalSong.setSongNo(num + 1);
|
|
|
|
|
|
|
|
journalSong.setSongId(song.getId());
|
|
|
|
|
|
|
|
journalSongList.add(journalSong);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
journalSongDao.saveAll(journalSongList);
|
|
|
|
journalSongDao.saveAll(journalSongList);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -257,75 +309,74 @@ public class CMSJournalService {
|
|
|
|
Journal journal = journalDao.findById(id).get();
|
|
|
|
Journal journal = journalDao.findById(id).get();
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
response.setId(journal.getId());
|
|
|
|
response.setId(journal.getId());
|
|
|
|
response.setNumber(journal.getNumber());
|
|
|
|
response.setJournalNo(journal.getJournalNo());
|
|
|
|
response.setName(journal.getName());
|
|
|
|
response.setTitle(journal.getTitle());
|
|
|
|
response.setTag(journalTagDao.findTagsByJournalId(id));
|
|
|
|
response.setTag(journalTagDao.findTagsByJournalId(id));
|
|
|
|
response.setUserId(journal.getUserId());
|
|
|
|
response.setUserId(journal.getUserId());
|
|
|
|
response.setCoverPhoto(journal.getCoverPhoto());
|
|
|
|
response.setImage(Constants.IMAGE_RESOURCE_PREFIX + journal.getImage());
|
|
|
|
response.setSongs(songInfo(journal.getId()));
|
|
|
|
response.setSongs(journalSongInfo(journal.getJournalNo()));
|
|
|
|
response.setSummary(journal.getSummary());
|
|
|
|
response.setContent(journal.getContent());
|
|
|
|
return Result.success(response);
|
|
|
|
return Result.success(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 期刊的音乐信息
|
|
|
|
* 期刊的音乐信息
|
|
|
|
* @param id
|
|
|
|
* @param journalNo
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private List<SongVO> songInfo(String id) {
|
|
|
|
private List<SongVO> journalSongInfo(String journalNo) {
|
|
|
|
List<SongVO> list = new ArrayList<>();
|
|
|
|
List<SongVO> list = new ArrayList<>();
|
|
|
|
List<JournalSong> journalSongList = journalSongDao.findByJournalId(id);
|
|
|
|
List<JournalSong> journalSongList = journalSongDao.findByJournalNo(journalNo);
|
|
|
|
if (!CollectionUtils.isEmpty(journalSongList)) {
|
|
|
|
if (!CollectionUtils.isEmpty(journalSongList)) {
|
|
|
|
Set<String> songIdSet = journalSongList.stream().map(JournalSong::getSongId).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
List<SongInfo> songList = songDao.findByIdIn(songIdSet);
|
|
|
|
|
|
|
|
Map<String, SongInfo> idTagMap = songList.stream().collect(Collectors.toMap(SongInfo::getId, obj -> obj));
|
|
|
|
|
|
|
|
for (JournalSong item : journalSongList) {
|
|
|
|
for (JournalSong item : journalSongList) {
|
|
|
|
if (idTagMap.containsKey(item.getSongId())) {
|
|
|
|
|
|
|
|
SongInfo song = idTagMap.get(item.getSongId());
|
|
|
|
|
|
|
|
SongVO songVO = new SongVO();
|
|
|
|
SongVO songVO = new SongVO();
|
|
|
|
songVO.setId(song.getId());
|
|
|
|
songVO.setId(item.getSongId());
|
|
|
|
songVO.setPicture(song.getPicture());
|
|
|
|
songVO.setImage(Constants.RESOURCE_PREFIX + Constants.MUSIC_KEY_PREFIX + item.getImage());
|
|
|
|
songVO.setName(song.getName());
|
|
|
|
songVO.setName(item.getName());
|
|
|
|
songVO.setArtist(song.getArtist());
|
|
|
|
songVO.setArtist(item.getArtist());
|
|
|
|
songVO.setAlbum(song.getAlbum());
|
|
|
|
songVO.setAlbum(item.getAlbum());
|
|
|
|
songVO.setDuration(CommonUtil.formatSongDuration(song.getDuration()));
|
|
|
|
|
|
|
|
songVO.setLyric(song.getLyric());
|
|
|
|
|
|
|
|
list.add(songVO);
|
|
|
|
list.add(songVO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 更新期刊
|
|
|
|
* 更新期刊
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @param token
|
|
|
|
* @param param
|
|
|
|
* @param param
|
|
|
|
* @param image
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result update(String id, JournalAddModel param, MultipartFile image) {
|
|
|
|
public Result update(String id, String token, JournalAddModel param) {
|
|
|
|
Journal journal = buildJournal(id, param);
|
|
|
|
List<Journal> byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
|
|
|
|
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
|
|
|
|
return Result.failed("更新失败,期刊编号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Journal journal = buildJournal(id, param, token);
|
|
|
|
Journal oldJournal = journalDao.findById(id).get();
|
|
|
|
Journal oldJournal = journalDao.findById(id).get();
|
|
|
|
boolean bool = UploadUtil.fileHasChanged(oldJournal.getCoverPhoto(), image);
|
|
|
|
String image = null;
|
|
|
|
if (bool) {
|
|
|
|
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
|
|
|
|
String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR);
|
|
|
|
image = moveJournalImage(param);
|
|
|
|
journal.setCoverPhoto(imagePath);
|
|
|
|
if (StringUtils.isBlank(image)) {
|
|
|
|
|
|
|
|
Result.failed("更新失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
journal.setImage(image);
|
|
|
|
journalDao.save(journal);
|
|
|
|
journalDao.save(journal);
|
|
|
|
batchDeleteJournalRelatesInfo(id);
|
|
|
|
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除期刊的标签、音乐信息
|
|
|
|
* 删除期刊的标签、音乐信息
|
|
|
|
* @param id
|
|
|
|
* @param journalId
|
|
|
|
|
|
|
|
* @param journalNo
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void batchDeleteJournalRelatesInfo(String id) {
|
|
|
|
private void batchDeleteJournalRelatesInfo(String journalId, String journalNo) {
|
|
|
|
journalTagDao.deleteByJournalId(id);
|
|
|
|
journalTagDao.deleteByJournalId(journalId);
|
|
|
|
journalSongDao.deleteByJournalId(id);
|
|
|
|
journalSongDao.deleteByJournalNo(journalNo);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -340,7 +391,7 @@ public class CMSJournalService {
|
|
|
|
if ("1".equals(scheduled)) {
|
|
|
|
if ("1".equals(scheduled)) {
|
|
|
|
if (StringUtils.isNotBlank(pubTimeStr)){
|
|
|
|
if (StringUtils.isNotBlank(pubTimeStr)){
|
|
|
|
pubTime = LocalDateTime.parse(pubTimeStr, formatter);
|
|
|
|
pubTime = LocalDateTime.parse(pubTimeStr, formatter);
|
|
|
|
journalDao.updateScheduledPubById(id, scheduled, pubTime);
|
|
|
|
journalDao.updateScheduledPubById(id, pubTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
@ -364,8 +415,11 @@ public class CMSJournalService {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result deleteById(String id) {
|
|
|
|
public Result deleteById(String id) {
|
|
|
|
|
|
|
|
Journal journal = journalDao.findById(id).get();
|
|
|
|
|
|
|
|
if (!Objects.isNull(journal)) {
|
|
|
|
journalDao.deleteById(id);
|
|
|
|
journalDao.deleteById(id);
|
|
|
|
batchDeleteJournalRelatesInfo(id);
|
|
|
|
batchDeleteJournalRelatesInfo(id, journal.getJournalNo());
|
|
|
|
|
|
|
|
}
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|