|
|
@ -1,9 +1,12 @@
|
|
|
|
package com.luoo.music.service;
|
|
|
|
package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dao.SongDao;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
|
|
|
|
import dto.MusicPointDto;
|
|
|
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
|
|
|
import exception.BizException;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
@ -12,12 +15,14 @@ import org.springframework.data.domain.PageRequest;
|
|
|
|
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 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.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
@ -30,11 +35,28 @@ public class SongService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IdWorker idWorker;
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private JournalSongDao journalSongDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SongInfoDao songInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ArtistAlbumSongDao artistAlbumSongDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ArtistAlbumDao artistAlbumDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询全部列表
|
|
|
|
* 查询全部列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public List<Song> findAll(){
|
|
|
|
public List<Song> findAll() {
|
|
|
|
return songDao.findAll();
|
|
|
|
return songDao.findAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -44,13 +66,14 @@ public class SongService {
|
|
|
|
|
|
|
|
|
|
|
|
public Page<Song> findSearch(Map whereMap, int page, int size) {
|
|
|
|
public Page<Song> findSearch(Map whereMap, int page, int size) {
|
|
|
|
Specification<Song> specification = createSpecification(whereMap);
|
|
|
|
Specification<Song> specification = createSpecification(whereMap);
|
|
|
|
PageRequest pageRequest = PageRequest.of(page-1, size);
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
return songDao.findAll(specification, pageRequest);
|
|
|
|
return songDao.findAll(specification, pageRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 条件查询
|
|
|
|
* 条件查询
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param whereMap
|
|
|
|
* @param whereMap
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -62,44 +85,49 @@ public class SongService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据ID查询实体
|
|
|
|
* 根据ID查询实体
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Cacheable(value = "song",key = "#id")
|
|
|
|
@Cacheable(value = "song", key = "#id")
|
|
|
|
public Song findById(String id) {
|
|
|
|
public Song findById(String id) {
|
|
|
|
return songDao.findById(id).get();
|
|
|
|
return songDao.findById(id).get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 增加
|
|
|
|
* 增加
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param song
|
|
|
|
* @param song
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void add(Song song) {
|
|
|
|
public void add(Song song) {
|
|
|
|
song.setId( idWorker.nextId()+"" );
|
|
|
|
song.setId(idWorker.nextId() + "");
|
|
|
|
songDao.save(song);
|
|
|
|
songDao.save(song);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 修改
|
|
|
|
* 修改
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param song
|
|
|
|
* @param song
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@CacheEvict(value = "song",key = "#song.id")
|
|
|
|
@CacheEvict(value = "song", key = "#song.id")
|
|
|
|
public void update(Song song) {
|
|
|
|
public void update(Song song) {
|
|
|
|
songDao.save(song);
|
|
|
|
songDao.save(song);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除
|
|
|
|
* 删除
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@CacheEvict(value = "song",key = "#id")
|
|
|
|
@CacheEvict(value = "song", key = "#id")
|
|
|
|
public void deleteById(String id) {
|
|
|
|
public void deleteById(String id) {
|
|
|
|
songDao.deleteById(id);
|
|
|
|
songDao.deleteById(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 动态条件构建
|
|
|
|
* 动态条件构建
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param searchMap
|
|
|
|
* @param searchMap
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -111,38 +139,39 @@ public class SongService {
|
|
|
|
public Predicate toPredicate(Root<Song> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
|
public Predicate toPredicate(Root<Song> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
// ID
|
|
|
|
// ID
|
|
|
|
if (searchMap.get("id")!=null && !"".equals(searchMap.get("id"))) {
|
|
|
|
if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) {
|
|
|
|
predicateList.add(cb.like(root.get("id").as(String.class), "%"+(String)searchMap.get("id")+"%"));
|
|
|
|
predicateList.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 专栏ID
|
|
|
|
// 专栏ID
|
|
|
|
if (searchMap.get("name")!=null && !"".equals(searchMap.get("name"))) {
|
|
|
|
if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) {
|
|
|
|
predicateList.add(cb.like(root.get("name").as(String.class), "%"+(String)searchMap.get("name")+"%"));
|
|
|
|
predicateList.add(cb.like(root.get("name").as(String.class), "%" + (String) searchMap.get("name") + "%"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 用户ID
|
|
|
|
// 用户ID
|
|
|
|
if (searchMap.get("artist")!=null && !"".equals(searchMap.get("artist"))) {
|
|
|
|
if (searchMap.get("artist") != null && !"".equals(searchMap.get("artist"))) {
|
|
|
|
predicateList.add(cb.like(root.get("artist").as(String.class), "%"+(String)searchMap.get("artist")+"%"));
|
|
|
|
predicateList.add(cb.like(root.get("artist").as(String.class), "%" + (String) searchMap.get("artist") + "%"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 剘刊号
|
|
|
|
// 剘刊号
|
|
|
|
if (searchMap.get("volid")!=null && !"".equals(searchMap.get("volid"))) {
|
|
|
|
if (searchMap.get("volid") != null && !"".equals(searchMap.get("volid"))) {
|
|
|
|
predicateList.add(cb.like(root.get("volid").as(String.class), "%"+(String)searchMap.get("volid")+"%"));
|
|
|
|
predicateList.add(cb.like(root.get("volid").as(String.class), "%" + (String) searchMap.get("volid") + "%"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 标题
|
|
|
|
// 标题
|
|
|
|
if (searchMap.get("album")!=null && !"".equals(searchMap.get("album"))) {
|
|
|
|
if (searchMap.get("album") != null && !"".equals(searchMap.get("album"))) {
|
|
|
|
predicateList.add(cb.like(root.get("album").as(String.class), "%"+(String)searchMap.get("album")+"%"));
|
|
|
|
predicateList.add(cb.like(root.get("album").as(String.class), "%" + (String) searchMap.get("album") + "%"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 文章正文
|
|
|
|
// 文章正文
|
|
|
|
if (searchMap.get("url")!=null && !"".equals(searchMap.get("url"))) {
|
|
|
|
if (searchMap.get("url") != null && !"".equals(searchMap.get("url"))) {
|
|
|
|
predicateList.add(cb.like(root.get("url").as(String.class), "%"+(String)searchMap.get("url")+"%"));
|
|
|
|
predicateList.add(cb.like(root.get("url").as(String.class), "%" + (String) searchMap.get("url") + "%"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public List<Song> findByVolid(String volid){
|
|
|
|
|
|
|
|
|
|
|
|
public List<Song> findByVolid(String volid) {
|
|
|
|
return songDao.findSongsByVolid(volid);
|
|
|
|
return songDao.findSongsByVolid(volid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -153,4 +182,42 @@ public class SongService {
|
|
|
|
public List<Song> orderByField(List<String> objectIds) {
|
|
|
|
public List<Song> orderByField(List<String> objectIds) {
|
|
|
|
return songDao.orderByField(objectIds);
|
|
|
|
return songDao.orderByField(objectIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 听歌埋点
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token 登录token
|
|
|
|
|
|
|
|
* @param musicPoint 音乐埋点对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void musicPoint(String token, MusicPointDto musicPoint) {
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
|
|
musicPoint.setUserId(user.getUserId());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
musicPoint.set_id(idWorker.nextId() + "");
|
|
|
|
|
|
|
|
SongInfo songById = songInfoDao.getSongById(musicPoint.getSongId());
|
|
|
|
|
|
|
|
musicPoint.setSongName(songById.getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JournalSong> bySongId = journalSongDao.findBySongId(musicPoint.getSongId());
|
|
|
|
|
|
|
|
if (!bySongId.isEmpty()) {
|
|
|
|
|
|
|
|
musicPoint.setJournalId(bySongId.get(0).getJournalNoSongId());
|
|
|
|
|
|
|
|
musicPoint.setJournalImage(bySongId.get(0).getImage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ArtistAlbumSong> artistAlbumSongList = artistAlbumSongDao.findAllBySongId(musicPoint.getSongId());
|
|
|
|
|
|
|
|
if (!artistAlbumSongList.isEmpty()) {
|
|
|
|
|
|
|
|
musicPoint.setAlbumId(artistAlbumSongList.get(0).getAlbumId());
|
|
|
|
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(artistAlbumSongList.get(0).getAlbumId()).get();
|
|
|
|
|
|
|
|
musicPoint.setAlbumName(artistAlbum.getName());
|
|
|
|
|
|
|
|
musicPoint.setArtistId(artistAlbum.getArtistId());
|
|
|
|
|
|
|
|
musicPoint.setArtistName(artistAlbum.getArtistName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
musicPoint.setEventTime(new Date());
|
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend("musicPoint",musicPoint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|