|
@@ -1,18 +1,24 @@
|
|
package cn.efunbox.audio.impl;
|
|
package cn.efunbox.audio.impl;
|
|
|
|
|
|
import cn.efunbox.audio.consts.MediaType;
|
|
import cn.efunbox.audio.consts.MediaType;
|
|
|
|
+import cn.efunbox.audio.entity.Album;
|
|
import cn.efunbox.audio.entity.Audio;
|
|
import cn.efunbox.audio.entity.Audio;
|
|
import cn.efunbox.audio.repository.AlbumRepo;
|
|
import cn.efunbox.audio.repository.AlbumRepo;
|
|
import cn.efunbox.audio.repository.AudioRepo;
|
|
import cn.efunbox.audio.repository.AudioRepo;
|
|
import cn.efunbox.audio.service.AudioService;
|
|
import cn.efunbox.audio.service.AudioService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
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.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by yao on 17-9-26.
|
|
* Created by yao on 17-9-26.
|
|
@@ -25,6 +31,9 @@ public class AudioServiceImpl implements AudioService {
|
|
@Autowired
|
|
@Autowired
|
|
AlbumRepo albumRepo;
|
|
AlbumRepo albumRepo;
|
|
|
|
|
|
|
|
+ @Value("${efunbox.oss.img.url}")
|
|
|
|
+ private String imgURL;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Audio GetOne(Long id){
|
|
public Audio GetOne(Long id){
|
|
Audio audio = audioRepo.findById(id);
|
|
Audio audio = audioRepo.findById(id);
|
|
@@ -41,9 +50,35 @@ public class AudioServiceImpl implements AudioService {
|
|
list = audioRepo.findByMediaType(mediaType, pageable);
|
|
list = audioRepo.findByMediaType(mediaType, pageable);
|
|
else
|
|
else
|
|
list = audioRepo.findAll(pageable);
|
|
list = audioRepo.findAll(pageable);
|
|
|
|
+
|
|
|
|
+ fillAlbum(list.getContent());
|
|
|
|
+
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void fillAlbum(List<Audio> list) {
|
|
|
|
+
|
|
|
|
+ List<Long> albumIds = new ArrayList<>();
|
|
|
|
+ list.stream().forEach(audio -> albumIds.add(audio.getAlbumId()));
|
|
|
|
+
|
|
|
|
+ List<Album> albumList = albumRepo.findByIdIn(albumIds);
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(albumList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<Long, Album> albumMap = albumList.stream().collect(Collectors.toMap(Album::getId, album -> album));
|
|
|
|
+
|
|
|
|
+ list.stream().forEach(audio -> {
|
|
|
|
+ Album album = albumMap.get(audio.getAlbumId());
|
|
|
|
+ if (Objects.nonNull(album)) {
|
|
|
|
+ audio.setAlbum(album.getName());
|
|
|
|
+ audio.setAlbumImage(imgURL + album.getImage());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Page<Audio> SearchByIdGroup(int mediaType, Long idGroup, int page, int size){
|
|
public Page<Audio> SearchByIdGroup(int mediaType, Long idGroup, int page, int size){
|
|
if(size<=0)
|
|
if(size<=0)
|
|
@@ -83,9 +118,9 @@ public class AudioServiceImpl implements AudioService {
|
|
List<Long> albumIds = albumRepo.findIdsByNameLike(album);
|
|
List<Long> albumIds = albumRepo.findIdsByNameLike(album);
|
|
List<Audio> list = null;
|
|
List<Audio> list = null;
|
|
if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
|
|
if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
|
|
- list = audioRepo.findByMediaTypeAndAlbumIn(mediaType, albumIds);
|
|
|
|
|
|
+ list = audioRepo.findByMediaTypeAndAlbumIdIn(mediaType, albumIds);
|
|
else
|
|
else
|
|
- list = audioRepo.findByAlbumIn(albumIds);
|
|
|
|
|
|
+ list = audioRepo.findByAlbumIdIn(albumIds);
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -97,11 +132,11 @@ public class AudioServiceImpl implements AudioService {
|
|
List<Long> albumIds = albumRepo.findIdsByNameLike(album);
|
|
List<Long> albumIds = albumRepo.findIdsByNameLike(album);
|
|
List<Audio> list = null;
|
|
List<Audio> list = null;
|
|
if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
|
|
if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
|
|
- list = audioRepo.findByMediaTypeAndNameAndAlbumIn(mediaType, name, albumIds);
|
|
|
|
|
|
+ list = audioRepo.findByMediaTypeAndNameAndAlbumIdIn(mediaType, name, albumIds);
|
|
else
|
|
else
|
|
- list = audioRepo.findByNameAndAlbumIn(name, albumIds);
|
|
|
|
|
|
+ list = audioRepo.findByNameAndAlbumIdIn(name, albumIds);
|
|
if(CollectionUtils.isEmpty(list))
|
|
if(CollectionUtils.isEmpty(list))
|
|
- list = audioRepo.findByNameLikeAndAlbumIn(name, albumIds);
|
|
|
|
|
|
+ list = audioRepo.findByNameLikeAndAlbumIdIn(name, albumIds);
|
|
|
|
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|