|
|
@ -1,9 +1,6 @@
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -18,6 +15,7 @@ import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.dto.response.TagDTO;
|
|
|
|
import com.luoo.music.dto.response.TagDTO;
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
@ -80,10 +78,32 @@ public class JournalController {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
updateQuery(user,queryReq);
|
|
|
|
updateQuery(user,queryReq);
|
|
|
|
List<JournalRespDTO> pageList=journalService.queryJournalByPage(queryReq);
|
|
|
|
List<JournalRespDTO> pageList=journalService.queryJournalByPage(queryReq);
|
|
|
|
|
|
|
|
pageList = pageList.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
|
|
|
|
Set<String> journalCollectSet = getJournalCollectSet(user);
|
|
|
|
Set<String> journalCollectSet = getJournalCollectSet(user);
|
|
|
|
updateCollectStatus(pageList,journalCollectSet);
|
|
|
|
updateCollectStatus(pageList,journalCollectSet);
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(pageList.size()), pageList));
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(pageList.size()), pageList));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JournalRespDTO randomCDN(JournalRespDTO journalRespDTO) {
|
|
|
|
|
|
|
|
// Random random = new Random();
|
|
|
|
|
|
|
|
// int randomNum = random.nextInt(2)+1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.isNotEmpty(journalRespDTO.getImage())){
|
|
|
|
|
|
|
|
journalRespDTO.setImage(journalRespDTO.getImage().replaceFirst("cdn1","cdn"+randomNum));
|
|
|
|
|
|
|
|
journalRespDTO.setImage(journalRespDTO.getImage().replaceFirst("cdn2","cdn"+randomNum));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return journalRespDTO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateCollectStatus(List<JournalRespDTO> pageList, Set<String> journalCollectSet) {
|
|
|
|
private void updateCollectStatus(List<JournalRespDTO> pageList, Set<String> journalCollectSet) {
|
|
|
|
pageList.forEach(j->{
|
|
|
|
pageList.forEach(j->{
|
|
|
@ -125,6 +145,7 @@ public class JournalController {
|
|
|
|
Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
|
|
|
|
Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -199,6 +220,7 @@ public class JournalController {
|
|
|
|
|
|
|
|
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL);
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL);
|
|
|
|
journalRespDTO.setHaveCollect(isCollect);
|
|
|
|
journalRespDTO.setHaveCollect(isCollect);
|
|
|
|
|
|
|
|
journalRespDTO = randomCDN(journalRespDTO);
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -218,6 +240,7 @@ public class JournalController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),journalRespDTO.getId(), CollectTypeEnum.JOURNAL);
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),journalRespDTO.getId(), CollectTypeEnum.JOURNAL);
|
|
|
|
journalRespDTO.setHaveCollect(isCollect);
|
|
|
|
journalRespDTO.setHaveCollect(isCollect);
|
|
|
|
|
|
|
|
journalRespDTO = randomCDN(journalRespDTO);
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private boolean isLatest10(String journalNo) {
|
|
|
|
private boolean isLatest10(String journalNo) {
|
|
|
@ -261,7 +284,7 @@ public class JournalController {
|
|
|
|
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
|
|
|
|
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
|
|
|
|
List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
|
|
|
|
List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
|
|
|
|
return Result.success(list);
|
|
|
|
return Result.success(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|