1.update app song info from journal song

main
Gary 9 months ago
parent 96dc30f219
commit 920af3ab67

@ -63,8 +63,7 @@ public class SaticScheduleTask {
addIKKeyWord(j.getJournalNo()); addIKKeyWord(j.getJournalNo());
addIKKeyWord(j.getTitle()); addIKKeyWord(j.getTitle());
}); });
List<String> journalNos = validJournals.stream().map(Journal::getJournalNo).collect(Collectors.toList()); journalSongDao.findAll().parallelStream().forEach(s -> {
journalSongDao.findByJournalNoIn(journalNos).parallelStream().forEach(s -> {
addIKKeyWord(s.getName()); addIKKeyWord(s.getName());
addIKKeyWord(s.getArtist()); addIKKeyWord(s.getArtist());
addIKKeyWord(s.getAlbum()); addIKKeyWord(s.getAlbum());

@ -1,7 +1,6 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -11,24 +10,20 @@ import com.luoo.music.dto.request.AutoCompleteReq;
import com.luoo.music.dto.request.FuzzySearchReq; import com.luoo.music.dto.request.FuzzySearchReq;
import com.luoo.music.dto.response.JournalRespDTO; import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SearchCategoryDTO; import com.luoo.music.dto.response.SearchCategoryDTO;
import com.luoo.music.dto.response.SearchResultDTO;
import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.SongRespDTO;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils; 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.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal; 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 com.luoo.music.pojo.Tag; import com.luoo.music.pojo.Tag;
import com.luoo.music.service.JournalService; import com.luoo.music.service.JournalService;
import com.luoo.music.service.JournalSongService; import com.luoo.music.service.JournalSongService;
import com.luoo.music.service.SearchService; import com.luoo.music.service.SearchService;
import com.luoo.music.service.SongInfoService;
import com.luoo.music.service.TagService; import com.luoo.music.service.TagService;
import annotation.GlobalInterceptor; import annotation.GlobalInterceptor;
import annotation.VerifyParam; import annotation.VerifyParam;
@ -52,7 +47,7 @@ public class SearchController {
private JournalService journalService; private JournalService journalService;
@Autowired @Autowired
private SongInfoService songInfoService; private JournalSongService journalSongService;
@Autowired @Autowired
private SearchService searchService; private SearchService searchService;
@ -78,7 +73,7 @@ public class SearchController {
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException { @VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize())); PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
List<SongInfo> pageResults=songInfoService.fuzzySearch(query.getKeyword(),pageRequest); List<JournalSong> pageResults=journalSongService.fuzzySearch(query.getKeyword(),pageRequest);
List<SongRespDTO> list = pageResults.stream().map(SongMapper::getSongRespDTO) List<SongRespDTO> list = pageResults.stream().map(SongMapper::getSongRespDTO)
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<SongRespDTO>(Long.valueOf(list.size()), list));

@ -56,4 +56,7 @@ public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSp
@Query(value = "select * from tb_journal_song where journal_no_song_id = ?1", nativeQuery = true) @Query(value = "select * from tb_journal_song where journal_no_song_id = ?1", nativeQuery = true)
JournalSong findByJournalNoSongId(String id); JournalSong findByJournalNoSongId(String id);
@Query(value = "select * from tb_journal_song where match(name, artist, album) against(?1 IN BOOLEAN MODE) limit ?2,?3 ", nativeQuery = true)
List<JournalSong> fuzzySearch(String keyword,int offset, int limit);
} }

@ -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()]));
}
};
}
} }

@ -34,31 +34,4 @@ public class SongInfoService {
public SongInfo findById(String id) { public SongInfo findById(String id) {
return songInfoDao.getSongById(id); return songInfoDao.getSongById(id);
} }
public List<SongInfo> fuzzySearch(String keyword, PageRequest pageRequest) {
if(keyword.length()==1) {
return searchByLike(keyword,pageRequest);
}
return songInfoDao.fuzzySearch("+\""+keyword+"\"", pageRequest.getPageNumber()*pageRequest.getPageSize(), pageRequest.getPageSize());
}
private List<SongInfo> searchByLike(String keyword, PageRequest pageRequest) {
Specification<SongInfo> specification = fuzzySpecification(keyword);
return songInfoDao.findAll(specification,pageRequest).getContent();
}
private Specification<SongInfo> fuzzySpecification(String keyword) {
return new Specification<SongInfo>() {
private static final long serialVersionUID = 1L;
@Override
public Predicate toPredicate(Root<SongInfo> 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()]));
}
};
}
} }

Loading…
Cancel
Save