|
|
|
@ -5,13 +5,14 @@ import api.Result;
|
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
|
import com.luoo.music.request.cms.JournalAddModel;
|
|
|
|
|
import com.luoo.music.request.cms.JournalPublishReq;
|
|
|
|
|
import com.luoo.music.request.cms.JournalQueryModel;
|
|
|
|
|
import com.luoo.music.response.cms.JournalVO;
|
|
|
|
|
import com.luoo.music.response.cms.SongVO;
|
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
|
import com.luoo.music.util.UploadUtil;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
@ -26,9 +27,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -55,8 +54,6 @@ public class CMSJournalService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页 + 条件检索
|
|
|
|
@ -93,15 +90,15 @@ public class CMSJournalService {
|
|
|
|
|
response.setJournalNo(Constants.JOURNAL_NO_PREF + item.getJournalNo());
|
|
|
|
|
response.setTitle(item.getTitle());
|
|
|
|
|
response.setImage(item.getImage());
|
|
|
|
|
response.setCreateTime(item.getCreateTime().format(formatter));
|
|
|
|
|
response.setCreateTime(item.getCreateTime().format(Constants.formatter));
|
|
|
|
|
response.setState(item.getState());
|
|
|
|
|
response.setIsPublish(item.getIsPublish());
|
|
|
|
|
if (!Objects.isNull(item.getPubTime())) {
|
|
|
|
|
response.setPubTime(item.getPubTime().format(formatter));
|
|
|
|
|
response.setPubTime(item.getPubTime().format(Constants.formatter));
|
|
|
|
|
}
|
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
|
response.setSongCount(songCountMap.get(item.getId()));
|
|
|
|
|
response.setSongCount(songCountMap.get(item.getJournalNo()));
|
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
|
response.setVisits(item.getVisits());
|
|
|
|
|
response.setComment(item.getComment());
|
|
|
|
@ -157,8 +154,11 @@ public class CMSJournalService {
|
|
|
|
|
private Map<String, Long> songCountInfo(List<String> journalNos) {
|
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
|
if (!CollectionUtils.isEmpty(journalNos)) {
|
|
|
|
|
List<JournalSongCount> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
|
|
|
|
|
songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalNo, JournalSongCount::getSongCount));
|
|
|
|
|
List<Map<String, Long>> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
|
|
|
|
|
songCountMap = journalSongCountList.stream()
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
map -> String.valueOf(map.get("journalNo")),
|
|
|
|
|
map -> Long.valueOf(String.valueOf(map.get("songCount")))));
|
|
|
|
|
}
|
|
|
|
|
return songCountMap;
|
|
|
|
|
}
|
|
|
|
@ -201,7 +201,8 @@ public class CMSJournalService {
|
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
|
return Result.failed("保存失败,期刊编号已存在");
|
|
|
|
|
}
|
|
|
|
|
String image = moveJournalImage(param);
|
|
|
|
|
String srcKey = param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX));
|
|
|
|
|
String image = moveJournalImage(srcKey, param);
|
|
|
|
|
if (StringUtils.isNotBlank(image)) {
|
|
|
|
|
Journal journal = buildJournal(null, param, token);
|
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
@ -220,11 +221,10 @@ public class CMSJournalService {
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String moveJournalImage(JournalAddModel param) {
|
|
|
|
|
private String moveJournalImage(String srcKey, 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 destKeySuffix = String.format("%05d/00%s", param.getJournalNo(), suffix);
|
|
|
|
|
String destKeySuffix = String.format("%05d/00%s", Integer.parseInt(param.getJournalNo()), suffix);
|
|
|
|
|
String destKey = Constants.IMAGE_KEY_PREFIX + destKeySuffix;
|
|
|
|
|
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
|
|
|
|
|
if (copy > 0) {
|
|
|
|
@ -248,10 +248,12 @@ public class CMSJournalService {
|
|
|
|
|
journal.setJournalNo(param.getJournalNo());
|
|
|
|
|
journal.setTitle(param.getTitle());
|
|
|
|
|
journal.setContent(param.getContent());
|
|
|
|
|
if (StringUtils.isNotBlank(token)) {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
journal.setUserId(user.getUserId());
|
|
|
|
|
journal.setUserName(user.getNickName());
|
|
|
|
|
journal.setUserType(user.getRoles());
|
|
|
|
|
}
|
|
|
|
|
return journal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -358,16 +360,28 @@ public class CMSJournalService {
|
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
|
return Result.failed("更新失败,期刊编号已存在");
|
|
|
|
|
}
|
|
|
|
|
Journal journal = buildJournal(id, param, token);
|
|
|
|
|
Journal oldJournal = journalDao.findById(id).get();
|
|
|
|
|
String image = null;
|
|
|
|
|
Journal journal = buildJournal(id, param, token);
|
|
|
|
|
String srcKey = null;
|
|
|
|
|
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
|
|
|
|
|
image = moveJournalImage(param);
|
|
|
|
|
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.IMAGE_KEY_PREFIX));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(srcKey)) {
|
|
|
|
|
String image = moveJournalImage(srcKey, param);
|
|
|
|
|
if (StringUtils.isBlank(image)) {
|
|
|
|
|
Result.failed("更新失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
journal.setImage(image);
|
|
|
|
|
}
|
|
|
|
|
journal.setState(oldJournal.getState());
|
|
|
|
|
journal.setIsPublish(oldJournal.getIsPublish());
|
|
|
|
|
journal.setIsScheduled(oldJournal.getIsScheduled());
|
|
|
|
|
journal.setVisits(oldJournal.getVisits());
|
|
|
|
|
journal.setComment(oldJournal.getComment());
|
|
|
|
|
journalDao.save(journal);
|
|
|
|
|
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
|
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
@ -387,19 +401,21 @@ public class CMSJournalService {
|
|
|
|
|
/**
|
|
|
|
|
* 发布期刊
|
|
|
|
|
* @param id
|
|
|
|
|
* @param scheduled
|
|
|
|
|
* @param pubTimeStr
|
|
|
|
|
* @param queryModel
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result publish(String id, String scheduled, String pubTimeStr) {
|
|
|
|
|
public Result publish(String id, JournalPublishReq queryModel) {
|
|
|
|
|
String scheduled = queryModel.getIsScheduled();
|
|
|
|
|
String pubTimeStr = queryModel.getPubTime();
|
|
|
|
|
LocalDateTime pubTime = LocalDateTime.now();
|
|
|
|
|
if ("1".equals(scheduled)) {
|
|
|
|
|
if (StringUtils.isNotBlank(pubTimeStr)){
|
|
|
|
|
pubTime = LocalDateTime.parse(pubTimeStr, formatter);
|
|
|
|
|
pubTime = LocalDateTime.parse(pubTimeStr, Constants.formatter);
|
|
|
|
|
journalDao.updateScheduledPubById(id, pubTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
|
|
}
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -411,7 +427,7 @@ public class CMSJournalService {
|
|
|
|
|
*/
|
|
|
|
|
public Result updateJournalState(String id, String state) {
|
|
|
|
|
journalDao.updateJournalState(id, state);
|
|
|
|
|
return Result.success("更新成功");
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|