|
|
@ -1,40 +1,22 @@
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.apifan.common.random.RandomSource;
|
|
|
|
|
|
|
|
import com.apifan.common.random.entity.Poem;
|
|
|
|
|
|
|
|
import com.luoo.music.dao.CommentDao;
|
|
|
|
import com.luoo.music.dao.CommentDao;
|
|
|
|
import com.luoo.music.dao.TagDao;
|
|
|
|
import com.luoo.music.dto.mapper.JournalMapper;
|
|
|
|
import com.luoo.music.dto.request.JournalQueryReq;
|
|
|
|
import com.luoo.music.dto.request.JournalQueryReq;
|
|
|
|
import com.luoo.music.dto.response.JournalFilterDTO;
|
|
|
|
import com.luoo.music.dto.response.JournalFilterDTO;
|
|
|
|
import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
|
|
|
|
import com.luoo.music.dto.response.TagDTO;
|
|
|
|
import com.luoo.music.dto.response.TotalCommentVo;
|
|
|
|
|
|
|
|
import com.luoo.music.pojo.Comment;
|
|
|
|
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
|
|
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.data.mongodb.core.MongoTemplate;
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
import com.luoo.music.pojo.Tag;
|
|
|
|
import com.luoo.music.pojo.Tag;
|
|
|
@ -45,14 +27,9 @@ import annotation.GlobalInterceptor;
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
import api.PageResult;
|
|
|
|
import api.PageResult;
|
|
|
|
import api.Result;
|
|
|
|
import api.Result;
|
|
|
|
import constants.Constants;
|
|
|
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
import enums.DateTimePatternEnum;
|
|
|
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
|
|
|
import util.DateUtil;
|
|
|
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
import util.JwtUtil;
|
|
|
|
import util.StringTools;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 控制器层
|
|
|
|
* 控制器层
|
|
|
@ -71,16 +48,12 @@ public class JournalController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JournalService journalService;
|
|
|
|
private JournalService journalService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private TagDao tagDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private TagService tagService;
|
|
|
|
private TagService tagService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
|
|
@ -88,30 +61,6 @@ public class JournalController {
|
|
|
|
private CommentDao commentDao;
|
|
|
|
private CommentDao commentDao;
|
|
|
|
|
|
|
|
|
|
|
|
private static final int JOURNAL_FILTER_NUMBER_RANGE=100;
|
|
|
|
private static final int JOURNAL_FILTER_NUMBER_RANGE=100;
|
|
|
|
// mock data
|
|
|
|
|
|
|
|
private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
|
|
|
|
|
|
|
|
private Map<String, List<String>> journalTagMap = new HashMap<>();
|
|
|
|
|
|
|
|
private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
|
|
|
|
getLines(JOURNAL_TAG_FILE_PATH).forEach(s -> {
|
|
|
|
|
|
|
|
String[] segs = s.split("\\|");
|
|
|
|
|
|
|
|
List<String> tags = Arrays.stream(segs[1].split(",")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
journalTagMap.put(segs[0], tags);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<String> getLines(String filePath) {
|
|
|
|
|
|
|
|
try (InputStream is = new ClassPathResource(filePath).getInputStream();
|
|
|
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));) {
|
|
|
|
|
|
|
|
return reader.lines().collect(Collectors.toList());
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.查询期刊信息", notes = "若authorization为空或authorization校验失败,默认返回最新的10期,期刊筛选条件对游客不可用")
|
|
|
|
@ApiOperation(value = "1.查询期刊信息", notes = "若authorization为空或authorization校验失败,默认返回最新的10期,期刊筛选条件对游客不可用")
|
|
|
|
@GetMapping("/list")
|
|
|
|
@GetMapping("/list")
|
|
|
@ -121,8 +70,7 @@ public class JournalController {
|
|
|
|
@VerifyParam JournalQueryReq queryReq) {
|
|
|
|
@VerifyParam JournalQueryReq queryReq) {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
if (null == user) {
|
|
|
|
if (null == user) {
|
|
|
|
queryReq.setLanguage(null);
|
|
|
|
queryReq.setCategoryId(null);
|
|
|
|
queryReq.setStyle(null);
|
|
|
|
|
|
|
|
queryReq.setPageNum(1);
|
|
|
|
queryReq.setPageNum(1);
|
|
|
|
queryReq.setPageSize(10);
|
|
|
|
queryReq.setPageSize(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,7 +78,7 @@ public class JournalController {
|
|
|
|
List<String> ids=pageList.stream().map(Journal::getId).collect(Collectors.toList());
|
|
|
|
List<String> ids=pageList.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);
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet))
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,mongoTemplate,commentDao))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.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));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -153,7 +101,7 @@ public class JournalController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Journal> pageList = journalService.orderByField(objectIds);
|
|
|
|
List<Journal> pageList = journalService.orderByField(objectIds);
|
|
|
|
Set<String> journalCollectSet = new HashSet<>(objectIds);
|
|
|
|
Set<String> journalCollectSet = new HashSet<>(objectIds);
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet))
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,mongoTemplate,commentDao))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.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));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -166,7 +114,7 @@ public class JournalController {
|
|
|
|
@PathVariable @VerifyParam(required = true) String id) {
|
|
|
|
@PathVariable @VerifyParam(required = true) String id) {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
Journal journal = journalService.findById(id);
|
|
|
|
Journal journal = journalService.findById(id);
|
|
|
|
JournalRespDTO journalRespDTO=getJournalRespDTO(journal, Collections.emptySet());
|
|
|
|
JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,commentDao);
|
|
|
|
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);
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
@ -179,86 +127,17 @@ public class JournalController {
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
JournalFilterDTO journalFilterDTO=new JournalFilterDTO();
|
|
|
|
JournalFilterDTO journalFilterDTO=new JournalFilterDTO();
|
|
|
|
journalFilterDTO.setJournalNoList(journalService.getJournalNoList(JOURNAL_FILTER_NUMBER_RANGE));
|
|
|
|
journalFilterDTO.setJournalNoList(journalService.getJournalNoList(JOURNAL_FILTER_NUMBER_RANGE));
|
|
|
|
journalFilterDTO.setLanguageList(tagService.getLanguageList());
|
|
|
|
|
|
|
|
journalFilterDTO.setStyleList(tagService.getStyleList());
|
|
|
|
|
|
|
|
return Result.success(journalFilterDTO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
|
|
|
|
|
|
|
|
JournalRespDTO journalRespDTO = new JournalRespDTO();
|
|
|
|
|
|
|
|
journalRespDTO.setId(journal.getId());
|
|
|
|
|
|
|
|
journalRespDTO.setJournalNo(journal.getJournalNo());
|
|
|
|
|
|
|
|
journalRespDTO.setTitle(journal.getTitle());
|
|
|
|
|
|
|
|
journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + journal.getImage());
|
|
|
|
|
|
|
|
journalRespDTO.setDate(getEditDate(journal));
|
|
|
|
|
|
|
|
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
|
|
|
|
|
|
|
|
journalRespDTO.setIpLocation("广东");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
journalRespDTO.setTags(getTags(journalRespDTO.getJournalNo()));
|
|
|
|
journalFilterDTO.setLanguageList(tagService.getLanguageList().stream().map(this::getTagDTO).collect(Collectors.toList()));
|
|
|
|
String content = journal.getContent();
|
|
|
|
journalFilterDTO.setStyleList(tagService.getStyleList().stream().map(this::getTagDTO).collect(Collectors.toList()));
|
|
|
|
if (StringTools.isEmpty(content)) {
|
|
|
|
return Result.success(journalFilterDTO);
|
|
|
|
Poem poem = RandomSource.languageSource().randomTangPoem();
|
|
|
|
|
|
|
|
journalRespDTO.setEditor(poem.getAuthor());
|
|
|
|
|
|
|
|
journalRespDTO.setContent(Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n")));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
journalRespDTO.setContent(content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
journalRespDTO.setEditor(getEditor(journal.getUserName()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
*显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Comment> commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journal.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
journalRespDTO.setCommentList(commentList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Criteria criteria = Criteria.where("journalId").is(journal.getId());
|
|
|
|
|
|
|
|
Aggregation agg = Aggregation.newAggregation(
|
|
|
|
|
|
|
|
Aggregation.match(criteria),//匹配条件
|
|
|
|
|
|
|
|
Aggregation.group().sum("commentCount").as("totalComment")
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg,"comment", TotalCommentVo.class);
|
|
|
|
|
|
|
|
TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
|
|
|
|
|
|
|
|
journalRespDTO.setTotalCommentReply("0");
|
|
|
|
|
|
|
|
List<Comment> list =commentDao.findByJournalId(journal.getId());
|
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
if(null != list && list.size()>0) {
|
|
|
|
|
|
|
|
total = list.size();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null != totalCommentVo) {
|
|
|
|
|
|
|
|
total = total + totalCommentVo.getTotalComment();
|
|
|
|
|
|
|
|
journalRespDTO.setTotalCommentReply(total+"");
|
|
|
|
|
|
|
|
if (total>99) {
|
|
|
|
|
|
|
|
journalRespDTO.setTotalCommentReply("99+");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return journalRespDTO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getEditor(String userName) {
|
|
|
|
|
|
|
|
return StringTools.isEmpty(userName)?EDITOR[RandomSource.numberSource().randomInt(0, EDITOR.length)]:userName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getTags(String journalNo) {
|
|
|
|
|
|
|
|
return journalTagMap.computeIfAbsent(journalNo, a -> getTags());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getTags() {
|
|
|
|
|
|
|
|
int limit = RandomSource.numberSource().randomInt(1, 3);
|
|
|
|
|
|
|
|
return tagDao.random(limit).stream().map(Tag::getNameCh).sorted().collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private TagDTO getTagDTO(Tag tag) {
|
|
|
|
private String getEditDate(Journal journal) {
|
|
|
|
TagDTO tagDTO=new TagDTO();
|
|
|
|
LocalDateTime date = null == journal.getUpdateTime() ? journal.getCreateTime() : journal.getUpdateTime();
|
|
|
|
tagDTO.setName(tag.getNameCh());
|
|
|
|
return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());
|
|
|
|
tagDTO.setId(tag.getId());
|
|
|
|
|
|
|
|
return tagDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "统计期刊的浏览数", notes = "APP端打开期刊调用一次统计接口")
|
|
|
|
@ApiOperation(value = "统计期刊的浏览数", notes = "APP端打开期刊调用一次统计接口")
|
|
|
|
@RequestMapping(value="/stat/visits/{id}", method= RequestMethod.PUT)
|
|
|
|
@RequestMapping(value="/stat/visits/{id}", method= RequestMethod.PUT)
|
|
|
|
public Result statVisitsCount(@ApiParam(value = "期刊ID", required = true) @PathVariable String id) {
|
|
|
|
public Result statVisitsCount(@ApiParam(value = "期刊ID", required = true) @PathVariable String id) {
|
|
|
|