|
|
@ -2,35 +2,23 @@ package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dao.JournalSongDao;
|
|
|
|
import com.luoo.music.dao.JournalSongDao;
|
|
|
|
import com.luoo.music.dto.mapper.SongMapper;
|
|
|
|
import com.luoo.music.dto.mapper.SongMapper;
|
|
|
|
import com.luoo.music.dto.response.SearchCategoryDTO;
|
|
|
|
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
|
|
|
|
import com.luoo.music.pojo.JournalSong;
|
|
|
|
import com.luoo.music.pojo.JournalSong;
|
|
|
|
import com.luoo.music.pojo.SongInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
|
|
|
|
|
|
|
|
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.Cacheable;
|
|
|
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
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 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.Collection;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
@ -42,10 +30,6 @@ public class JournalSongService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private CacheChannel cacheChannel;
|
|
|
|
private CacheChannel cacheChannel;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询全部列表
|
|
|
|
* 查询全部列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -141,8 +125,34 @@ public class JournalSongService {
|
|
|
|
|
|
|
|
|
|
|
|
private List<SongRespDTO> getSongRespDTO(String journalNo) {
|
|
|
|
private List<SongRespDTO> getSongRespDTO(String journalNo) {
|
|
|
|
List<JournalSong> songs = findByVolid(journalNo);
|
|
|
|
List<JournalSong> songs = findByVolid(journalNo);
|
|
|
|
List<String> ids=songs.stream().map(JournalSong::getJournalNoSongId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return songs.stream().map(s -> SongMapper.getSongRespDTO(s))
|
|
|
|
return songs.stream().map(s -> SongMapper.getSongRespDTO(s))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<JournalSong> fuzzySearch(String keyword, PageRequest pageRequest) {
|
|
|
|
|
|
|
|
if(keyword.length()==1) {
|
|
|
|
|
|
|
|
return searchByLike(keyword,pageRequest);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return journalSongDao.fuzzySearch("+\""+keyword+"\"", pageRequest.getPageNumber()*pageRequest.getPageSize(), pageRequest.getPageSize());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<JournalSong> searchByLike(String keyword, PageRequest pageRequest) {
|
|
|
|
|
|
|
|
Specification<JournalSong> specification = fuzzySpecification(keyword);
|
|
|
|
|
|
|
|
return journalSongDao.findAll(specification,pageRequest).getContent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Specification<JournalSong> fuzzySpecification(String keyword) {
|
|
|
|
|
|
|
|
return new Specification<JournalSong>() {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Predicate toPredicate(Root<JournalSong> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("name").as(String.class),"%"+keyword+"%"));
|
|
|
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("artist").as(String.class),"%"+keyword+"%"));
|
|
|
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("album").as(String.class),"%"+keyword+"%"));
|
|
|
|
|
|
|
|
query.orderBy(criteriaBuilder.asc(root.get("name")));
|
|
|
|
|
|
|
|
return criteriaBuilder.or(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|