diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index 86fadff..4819535 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -12,6 +12,8 @@ public class Constants { public static final String J2CACHE_REGION_JOURNAL_QUERY_PAGE = "journal_query_page"; public static final String J2CACHE_REGION_JOURNAL_ID = "journal_id"; + public static final String J2CACHE_REGION_JOURNAL_SONG_KEY = "journal_song_key"; + public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT = "journal_comment_page_hot"; public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW = "journal_comment_page_new"; diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index e208887..c0dca71 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -45,8 +45,8 @@ public class SongController { private JournalSongService journalSongService; @Autowired private JournalService journalService; - @Autowired - private SongInfoService songInfoService; + //@Autowired + //private SongInfoService songInfoService; @Autowired private JwtUtil jwtUtil; @@ -71,7 +71,7 @@ public class SongController { return Result.unauthorized(null); } List songs = journalSongService.findByVolid(journalNo); - List ids=songs.stream().map(JournalSong::getSongId).collect(Collectors.toList()); + List ids=songs.stream().map(JournalSong::getJournalNoSongId).collect(Collectors.toList()); Set songCollectSet = null == user ? Collections.emptySet() : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG); List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) @@ -99,7 +99,7 @@ public class SongController { if (objectIds.isEmpty()) { return Result.success(new PageResult(0L, Collections.emptyList())); } - List songs = songInfoService.orderByField(objectIds); + List songs = journalSongService.orderByField(objectIds); Set songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource); List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) .collect(Collectors.toList()); @@ -131,10 +131,10 @@ public class SongController { public Result> random( @RequestHeader(value = "Authorization", required = false) String authorization, @PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) { - List songs = songInfoService.random(limit); + List songs = journalSongService.random(limit); UserLoginDto user = jwtUtil.getUserLoginDto(authorization); - List ids=songs.stream().map(SongInfo::getId).collect(Collectors.toList()); + List ids=songs.stream().map(JournalSong::getJournalNoSongId).collect(Collectors.toList()); Set songCollectSet = null == user ? Collections.emptySet() : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG); @@ -148,7 +148,7 @@ public class SongController { @GlobalInterceptor public Result findById(@RequestHeader(value = "Authorization", required = false) String authorization, @PathVariable @VerifyParam(required = true) String id) { - SongInfo song = songInfoService.findById(id); + JournalSong song = journalSongService.findByJournalNoSongId(id); if(null==song) { return Result.failed(StatusCode.MUSIC_COMMON_FAILED,"找不到歌曲, id: "+id); } 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 63e13c1..3484fd6 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 @@ -44,7 +44,7 @@ public interface JournalSongDao extends JpaRepository, JpaSp @Query(value = "select * from tb_journal_song order by rand() limit ?1 ", nativeQuery = true) List random(int limit); - @Query(value = "select * from tb_journal_song where id in ?1 order by field(id,?1)", nativeQuery = true) + @Query(value = "select * from tb_journal_song where journal_no_song_id in ?1 order by field(id,?1)", nativeQuery = true) public List orderByField(List idList); List findByJournalNoOrderBySongNo(String journalNo); @@ -53,4 +53,7 @@ public interface JournalSongDao extends JpaRepository, JpaSp List orderByJournalIdField(List jouranlIds); List findByJournalNoIn(List journalNos); + + @Query(value = "select * from tb_journal_song where journal_no_song_id = ?1", nativeQuery = true) + JournalSong findByJournalNoSongId(String id); } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/mapper/SongMapper.java b/luoo_music/src/main/java/com/luoo/music/dto/mapper/SongMapper.java index d2e37c7..93e17c4 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/mapper/SongMapper.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/mapper/SongMapper.java @@ -16,7 +16,7 @@ public class SongMapper { songRespDTO.setJournalNo(song.getJournalNo()); songRespDTO.setAlbum(song.getAlbum()); songRespDTO.setArtist(song.getArtist()); - songRespDTO.setId(song.getSongId()); + songRespDTO.setId(song.getJournalNoSongId()); songRespDTO.setTitle(song.getName()); songRespDTO.setSrc(Constants.RESOURCE_PREFIX + song.getUrl()); songRespDTO.setPic(Constants.RESOURCE_PREFIX + song.getImage()); 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 96a8ee0..f6aad8f 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 @@ -4,6 +4,10 @@ import com.luoo.music.dao.JournalSongDao; import com.luoo.music.dto.response.SearchCategoryDTO; import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.JournalSong; +import com.luoo.music.pojo.SongInfo; + +import constants.Constants; +import net.oschina.j2cache.CacheChannel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -30,6 +34,9 @@ public class JournalSongService { @Autowired private JournalSongDao journalSongDao; + @Autowired + private CacheChannel cacheChannel; + @Autowired private IdWorker idWorker; @@ -63,44 +70,6 @@ public class JournalSongService { } - /** - * 根据ID查询实体 - * @param id - * @return - */ - @Cacheable(value = "journalSong",key = "#id") - public JournalSong findById(String id) { - return journalSongDao.findById(id).get(); - } - - - - /** - * 增加 - * @param song - */ - public void add(JournalSong song) { - song.setId( idWorker.nextId()+"" ); - journalSongDao.save(song); - } - - /** - * 修改 - * @param song - */ - @CacheEvict(value = "journalSong",key = "#journalSong.id") - public void update(JournalSong song) { - journalSongDao.save(song); - } - - /** - * 删除 - * @param id - */ - @CacheEvict(value = "journalSong",key = "#id") - public void deleteById(String id) { - journalSongDao.deleteById(id); - } /** * 动态条件构建 * @param searchMap @@ -143,7 +112,6 @@ public class JournalSongService { } }; - } public List findByVolid(String journalNo){ return journalSongDao.findByJournalNo(journalNo); @@ -156,4 +124,8 @@ public class JournalSongService { public List orderByField(List objectIds) { return journalSongDao.orderByField(objectIds); } + + public JournalSong findByJournalNoSongId(String id) { + return (JournalSong) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, id, key -> journalSongDao.findByJournalNoSongId(id) , true).getValue() ; + } } diff --git a/luoo_music/src/main/resources/caffeine.properties b/luoo_music/src/main/resources/caffeine.properties index 71c0866..fc457eb 100644 --- a/luoo_music/src/main/resources/caffeine.properties +++ b/luoo_music/src/main/resources/caffeine.properties @@ -1,3 +1,4 @@ default: 1000, 2h journal_query_page: 10000, 6h -journal_id: 2000, 6h \ No newline at end of file +journal_id: 2000, 6h +journal_song_key: 10000, 6h \ No newline at end of file