|
|
@ -5,13 +5,14 @@ import api.Result;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
import com.luoo.music.request.cms.JournalAddModel;
|
|
|
|
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.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.Constants;
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
import com.luoo.music.util.UploadUtil;
|
|
|
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
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;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
@ -26,9 +27,7 @@ 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.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -55,8 +54,6 @@ public class CMSJournalService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
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.setJournalNo(Constants.JOURNAL_NO_PREF + item.getJournalNo());
|
|
|
|
response.setTitle(item.getTitle());
|
|
|
|
response.setTitle(item.getTitle());
|
|
|
|
response.setImage(item.getImage());
|
|
|
|
response.setImage(item.getImage());
|
|
|
|
response.setCreateTime(item.getCreateTime().format(formatter));
|
|
|
|
response.setCreateTime(item.getCreateTime().format(Constants.formatter));
|
|
|
|
response.setState(item.getState());
|
|
|
|
response.setState(item.getState());
|
|
|
|
response.setIsPublish(item.getIsPublish());
|
|
|
|
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(Constants.formatter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
response.setSongCount(songCountMap.get(item.getId()));
|
|
|
|
response.setSongCount(songCountMap.get(item.getJournalNo()));
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
response.setVisits(item.getVisits());
|
|
|
|
response.setVisits(item.getVisits());
|
|
|
|
response.setComment(item.getComment());
|
|
|
|
response.setComment(item.getComment());
|
|
|
@ -157,8 +154,11 @@ public class CMSJournalService {
|
|
|
|
private Map<String, Long> songCountInfo(List<String> journalNos) {
|
|
|
|
private Map<String, Long> songCountInfo(List<String> journalNos) {
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
if (!CollectionUtils.isEmpty(journalNos)) {
|
|
|
|
if (!CollectionUtils.isEmpty(journalNos)) {
|
|
|
|
List<JournalSongCount> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
|
|
|
|
List<Map<String, Long>> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
|
|
|
|
songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalNo, JournalSongCount::getSongCount));
|
|
|
|
songCountMap = journalSongCountList.stream()
|
|
|
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
|
|
|
map -> String.valueOf(map.get("journalNo")),
|
|
|
|
|
|
|
|
map -> Long.valueOf(String.valueOf(map.get("songCount")))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return songCountMap;
|
|
|
|
return songCountMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -201,7 +201,8 @@ public class CMSJournalService {
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
return Result.failed("保存失败,期刊编号已存在");
|
|
|
|
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)) {
|
|
|
|
if (StringUtils.isNotBlank(image)) {
|
|
|
|
Journal journal = buildJournal(null, param, token);
|
|
|
|
Journal journal = buildJournal(null, param, token);
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
@ -220,11 +221,10 @@ public class CMSJournalService {
|
|
|
|
* @param param
|
|
|
|
* @param param
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String moveJournalImage(JournalAddModel param) {
|
|
|
|
private String moveJournalImage(String srcKey, JournalAddModel param) {
|
|
|
|
String image = param.getImage();
|
|
|
|
String image = param.getImage();
|
|
|
|
String srcKey = image.substring(image.indexOf(Constants.TEMP_KEY_PREFIX));
|
|
|
|
|
|
|
|
String suffix = image.substring(image.lastIndexOf(Constants.DOT));
|
|
|
|
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;
|
|
|
|
String destKey = Constants.IMAGE_KEY_PREFIX + destKeySuffix;
|
|
|
|
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
|
|
|
|
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
|
|
|
|
if (copy > 0) {
|
|
|
|
if (copy > 0) {
|
|
|
@ -248,10 +248,12 @@ public class CMSJournalService {
|
|
|
|
journal.setJournalNo(param.getJournalNo());
|
|
|
|
journal.setJournalNo(param.getJournalNo());
|
|
|
|
journal.setTitle(param.getTitle());
|
|
|
|
journal.setTitle(param.getTitle());
|
|
|
|
journal.setContent(param.getContent());
|
|
|
|
journal.setContent(param.getContent());
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(token)) {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
journal.setUserId(user.getUserId());
|
|
|
|
journal.setUserId(user.getUserId());
|
|
|
|
journal.setUserName(user.getNickName());
|
|
|
|
journal.setUserName(user.getNickName());
|
|
|
|
journal.setUserType(user.getRoles());
|
|
|
|
journal.setUserType(user.getRoles());
|
|
|
|
|
|
|
|
}
|
|
|
|
return journal;
|
|
|
|
return journal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -358,16 +360,28 @@ public class CMSJournalService {
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
return Result.failed("更新失败,期刊编号已存在");
|
|
|
|
return Result.failed("更新失败,期刊编号已存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Journal journal = buildJournal(id, param, token);
|
|
|
|
|
|
|
|
Journal oldJournal = journalDao.findById(id).get();
|
|
|
|
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)) {
|
|
|
|
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)) {
|
|
|
|
if (StringUtils.isBlank(image)) {
|
|
|
|
Result.failed("更新失败");
|
|
|
|
Result.failed("更新失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
journal.setImage(image);
|
|
|
|
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);
|
|
|
|
journalDao.save(journal);
|
|
|
|
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
|
|
|
|
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
@ -387,19 +401,21 @@ public class CMSJournalService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 发布期刊
|
|
|
|
* 发布期刊
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
|
* @param scheduled
|
|
|
|
* @param queryModel
|
|
|
|
* @param pubTimeStr
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @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();
|
|
|
|
LocalDateTime pubTime = LocalDateTime.now();
|
|
|
|
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, Constants.formatter);
|
|
|
|
journalDao.updateScheduledPubById(id, pubTime);
|
|
|
|
journalDao.updateScheduledPubById(id, pubTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
|
|
|
|
|
}
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -411,7 +427,7 @@ public class CMSJournalService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result updateJournalState(String id, String state) {
|
|
|
|
public Result updateJournalState(String id, String state) {
|
|
|
|
journalDao.updateJournalState(id, state);
|
|
|
|
journalDao.updateJournalState(id, state);
|
|
|
|
return Result.success("更新成功");
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|