From 920af3ab671c533ed3899d2cc779ac7b84d05c60 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 4 Mar 2024 11:14:21 +0800 Subject: [PATCH] 1.update app song info from journal song --- .../luoo/music/config/SaticScheduleTask.java | 3 +- .../music/controller/SearchController.java | 11 ++--- .../com/luoo/music/dao/JournalSongDao.java | 3 ++ .../music/service/JournalSongService.java | 44 ++++++++++++------- .../luoo/music/service/SongInfoService.java | 27 ------------ 5 files changed, 34 insertions(+), 54 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java b/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java index 2f1b2ff..8b892e4 100644 --- a/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java +++ b/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java @@ -63,8 +63,7 @@ public class SaticScheduleTask { addIKKeyWord(j.getJournalNo()); addIKKeyWord(j.getTitle()); }); - List journalNos = validJournals.stream().map(Journal::getJournalNo).collect(Collectors.toList()); - journalSongDao.findByJournalNoIn(journalNos).parallelStream().forEach(s -> { + journalSongDao.findAll().parallelStream().forEach(s -> { addIKKeyWord(s.getName()); addIKKeyWord(s.getArtist()); addIKKeyWord(s.getAlbum()); diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java b/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java index a8a1453..a7268c6 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java @@ -1,7 +1,6 @@ package com.luoo.music.controller; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; 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.response.JournalRespDTO; import com.luoo.music.dto.response.SearchCategoryDTO; -import com.luoo.music.dto.response.SearchResultDTO; import com.luoo.music.dto.response.SongRespDTO; import io.swagger.annotations.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.JournalSong; -import com.luoo.music.pojo.SongInfo; import com.luoo.music.pojo.Tag; import com.luoo.music.service.JournalService; import com.luoo.music.service.JournalSongService; import com.luoo.music.service.SearchService; -import com.luoo.music.service.SongInfoService; import com.luoo.music.service.TagService; import annotation.GlobalInterceptor; import annotation.VerifyParam; @@ -50,9 +45,9 @@ public class SearchController { private static final int DEFAULT_AUTO_COMPLETE_LIMIT = 10; @Autowired private JournalService journalService; - + @Autowired - private SongInfoService songInfoService; + private JournalSongService journalSongService; @Autowired private SearchService searchService; @@ -78,7 +73,7 @@ public class SearchController { @VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException { PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize())); - List pageResults=songInfoService.fuzzySearch(query.getKeyword(),pageRequest); + List pageResults=journalSongService.fuzzySearch(query.getKeyword(),pageRequest); List list = pageResults.stream().map(SongMapper::getSongRespDTO) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java index 3484fd6..12dd828 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java @@ -56,4 +56,7 @@ public interface JournalSongDao extends JpaRepository, JpaSp @Query(value = "select * from tb_journal_song where journal_no_song_id = ?1", nativeQuery = true) 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 fuzzySearch(String keyword,int offset, int limit); } diff --git a/luoo_music/src/main/java/com/luoo/music/service/JournalSongService.java b/luoo_music/src/main/java/com/luoo/music/service/JournalSongService.java index 26a20b3..9fa2c23 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/JournalSongService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/JournalSongService.java @@ -2,35 +2,23 @@ package com.luoo.music.service; import com.luoo.music.dao.JournalSongDao; 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.pojo.Journal; import com.luoo.music.pojo.JournalSong; -import com.luoo.music.pojo.SongInfo; - import constants.Constants; -import enums.CollectTypeEnum; import net.oschina.j2cache.CacheChannel; 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.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; -import util.IdWorker; - import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; @Service @@ -42,10 +30,6 @@ public class JournalSongService { @Autowired private CacheChannel cacheChannel; - @Autowired - private IdWorker idWorker; - - /** * 查询全部列表 */ @@ -141,8 +125,34 @@ public class JournalSongService { private List getSongRespDTO(String journalNo) { List songs = findByVolid(journalNo); - List ids=songs.stream().map(JournalSong::getJournalNoSongId).collect(Collectors.toList()); return songs.stream().map(s -> SongMapper.getSongRespDTO(s)) .collect(Collectors.toList()); } + + public List 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 searchByLike(String keyword, PageRequest pageRequest) { + Specification specification = fuzzySpecification(keyword); + return journalSongDao.findAll(specification,pageRequest).getContent(); + } + + private Specification fuzzySpecification(String keyword) { + return new Specification() { + private static final long serialVersionUID = 1L; + @Override + public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { + List predicateList = new ArrayList(); + 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()])); + } + }; + } } diff --git a/luoo_music/src/main/java/com/luoo/music/service/SongInfoService.java b/luoo_music/src/main/java/com/luoo/music/service/SongInfoService.java index 197c8e1..62b3ee6 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/SongInfoService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/SongInfoService.java @@ -34,31 +34,4 @@ public class SongInfoService { public SongInfo findById(String id) { return songInfoDao.getSongById(id); } - - public List 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 searchByLike(String keyword, PageRequest pageRequest) { - Specification specification = fuzzySpecification(keyword); - return songInfoDao.findAll(specification,pageRequest).getContent(); - } - - private Specification fuzzySpecification(String keyword) { - return new Specification() { - private static final long serialVersionUID = 1L; - @Override - public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { - List predicateList = new ArrayList(); - 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()])); - } - }; - } }