|
|
|
@ -21,6 +21,7 @@ import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -28,10 +29,7 @@ import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@ -71,16 +69,42 @@ public class SongController {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
List<SongRespDTO> results = journalSongService.findByJournalNo(journalNo);
|
|
|
|
|
results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
|
|
|
|
|
Set<String> songCollectSet = getSongCollectSet(results,user);
|
|
|
|
|
updateCollectStatus(results,songCollectSet);
|
|
|
|
|
return Result.success(results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SongRespDTO randomCDN(SongRespDTO s){
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
int rate = random.nextInt(100);
|
|
|
|
|
// int randomNum = random.nextInt(2)+1;
|
|
|
|
|
int randomNum =1;
|
|
|
|
|
if (rate>20) {
|
|
|
|
|
randomNum =2;
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isEmpty(s.getLrc())){
|
|
|
|
|
s.setLrc(s.getLrc().replaceFirst("cdn1","cdn"+randomNum));
|
|
|
|
|
s.setLrc(s.getLrc().replaceFirst("cdn2","cdn"+randomNum));
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isEmpty(s.getSrc())){
|
|
|
|
|
s.setSrc(s.getSrc().replaceFirst("cdn1","cdn"+randomNum));
|
|
|
|
|
s.setSrc(s.getSrc().replaceFirst("cdn2","cdn"+randomNum));
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isEmpty(s.getPic())){
|
|
|
|
|
s.setPic(s.getPic().replaceFirst("cdn1","cdn"+randomNum));
|
|
|
|
|
s.setPic(s.getPic().replaceFirst("cdn2","cdn"+randomNum));
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
@ApiOperation(value = "1.1 根据期刊id查询歌曲信息", notes = "仅用于外部分享")
|
|
|
|
|
@GetMapping("/journalId/{journalId}")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<List<SongRespDTO>> getByJournalId(@PathVariable String journalId) {
|
|
|
|
|
return Result.success(journalSongService.findByJournalId(journalId));
|
|
|
|
|
List<SongRespDTO> list = journalSongService.findByJournalId(journalId);
|
|
|
|
|
list = list.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
|
|
|
|
|
return Result.success(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateCollectStatus(List<SongRespDTO> results, Set<String> songCollectSet) {
|
|
|
|
@ -120,6 +144,7 @@ public class SongController {
|
|
|
|
|
Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
|
|
|
|
|
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -157,6 +182,7 @@ public class SongController {
|
|
|
|
|
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
|
|
|
|
|
return Result.success(results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -173,6 +199,7 @@ public class SongController {
|
|
|
|
|
SongRespDTO songRespDTO=SongMapper.getSongRespDTO(song);
|
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.SONG);
|
|
|
|
|
songRespDTO.setHaveCollect(isCollect);
|
|
|
|
|
songRespDTO = randomCDN(songRespDTO);
|
|
|
|
|
return Result.success(songRespDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|