|
|
|
@ -30,6 +30,7 @@ import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -38,449 +39,528 @@ import java.util.stream.Collectors;
|
|
|
|
|
@Service
|
|
|
|
|
public class CMSJournalService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private S3Service s3Service;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalTagDao journalTagDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalDao journalDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalSongDao journalSongDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TagDao tagDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SongInfoDao songDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserClient userClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
@Autowired
|
|
|
|
|
private S3Service s3Service;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalTagDao journalTagDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalDao journalDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalSongDao journalSongDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TagDao tagDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SongInfoDao songDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserClient userClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页 + 条件检索
|
|
|
|
|
* @param param
|
|
|
|
|
* @param page
|
|
|
|
|
* @param size
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result<PageResult<JournalVO>> search(JournalQueryModel param, int page, int size) {
|
|
|
|
|
List<JournalVO> result = new ArrayList<>();
|
|
|
|
|
/**
|
|
|
|
|
* 分页 + 条件检索
|
|
|
|
|
*
|
|
|
|
|
* @param param
|
|
|
|
|
* @param page
|
|
|
|
|
* @param size
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result<PageResult<JournalVO>> search(JournalQueryModel param, int page, int size) {
|
|
|
|
|
List<JournalVO> result = new ArrayList<>();
|
|
|
|
|
// Sort sort = new Sort(Sort.Direction.DESC, "journalNo");
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
Page<Journal> journalPage;
|
|
|
|
|
if (!Objects.isNull(param)) {
|
|
|
|
|
List<String> journalIdsByTags = null;
|
|
|
|
|
if (!CollectionUtils.isEmpty(param.getTags())) {
|
|
|
|
|
journalIdsByTags = journalTagDao.findJournalIdsByTags(param.getTags());
|
|
|
|
|
if (journalIdsByTags.size() == 0) {
|
|
|
|
|
return Result.success(new PageResult<>(0L, result));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Specification<Journal> journalSpecification = buildSearchSpecification(param, journalIdsByTags);
|
|
|
|
|
journalPage = journalDao.findAll(journalSpecification, pageRequest);
|
|
|
|
|
} else {
|
|
|
|
|
List<String> journalIdsByTags = null;
|
|
|
|
|
Specification<Journal> journalSpecification = buildSearchSpecification(param, journalIdsByTags);
|
|
|
|
|
journalPage = journalDao.findAll(journalSpecification,pageRequest);
|
|
|
|
|
}
|
|
|
|
|
long totalElements = journalPage.getTotalElements();
|
|
|
|
|
List<Journal> content = journalPage.getContent();
|
|
|
|
|
if (!CollectionUtils.isEmpty(content)) {
|
|
|
|
|
List<String> ids = content.stream().map(Journal::getId).collect(Collectors.toList());
|
|
|
|
|
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) {
|
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
|
response.setId(item.getId());
|
|
|
|
|
response.setJournalNo(item.getJournalNo());
|
|
|
|
|
response.setTitle(item.getTitle());
|
|
|
|
|
response.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage());
|
|
|
|
|
if (!Objects.isNull(item.getCreateTime())) {
|
|
|
|
|
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(Constants.formatter));
|
|
|
|
|
}
|
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
|
response.setSongCount(songCountMap.get(item.getJournalNo()));
|
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
|
response.setVisits(item.getVisits());
|
|
|
|
|
response.setComment(item.getComment());
|
|
|
|
|
result.add(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Result.success(new PageResult<>(totalElements, result));
|
|
|
|
|
}
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
Page<Journal> journalPage;
|
|
|
|
|
if (!Objects.isNull(param)) {
|
|
|
|
|
List<String> journalIdsByTags = null;
|
|
|
|
|
if (!CollectionUtils.isEmpty(param.getTags())) {
|
|
|
|
|
journalIdsByTags = journalTagDao.findJournalIdsByTags(param.getTags());
|
|
|
|
|
if (journalIdsByTags.size() == 0) {
|
|
|
|
|
return Result.success(new PageResult<>(0L, result));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Specification<Journal> journalSpecification = buildSearchSpecification(param, journalIdsByTags);
|
|
|
|
|
journalPage = journalDao.findAll(journalSpecification, pageRequest);
|
|
|
|
|
} else {
|
|
|
|
|
List<String> journalIdsByTags = null;
|
|
|
|
|
Specification<Journal> journalSpecification = buildSearchSpecification(param, journalIdsByTags);
|
|
|
|
|
journalPage = journalDao.findAll(journalSpecification, pageRequest);
|
|
|
|
|
}
|
|
|
|
|
long totalElements = journalPage.getTotalElements();
|
|
|
|
|
List<Journal> content = journalPage.getContent();
|
|
|
|
|
if (!CollectionUtils.isEmpty(content)) {
|
|
|
|
|
List<String> ids = content.stream().map(Journal::getId).collect(Collectors.toList());
|
|
|
|
|
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) {
|
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
|
response.setId(item.getId());
|
|
|
|
|
response.setJournalNo(item.getJournalNo());
|
|
|
|
|
response.setTitle(item.getTitle());
|
|
|
|
|
response.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage());
|
|
|
|
|
if (!Objects.isNull(item.getCreateTime())) {
|
|
|
|
|
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(Constants.formatter));
|
|
|
|
|
}
|
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
|
response.setSongCount(songCountMap.get(item.getJournalNo()));
|
|
|
|
|
response.setTag(journalTagMap.get(item.getId()));
|
|
|
|
|
response.setVisits(item.getVisits());
|
|
|
|
|
response.setComment(item.getComment());
|
|
|
|
|
result.add(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Result.success(new PageResult<>(totalElements, result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检索条件
|
|
|
|
|
*
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Specification<Journal> buildSearchSpecification(JournalQueryModel param, List<String> ids) {
|
|
|
|
|
return (Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
if ("1".equals(param.getTab())) {
|
|
|
|
|
predicateList.add(builder.equal(root.get("isPublish"), "1"));
|
|
|
|
|
} else if ("2".equals(param.getTab())) {
|
|
|
|
|
predicateList.add(builder.equal(root.get("state"), "0"));
|
|
|
|
|
} else {
|
|
|
|
|
Predicate state = builder.equal(root.get("state"), "1");
|
|
|
|
|
Predicate isPublish = builder.equal(root.get("isPublish"), "0");
|
|
|
|
|
predicateList.add(builder.and(state, isPublish));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(param.getUserId())) {
|
|
|
|
|
predicateList.add(builder.equal(root.get("userId"), param.getUserId()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(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)) {
|
|
|
|
|
predicateList.add(root.get("journalNo").in(ids));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(param.getKeyword())) {
|
|
|
|
|
String likeExpression = "%" + param.getKeyword() + "%";
|
|
|
|
|
Predicate journalNo = builder.like(root.get("journalNo"), likeExpression);
|
|
|
|
|
Predicate title = builder.like(root.get("title"), likeExpression);
|
|
|
|
|
predicateList.add(builder.or(journalNo, title));
|
|
|
|
|
}
|
|
|
|
|
query.orderBy(builder.desc(root.get("journalNo").as(Integer.class)));
|
|
|
|
|
return builder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 期刊的音乐数量
|
|
|
|
|
*
|
|
|
|
|
* @param journalNos
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Long> songCountInfo(List<String> journalNos) {
|
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
|
if (!CollectionUtils.isEmpty(journalNos)) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 期刊的标签信息
|
|
|
|
|
*
|
|
|
|
|
* @param ids
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, List<String>> tagInfo(List<String> ids) {
|
|
|
|
|
Map<String, List<String>> journalTagMap = new HashMap<>();
|
|
|
|
|
List<JournalTag> journalTagList = journalTagDao.findByJournalIds(ids);
|
|
|
|
|
Set<String> tagIdSet = journalTagList.stream().map(JournalTag::getTagId).collect(Collectors.toSet());
|
|
|
|
|
List<Tag> tagList = tagDao.findByIdIn(tagIdSet);
|
|
|
|
|
Map<String, Tag> idTagMap = tagList.stream().collect(Collectors.toMap(Tag::getId, obj -> obj));
|
|
|
|
|
List<String> list;
|
|
|
|
|
for (JournalTag item : journalTagList) {
|
|
|
|
|
String journalId = item.getJournalId();
|
|
|
|
|
if (journalTagMap.containsKey(journalId)) {
|
|
|
|
|
list = journalTagMap.get(journalId);
|
|
|
|
|
} else {
|
|
|
|
|
list = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
if (idTagMap.containsKey(item.getTagId())) {
|
|
|
|
|
Tag tag = idTagMap.get(item.getTagId());
|
|
|
|
|
list.add(tag.getId());
|
|
|
|
|
}
|
|
|
|
|
journalTagMap.put(journalId, list);
|
|
|
|
|
}
|
|
|
|
|
return journalTagMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增期刊
|
|
|
|
|
*
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result add(String token, JournalAddModel param) {
|
|
|
|
|
List<Journal> byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
|
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
|
return Result.failed("保存失败,期刊编号已存在");
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
journal.setId(id);
|
|
|
|
|
journal.setImage(image);
|
|
|
|
|
journalDao.save(journal);
|
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
|
return Result.success();
|
|
|
|
|
} else {
|
|
|
|
|
return Result.failed("保存失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 移动对象
|
|
|
|
|
*
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String moveJournalImage(String srcKey, JournalAddModel param) {
|
|
|
|
|
String image = param.getImage();
|
|
|
|
|
String suffix = image.substring(image.lastIndexOf(Constants.DOT));
|
|
|
|
|
String destKeySuffix = String.format("%05d/00%s", Integer.parseInt(param.getJournalNo()), suffix);
|
|
|
|
|
String destKey = Constants.MUSIC_KEY_PREFIX + destKeySuffix;
|
|
|
|
|
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
|
|
|
|
|
if (copy > 0) {
|
|
|
|
|
return destKeySuffix;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建对象
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param param
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Journal buildJournal(String id, JournalAddModel param, String token) {
|
|
|
|
|
Journal journal = new Journal();
|
|
|
|
|
if (!StringUtils.isBlank(id)) {
|
|
|
|
|
journal.setId(id);
|
|
|
|
|
}
|
|
|
|
|
journal.setJournalNo(param.getJournalNo());
|
|
|
|
|
journal.setTitle(param.getTitle());
|
|
|
|
|
journal.setContent(param.getContent());
|
|
|
|
|
UserInfo userInfo = userClient.queryUserInfoById(param.getUserId());
|
|
|
|
|
if (!Objects.isNull(userInfo)) {
|
|
|
|
|
journal.setUserId(userInfo.getId());
|
|
|
|
|
journal.setUserName(userInfo.getName());
|
|
|
|
|
journal.setUserType(userInfo.getType());
|
|
|
|
|
}
|
|
|
|
|
return journal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检索条件
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Specification<Journal> buildSearchSpecification(JournalQueryModel param, List<String> ids) {
|
|
|
|
|
return (Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
if("1".equals(param.getTab())) {
|
|
|
|
|
predicateList.add(builder.equal(root.get("isPublish"), "1"));
|
|
|
|
|
} else if ("2".equals(param.getTab())) {
|
|
|
|
|
predicateList.add(builder.equal(root.get("state"), "0"));
|
|
|
|
|
} else {
|
|
|
|
|
Predicate state = builder.equal(root.get("state"), "1");
|
|
|
|
|
Predicate isPublish = builder.equal(root.get("isPublish"), "0");
|
|
|
|
|
predicateList.add(builder.and(state, isPublish));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(param.getUserId())) {
|
|
|
|
|
predicateList.add(builder.equal(root.get("userId"), param.getUserId()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(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)) {
|
|
|
|
|
predicateList.add(root.get("journalNo").in(ids));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(param.getKeyword())) {
|
|
|
|
|
String likeExpression = "%" + param.getKeyword() + "%";
|
|
|
|
|
Predicate journalNo = builder.like(root.get("journalNo"), likeExpression);
|
|
|
|
|
Predicate title = builder.like(root.get("title"), likeExpression);
|
|
|
|
|
predicateList.add(builder.or(journalNo, title));
|
|
|
|
|
}
|
|
|
|
|
query.orderBy(builder.desc(root.get("journalNo").as(Integer.class)));
|
|
|
|
|
return builder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 保存期刊的标签、音乐信息
|
|
|
|
|
*
|
|
|
|
|
* @param journalId
|
|
|
|
|
* @param param
|
|
|
|
|
*/
|
|
|
|
|
private void batchSaveJournalRelatesInfo(String journalId, JournalAddModel param) {
|
|
|
|
|
// 标签信息
|
|
|
|
|
if (!CollectionUtils.isEmpty(param.getTag())) {
|
|
|
|
|
List<JournalTag> journalTagList = new ArrayList<>();
|
|
|
|
|
for (String item : param.getTag()) {
|
|
|
|
|
JournalTag journalTag = new JournalTag();
|
|
|
|
|
journalTag.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
journalTag.setJournalId(journalId);
|
|
|
|
|
journalTag.setTagId(item);
|
|
|
|
|
journalTagList.add(journalTag);
|
|
|
|
|
}
|
|
|
|
|
journalTagDao.saveAll(journalTagList);
|
|
|
|
|
}
|
|
|
|
|
// 歌曲信息
|
|
|
|
|
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<>();
|
|
|
|
|
int num = 0;
|
|
|
|
|
for (String item : param.getSongs()) {
|
|
|
|
|
if (idSongMap.containsKey(item)) {
|
|
|
|
|
num += 1;
|
|
|
|
|
SongInfo song = idSongMap.get(item);
|
|
|
|
|
JournalSong journalSong = new JournalSong();
|
|
|
|
|
journalSong.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
journalSong.setName(song.getName());
|
|
|
|
|
journalSong.setAlbum(song.getAlbum());
|
|
|
|
|
journalSong.setArtist(song.getArtist());
|
|
|
|
|
journalSong.setUrl(song.getUrl());
|
|
|
|
|
journalSong.setImage(song.getImage());
|
|
|
|
|
journalSong.setSongId(item);
|
|
|
|
|
journalSong.setJournalNo(param.getJournalNo());
|
|
|
|
|
journalSong.setSongNo(num);
|
|
|
|
|
journalSong.setSongId(song.getId());
|
|
|
|
|
journalSongList.add(journalSong);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s3Service.fromSongToMusic(journalSongList);
|
|
|
|
|
journalSongDao.saveAll(journalSongList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 期刊的音乐数量
|
|
|
|
|
* @param journalNos
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Long> songCountInfo(List<String> journalNos) {
|
|
|
|
|
Map<String, Long> songCountMap = new HashMap<>();
|
|
|
|
|
if (!CollectionUtils.isEmpty(journalNos)) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 查询期刊详情
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result<JournalVO> findOne(String id) {
|
|
|
|
|
Optional<Journal> optional=journalDao.findById(id);
|
|
|
|
|
if(!optional.isPresent()) {
|
|
|
|
|
return Result.failed("无法找到期刊: "+id);
|
|
|
|
|
}
|
|
|
|
|
Journal journal = optional.get();
|
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
|
response.setId(journal.getId());
|
|
|
|
|
response.setJournalNo(journal.getJournalNo());
|
|
|
|
|
response.setTitle(journal.getTitle());
|
|
|
|
|
response.setTag(journalTagDao.findTagsByJournalId(id));
|
|
|
|
|
response.setUserId(journal.getUserId());
|
|
|
|
|
if (StringUtils.isNotBlank(journal.getImage())) {
|
|
|
|
|
response.setImage(Constants.MUSIC_RESOURCE_PREFIX + journal.getImage());
|
|
|
|
|
}
|
|
|
|
|
response.setSongs(journalSongInfo(journal.getJournalNo()));
|
|
|
|
|
response.setContent(journal.getContent());
|
|
|
|
|
return Result.success(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 期刊的标签信息
|
|
|
|
|
* @param ids
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, List<String>> tagInfo(List<String> ids) {
|
|
|
|
|
Map<String, List<String>> journalTagMap = new HashMap<>();
|
|
|
|
|
List<JournalTag> journalTagList = journalTagDao.findByJournalIds(ids);
|
|
|
|
|
Set<String> tagIdSet = journalTagList.stream().map(JournalTag::getTagId).collect(Collectors.toSet());
|
|
|
|
|
List<Tag> tagList = tagDao.findByIdIn(tagIdSet);
|
|
|
|
|
Map<String, Tag> idTagMap = tagList.stream().collect(Collectors.toMap(Tag::getId, obj -> obj));
|
|
|
|
|
List<String> list;
|
|
|
|
|
for (JournalTag item : journalTagList) {
|
|
|
|
|
String journalId = item.getJournalId();
|
|
|
|
|
if (journalTagMap.containsKey(journalId)) {
|
|
|
|
|
list = journalTagMap.get(journalId);
|
|
|
|
|
} else {
|
|
|
|
|
list = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
if (idTagMap.containsKey(item.getTagId())) {
|
|
|
|
|
Tag tag = idTagMap.get(item.getTagId());
|
|
|
|
|
list.add(tag.getId());
|
|
|
|
|
}
|
|
|
|
|
journalTagMap.put(journalId, list);
|
|
|
|
|
}
|
|
|
|
|
return journalTagMap;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 期刊的音乐信息
|
|
|
|
|
*
|
|
|
|
|
* @param journalNo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<SongVO> journalSongInfo(String journalNo) {
|
|
|
|
|
List<SongVO> list = new ArrayList<>();
|
|
|
|
|
List<JournalSong> journalSongList = journalSongDao.findByJournalNo(journalNo);
|
|
|
|
|
if (!CollectionUtils.isEmpty(journalSongList)) {
|
|
|
|
|
for (JournalSong item : journalSongList) {
|
|
|
|
|
SongVO songVO = new SongVO();
|
|
|
|
|
songVO.setId(item.getSongId());
|
|
|
|
|
songVO.setName(item.getName());
|
|
|
|
|
songVO.setArtist(item.getArtist());
|
|
|
|
|
songVO.setAlbum(item.getAlbum());
|
|
|
|
|
if (StringUtils.isNotBlank(item.getUrl())) {
|
|
|
|
|
songVO.setUrl(Constants.RESOURCE_PREFIX + item.getUrl());
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(item.getImage())) {
|
|
|
|
|
songVO.setImage(Constants.RESOURCE_PREFIX + item.getImage());
|
|
|
|
|
}
|
|
|
|
|
list.add(songVO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增期刊
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result add(String token, JournalAddModel param) {
|
|
|
|
|
List<Journal> byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
|
|
|
|
|
if (byJournalNo.size() > 0) {
|
|
|
|
|
return Result.failed("保存失败,期刊编号已存在");
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
journal.setId(id);
|
|
|
|
|
journal.setImage(image);
|
|
|
|
|
journalDao.save(journal);
|
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
|
return Result.success();
|
|
|
|
|
} else {
|
|
|
|
|
return Result.failed("保存失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 更新期刊
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param token
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result update(String id, String token, JournalAddModel param) {
|
|
|
|
|
Optional<Journal> optional = journalDao.findById(id);
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
return Result.failed("找不到期刊: " + id);
|
|
|
|
|
}
|
|
|
|
|
Journal journal = optional.get();
|
|
|
|
|
updateJournal(journal, param, token);
|
|
|
|
|
journalDao.save(journal);
|
|
|
|
|
redisTemplate.opsForValue().set("journal_" + id, journal);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 移动对象
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String moveJournalImage(String srcKey, JournalAddModel param) {
|
|
|
|
|
String image = param.getImage();
|
|
|
|
|
String suffix = image.substring(image.lastIndexOf(Constants.DOT));
|
|
|
|
|
String destKeySuffix = String.format("%05d/00%s", Integer.parseInt(param.getJournalNo()), suffix);
|
|
|
|
|
String destKey = Constants.MUSIC_KEY_PREFIX + destKeySuffix;
|
|
|
|
|
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
|
|
|
|
|
if (copy > 0) {
|
|
|
|
|
return destKeySuffix;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
batchUpdateJournalRelatesInfo(id, journal.getJournalNo(), param);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建对象
|
|
|
|
|
* @param id
|
|
|
|
|
* @param param
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Journal buildJournal(String id, JournalAddModel param, String token) {
|
|
|
|
|
Journal journal = new Journal();
|
|
|
|
|
if (!StringUtils.isBlank(id)) {
|
|
|
|
|
journal.setId(id);
|
|
|
|
|
}
|
|
|
|
|
journal.setJournalNo(param.getJournalNo());
|
|
|
|
|
journal.setTitle(param.getTitle());
|
|
|
|
|
journal.setContent(param.getContent());
|
|
|
|
|
UserInfo userInfo = userClient.queryUserInfoById(param.getUserId());
|
|
|
|
|
if (!Objects.isNull(userInfo)) {
|
|
|
|
|
journal.setUserId(userInfo.getId());
|
|
|
|
|
journal.setUserName(userInfo.getName());
|
|
|
|
|
journal.setUserType(userInfo.getType());
|
|
|
|
|
}
|
|
|
|
|
return journal;
|
|
|
|
|
}
|
|
|
|
|
private void batchUpdateJournalRelatesInfo(String journalId, String journalNo, JournalAddModel param) {
|
|
|
|
|
// 标签信息
|
|
|
|
|
List<String> updateTags = param.getTag();
|
|
|
|
|
List<String> currentTags = journalTagDao.findTagsByJournalId(journalId);
|
|
|
|
|
if (!CollectionUtils.isEmpty(updateTags) && !isCollectionEqual(currentTags, updateTags)) {
|
|
|
|
|
// 清理当前journalTag
|
|
|
|
|
journalTagDao.deleteByJournalId(journalId);
|
|
|
|
|
List<JournalTag> updatedJournalTags = updateTags.stream().map(t -> createJournalTag(t, journalId))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
journalTagDao.saveAll(updatedJournalTags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 歌曲信息
|
|
|
|
|
List<String> updateSongs = param.getSongs();
|
|
|
|
|
if (!CollectionUtils.isEmpty(updateSongs)) {
|
|
|
|
|
// 清理当前journalSong
|
|
|
|
|
journalSongDao.deleteByJournalNo(journalId);
|
|
|
|
|
List<SongInfo> songList = songDao.orderByField(updateSongs);
|
|
|
|
|
List<JournalSong> updatedJournalSong = new ArrayList<>();
|
|
|
|
|
for (int i = 1; i < songList.size(); i++) {
|
|
|
|
|
SongInfo song = songList.get(i);
|
|
|
|
|
JournalSong journalSong = new JournalSong();
|
|
|
|
|
journalSong.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
journalSong.setName(song.getName());
|
|
|
|
|
journalSong.setAlbum(song.getAlbum());
|
|
|
|
|
journalSong.setArtist(song.getArtist());
|
|
|
|
|
journalSong.setUrl(Constants.SONG_KEY_PREFIX+song.getUrl());
|
|
|
|
|
journalSong.setImage(Constants.SONG_KEY_PREFIX+song.getImage());
|
|
|
|
|
journalSong.setLyricUrl(Constants.SONG_KEY_PREFIX+song.getLyricUrl());
|
|
|
|
|
journalSong.setSongId(song.getId());
|
|
|
|
|
journalSong.setJournalNo(journalNo);
|
|
|
|
|
journalSong.setSongNo(i);
|
|
|
|
|
|
|
|
|
|
updatedJournalSong.add(journalSong);
|
|
|
|
|
}
|
|
|
|
|
journalSongDao.saveAll(updatedJournalSong);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存期刊的标签、音乐信息
|
|
|
|
|
* @param journalId
|
|
|
|
|
* @param param
|
|
|
|
|
*/
|
|
|
|
|
private void batchSaveJournalRelatesInfo(String journalId, JournalAddModel param) {
|
|
|
|
|
// 标签信息
|
|
|
|
|
if (!CollectionUtils.isEmpty(param.getTag())) {
|
|
|
|
|
List<JournalTag> journalTagList = new ArrayList<>();
|
|
|
|
|
for (String item : param.getTag()) {
|
|
|
|
|
JournalTag journalTag = new JournalTag();
|
|
|
|
|
journalTag.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
journalTag.setJournalId(journalId);
|
|
|
|
|
journalTag.setTagId(item);
|
|
|
|
|
journalTagList.add(journalTag);
|
|
|
|
|
}
|
|
|
|
|
journalTagDao.saveAll(journalTagList);
|
|
|
|
|
}
|
|
|
|
|
// 歌曲信息
|
|
|
|
|
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<>();
|
|
|
|
|
int num = 0;
|
|
|
|
|
for (String item : param.getSongs()) {
|
|
|
|
|
if (idSongMap.containsKey(item)) {
|
|
|
|
|
num += 1;
|
|
|
|
|
SongInfo song = idSongMap.get(item);
|
|
|
|
|
JournalSong journalSong = new JournalSong();
|
|
|
|
|
journalSong.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
journalSong.setName(song.getName());
|
|
|
|
|
journalSong.setAlbum(song.getAlbum());
|
|
|
|
|
journalSong.setArtist(song.getArtist());
|
|
|
|
|
journalSong.setUrl(song.getUrl());
|
|
|
|
|
journalSong.setImage(song.getImage());
|
|
|
|
|
journalSong.setSongId(item);
|
|
|
|
|
journalSong.setJournalNo(param.getJournalNo());
|
|
|
|
|
journalSong.setSongNo(num);
|
|
|
|
|
journalSong.setSongId(song.getId());
|
|
|
|
|
journalSongList.add(journalSong);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s3Service.fromSongToMusic(journalSongList);
|
|
|
|
|
journalSongDao.saveAll(journalSongList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private JournalTag createJournalTag(String tagId, String journalId) {
|
|
|
|
|
JournalTag journalTag = new JournalTag();
|
|
|
|
|
journalTag.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
journalTag.setJournalId(journalId);
|
|
|
|
|
journalTag.setTagId(tagId);
|
|
|
|
|
return journalTag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询期刊详情
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result<JournalVO> findOne(String id) {
|
|
|
|
|
Journal journal = journalDao.findById(id).get();
|
|
|
|
|
JournalVO response = new JournalVO();
|
|
|
|
|
response.setId(journal.getId());
|
|
|
|
|
response.setJournalNo(journal.getJournalNo());
|
|
|
|
|
response.setTitle(journal.getTitle());
|
|
|
|
|
response.setTag(journalTagDao.findTagsByJournalId(id));
|
|
|
|
|
response.setUserId(journal.getUserId());
|
|
|
|
|
if (StringUtils.isNotBlank(journal.getImage())) {
|
|
|
|
|
response.setImage(Constants.MUSIC_RESOURCE_PREFIX + journal.getImage());
|
|
|
|
|
}
|
|
|
|
|
response.setSongs(journalSongInfo(journal.getJournalNo()));
|
|
|
|
|
response.setContent(journal.getContent());
|
|
|
|
|
return Result.success(response);
|
|
|
|
|
}
|
|
|
|
|
private boolean isCollectionEqual(List<String> current, List<String> update) {
|
|
|
|
|
if ((null == current && null == update) || (current.isEmpty() && update.isEmpty())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (current.size() != update.size()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Collections.sort(current);
|
|
|
|
|
Collections.sort(update);
|
|
|
|
|
for (int i = 0; i < current.size(); i++) {
|
|
|
|
|
if (!current.get(i).equals(update.get(i))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 期刊的音乐信息
|
|
|
|
|
* @param journalNo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<SongVO> journalSongInfo(String journalNo) {
|
|
|
|
|
List<SongVO> list = new ArrayList<>();
|
|
|
|
|
List<JournalSong> journalSongList = journalSongDao.findByJournalNo(journalNo);
|
|
|
|
|
if (!CollectionUtils.isEmpty(journalSongList)) {
|
|
|
|
|
for (JournalSong item : journalSongList) {
|
|
|
|
|
SongVO songVO = new SongVO();
|
|
|
|
|
songVO.setId(item.getSongId());
|
|
|
|
|
songVO.setName(item.getName());
|
|
|
|
|
songVO.setArtist(item.getArtist());
|
|
|
|
|
songVO.setAlbum(item.getAlbum());
|
|
|
|
|
if (StringUtils.isNotBlank(item.getUrl())) {
|
|
|
|
|
songVO.setUrl(Constants.MUSIC_RESOURCE_PREFIX + item.getUrl());
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(item.getImage())) {
|
|
|
|
|
songVO.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage());
|
|
|
|
|
}
|
|
|
|
|
list.add(songVO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
private void updateJournal(Journal journal, JournalAddModel param, String token) {
|
|
|
|
|
String title = param.getTitle();
|
|
|
|
|
if (!StringTools.isEmpty(title)) {
|
|
|
|
|
journal.setTitle(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新期刊
|
|
|
|
|
* @param id
|
|
|
|
|
* @param token
|
|
|
|
|
* @param param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result update(String id, String token, JournalAddModel param) {
|
|
|
|
|
Optional<Journal> optional = journalDao.findById(id);
|
|
|
|
|
if(!optional.isPresent()) {
|
|
|
|
|
return Result.failed("找不到期刊: "+id);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
if (!CollectionUtils.isEmpty(param.getSongs())) {
|
|
|
|
|
journalSongDao.deleteByJournalNo(id);
|
|
|
|
|
}
|
|
|
|
|
batchSaveJournalRelatesInfo(id, param);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
private void updateJournal(Journal journal, JournalAddModel param, String token) {
|
|
|
|
|
String title=param.getTitle();
|
|
|
|
|
if(!StringTools.isEmpty(title)) {
|
|
|
|
|
journal.setTitle(title);
|
|
|
|
|
}
|
|
|
|
|
String content = param.getContent();
|
|
|
|
|
if (!StringTools.isEmpty(content)) {
|
|
|
|
|
journal.setContent(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String content=param.getContent();
|
|
|
|
|
if(!StringTools.isEmpty(content)) {
|
|
|
|
|
journal.setContent(content);
|
|
|
|
|
}
|
|
|
|
|
String userId = param.getUserId();
|
|
|
|
|
if (!StringTools.isEmpty(userId)) {
|
|
|
|
|
UserInfo userInfo = userClient.queryUserInfoById(userId);
|
|
|
|
|
if (!Objects.isNull(userInfo)) {
|
|
|
|
|
journal.setUserId(userInfo.getId());
|
|
|
|
|
journal.setUserName(userInfo.getName());
|
|
|
|
|
journal.setUserType(userInfo.getType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String userId=param.getUserId();
|
|
|
|
|
if(!StringTools.isEmpty(userId)) {
|
|
|
|
|
UserInfo userInfo = userClient.queryUserInfoById(userId);
|
|
|
|
|
if (!Objects.isNull(userInfo)) {
|
|
|
|
|
journal.setUserId(userInfo.getId());
|
|
|
|
|
journal.setUserName(userInfo.getName());
|
|
|
|
|
journal.setUserType(userInfo.getType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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 = copyJournalImage(srcKey, journal.getJournalNo());
|
|
|
|
|
if (null != image) {
|
|
|
|
|
journal.setImage(image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 = 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 journalNo
|
|
|
|
|
*/
|
|
|
|
|
private void batchDeleteJournalRelatesInfo(String journalId, String journalNo) {
|
|
|
|
|
journalTagDao.deleteByJournalId(journalId);
|
|
|
|
|
journalSongDao.deleteByJournalNo(journalNo);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 删除期刊的标签、音乐信息
|
|
|
|
|
*
|
|
|
|
|
* @param journalId
|
|
|
|
|
* @param journalNo
|
|
|
|
|
*/
|
|
|
|
|
private void batchDeleteJournalRelatesInfo(String journalId, String journalNo) {
|
|
|
|
|
journalTagDao.deleteByJournalId(journalId);
|
|
|
|
|
journalSongDao.deleteByJournalNo(journalNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发布期刊
|
|
|
|
|
* @param id
|
|
|
|
|
* @param queryModel
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
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, Constants.formatter);
|
|
|
|
|
journalDao.updateScheduledPubById(id, pubTime);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
|
|
}
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 发布期刊
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param queryModel
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
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, Constants.formatter);
|
|
|
|
|
journalDao.updateScheduledPubById(id, pubTime);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
journalDao.updatePubById(id, pubTime);
|
|
|
|
|
}
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新期刊启停状态
|
|
|
|
|
* @param id
|
|
|
|
|
* @param state
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result updateJournalState(String id, String state) {
|
|
|
|
|
journalDao.updateJournalState(id, state);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 更新期刊启停状态
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param state
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result updateJournalState(String id, String state) {
|
|
|
|
|
journalDao.updateJournalState(id, state);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除期刊
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result deleteById(String id) {
|
|
|
|
|
Journal journal = journalDao.findById(id).get();
|
|
|
|
|
if (!Objects.isNull(journal)) {
|
|
|
|
|
journalDao.deleteById(id);
|
|
|
|
|
batchDeleteJournalRelatesInfo(id, journal.getJournalNo());
|
|
|
|
|
}
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 删除期刊
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result deleteById(String id) {
|
|
|
|
|
Journal journal = journalDao.findById(id).get();
|
|
|
|
|
if (!Objects.isNull(journal)) {
|
|
|
|
|
journalDao.deleteById(id);
|
|
|
|
|
batchDeleteJournalRelatesInfo(id, journal.getJournalNo());
|
|
|
|
|
}
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|