1.update collect journal song relation

main
Gary 9 months ago
parent 31b975a593
commit 7217d20389

@ -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_QUERY_PAGE = "journal_query_page";
public static final String J2CACHE_REGION_JOURNAL_ID = "journal_id"; 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_HOT = "journal_comment_page_hot";
public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW = "journal_comment_page_new"; public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW = "journal_comment_page_new";

@ -45,8 +45,8 @@ public class SongController {
private JournalSongService journalSongService; private JournalSongService journalSongService;
@Autowired @Autowired
private JournalService journalService; private JournalService journalService;
@Autowired //@Autowired
private SongInfoService songInfoService; //private SongInfoService songInfoService;
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@ -71,7 +71,7 @@ public class SongController {
return Result.unauthorized(null); return Result.unauthorized(null);
} }
List<JournalSong> songs = journalSongService.findByVolid(journalNo); List<JournalSong> songs = journalSongService.findByVolid(journalNo);
List<String> ids=songs.stream().map(JournalSong::getSongId).collect(Collectors.toList()); List<String> ids=songs.stream().map(JournalSong::getJournalNoSongId).collect(Collectors.toList());
Set<String> songCollectSet = null == user ? Collections.emptySet() Set<String> songCollectSet = null == user ? Collections.emptySet()
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG); : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG);
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
@ -99,7 +99,7 @@ public class SongController {
if (objectIds.isEmpty()) { if (objectIds.isEmpty()) {
return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList())); return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList()));
} }
List<SongInfo> songs = songInfoService.orderByField(objectIds); List<JournalSong> songs = journalSongService.orderByField(objectIds);
Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource); Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource);
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -131,10 +131,10 @@ public class SongController {
public Result<List<SongRespDTO>> random( public Result<List<SongRespDTO>> random(
@RequestHeader(value = "Authorization", required = false) String authorization, @RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) { @PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
List<SongInfo> songs = songInfoService.random(limit); List<JournalSong> songs = journalSongService.random(limit);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
List<String> ids=songs.stream().map(SongInfo::getId).collect(Collectors.toList()); List<String> ids=songs.stream().map(JournalSong::getJournalNoSongId).collect(Collectors.toList());
Set<String> songCollectSet = null == user ? Collections.emptySet() Set<String> songCollectSet = null == user ? Collections.emptySet()
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG); : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG);
@ -148,7 +148,7 @@ public class SongController {
@GlobalInterceptor @GlobalInterceptor
public Result<SongRespDTO> findById(@RequestHeader(value = "Authorization", required = false) String authorization, public Result<SongRespDTO> findById(@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) { @PathVariable @VerifyParam(required = true) String id) {
SongInfo song = songInfoService.findById(id); JournalSong song = journalSongService.findByJournalNoSongId(id);
if(null==song) { if(null==song) {
return Result.failed(StatusCode.MUSIC_COMMON_FAILED,"找不到歌曲, id: "+id); return Result.failed(StatusCode.MUSIC_COMMON_FAILED,"找不到歌曲, id: "+id);
} }

@ -44,7 +44,7 @@ public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSp
@Query(value = "select * from tb_journal_song order by rand() limit ?1 ", nativeQuery = true) @Query(value = "select * from tb_journal_song order by rand() limit ?1 ", nativeQuery = true)
List<JournalSong> random(int limit); List<JournalSong> 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<JournalSong> orderByField(List<String> idList); public List<JournalSong> orderByField(List<String> idList);
List<JournalSong> findByJournalNoOrderBySongNo(String journalNo); List<JournalSong> findByJournalNoOrderBySongNo(String journalNo);
@ -53,4 +53,7 @@ public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSp
List<String> orderByJournalIdField(List<String> jouranlIds); List<String> orderByJournalIdField(List<String> jouranlIds);
List<JournalSong> findByJournalNoIn(List<String> journalNos); List<JournalSong> findByJournalNoIn(List<String> journalNos);
@Query(value = "select * from tb_journal_song where journal_no_song_id = ?1", nativeQuery = true)
JournalSong findByJournalNoSongId(String id);
} }

@ -16,7 +16,7 @@ public class SongMapper {
songRespDTO.setJournalNo(song.getJournalNo()); songRespDTO.setJournalNo(song.getJournalNo());
songRespDTO.setAlbum(song.getAlbum()); songRespDTO.setAlbum(song.getAlbum());
songRespDTO.setArtist(song.getArtist()); songRespDTO.setArtist(song.getArtist());
songRespDTO.setId(song.getSongId()); songRespDTO.setId(song.getJournalNoSongId());
songRespDTO.setTitle(song.getName()); songRespDTO.setTitle(song.getName());
songRespDTO.setSrc(Constants.RESOURCE_PREFIX + song.getUrl()); songRespDTO.setSrc(Constants.RESOURCE_PREFIX + song.getUrl());
songRespDTO.setPic(Constants.RESOURCE_PREFIX + song.getImage()); songRespDTO.setPic(Constants.RESOURCE_PREFIX + song.getImage());

@ -4,6 +4,10 @@ import com.luoo.music.dao.JournalSongDao;
import com.luoo.music.dto.response.SearchCategoryDTO; import com.luoo.music.dto.response.SearchCategoryDTO;
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 constants.Constants;
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.CacheEvict;
@ -30,6 +34,9 @@ public class JournalSongService {
@Autowired @Autowired
private JournalSongDao journalSongDao; private JournalSongDao journalSongDao;
@Autowired
private CacheChannel cacheChannel;
@Autowired @Autowired
private IdWorker idWorker; 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 * @param searchMap
@ -143,7 +112,6 @@ public class JournalSongService {
} }
}; };
} }
public List<JournalSong> findByVolid(String journalNo){ public List<JournalSong> findByVolid(String journalNo){
return journalSongDao.findByJournalNo(journalNo); return journalSongDao.findByJournalNo(journalNo);
@ -156,4 +124,8 @@ public class JournalSongService {
public List<JournalSong> orderByField(List<String> objectIds) { public List<JournalSong> orderByField(List<String> objectIds) {
return journalSongDao.orderByField(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() ;
}
} }

@ -1,3 +1,4 @@
default: 1000, 2h default: 1000, 2h
journal_query_page: 10000, 6h journal_query_page: 10000, 6h
journal_id: 2000, 6h journal_id: 2000, 6h
journal_song_key: 10000, 6h
Loading…
Cancel
Save