1.recomend by limit

main
Gary 8 months ago
parent 0c3a986c21
commit 670cf426f3

@ -84,27 +84,6 @@ public class JournalController {
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(pageList.size()), pageList)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(pageList.size()), pageList));
} }
private JournalRespDTO randomCDN1(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->{
j.setHaveCollect(journalCollectSet.contains(j.getId())); j.setHaveCollect(journalCollectSet.contains(j.getId()));
@ -272,18 +251,20 @@ public class JournalController {
return Result.success(journalService.getJournalFilterDTO()); return Result.success(journalService.getJournalFilterDTO());
} }
@ApiOperation(value = "5.根据当前期刊的标签推荐6期类似期刊") @ApiOperation(value = "5.根据当前期刊的标签推荐类似期刊默认6期")
@GetMapping("/recommend/{id}") @GetMapping(value={"/recommend/{id}","/recommend/{id}/{limit}"})
@GlobalInterceptor @GlobalInterceptor
public Result<List<JournalRespDTO>> recommendById( public Result<List<JournalRespDTO>> recommendById(
@RequestHeader(value = "Authorization", required = false) String authorization, @RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) { @PathVariable @VerifyParam(required = true) String id,@PathVariable(required=false) Integer limit) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user && !journalService.isLatest10ByJournalId(id)) { if (null == user && !journalService.isLatest10ByJournalId(id)) {
return Result.unauthorized(null); return Result.unauthorized(null);
} }
if(null == limit) {
List<Journal> journals = journalService.recommendById(id); limit = 6;
}
List<Journal> journals = journalService.recommendById(id,limit);
List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList()); List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList());
Set<String> journalCollectSet = null == user ? Collections.emptySet() Set<String> journalCollectSet = null == user ? Collections.emptySet()
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
@ -295,14 +276,14 @@ public class JournalController {
@ApiOperation(value = "统计期刊的浏览数", notes = "APP端打开期刊调用一次统计接口") @ApiOperation(value = "统计期刊的浏览数", notes = "APP端打开期刊调用一次统计接口")
@RequestMapping(value="/stat/visits/{id}", method= RequestMethod.PUT) @PutMapping("/stat/visits/{id}")
public Result statVisitsCount(@ApiParam(value = "期刊ID", required = true) @PathVariable String id) { public Result statVisitsCount(@ApiParam(value = "期刊ID", required = true) @PathVariable String id) {
return journalService.statVisitsCount(id); return journalService.statVisitsCount(id);
} }
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
@ApiOperation(value = "统计期刊的评论数", notes = "APP端增加期刊时或删除评论时调用一次该接口status根据操作类型对应传参") @ApiOperation(value = "统计期刊的评论数", notes = "APP端增加期刊时或删除评论时调用一次该接口status根据操作类型对应传参")
@RequestMapping(value="/stat/comment/{id}", method= RequestMethod.PUT) @PutMapping("/stat/comment/{id}")
public Result statCommentCount(@ApiParam(value = "期刊ID", required = true) @PathVariable String id, public Result statCommentCount(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "状态1:增加评论0删除评论", required = true) @RequestBody String status) { @ApiParam(value = "状态1:增加评论0删除评论", required = true) @RequestBody String status) {
return journalService.statCommentCount(id, status); return journalService.statCommentCount(id, status);

@ -33,6 +33,6 @@ public interface JournalTagDao extends JpaRepository<JournalTag,String>, JpaSpec
List<String> getJournalIdByTagId(String tagId); List<String> getJournalIdByTagId(String tagId);
@Query(value = "select journal_id from tb_journal_tag where tag_id in (select tag_id from tb_journal_tag where journal_id=?1) and not journal_id=?1 order by rand() limit 6", nativeQuery = true) @Query(value = "select journal_id from tb_journal_tag where tag_id in (select tag_id from tb_journal_tag where journal_id=?1) and not journal_id=?1 order by rand() limit ?2", nativeQuery = true)
List<String> recommendByJournalId(String journalId); List<String> recommendByJournalId(String journalId, Integer limit);
} }

@ -331,11 +331,11 @@ public class JournalService {
} }
public List<Journal> recommendById(String id) { public List<Journal> recommendById(String id, Integer limit) {
List<String> recommendIds=journalTagDao.recommendByJournalId(id); List<String> recommendIds=journalTagDao.recommendByJournalId(id,limit);
List<String> extraIds=Collections.emptyList(); List<String> extraIds=Collections.emptyList();
if(recommendIds.size()<6) { if(recommendIds.size()<limit) {
extraIds=recommendIds.isEmpty()?journalDao.random(6):journalDao.random(6-recommendIds.size(),recommendIds); extraIds = recommendIds.isEmpty()?journalDao.random(limit):journalDao.random(limit-recommendIds.size(),recommendIds);
} }
if(!extraIds.isEmpty()) { if(!extraIds.isEmpty()) {
recommendIds.addAll(extraIds); recommendIds.addAll(extraIds);

Loading…
Cancel
Save