1.add tag infos in jouranl response

main
Gary 5 months ago
parent a7fd80ab97
commit 7cf67658d3

@ -124,6 +124,7 @@ public class SaticScheduleTask {
private void updateJouranlTag(Journal journal) {
List<String> tags = tagDao.getTagNameChByJournalId(journal.getId());
if (!tags.isEmpty()) {
cacheChannel.clear("tag");
String tagStr = tags.stream().distinct().sorted().collect(Collectors.joining(Constants.COMMA));
if (!tagStr.equals(journal.getNameChTags())) {
journal.setNameChTags(tagStr);

@ -12,7 +12,6 @@ import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SongRespDTO;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.core.RedisTemplate;
@ -50,6 +49,9 @@ public class JournalController {
@Autowired
private JournalService journalService;
@Autowired
private JournalMapper journalMapper;
@Autowired
private SongController songController;
@ -124,7 +126,7 @@ public class JournalController {
List<Journal> pageList = journalService.orderByField(objectIds);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
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());
// list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(count, list));
@ -278,7 +280,7 @@ public class JournalController {
List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList());
Set<String> journalCollectSet = null == user ? Collections.emptySet()
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> journalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList());
return Result.success(list);
}
@ -288,7 +290,7 @@ public class JournalController {
@GlobalInterceptor
public Result<List<JournalRespDTO>> recommend() {
List<Journal> journals = journalService.recommend();
List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> JournalMapper.getJournalRespDTO(a))
List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> journalMapper.getJournalRespDTO(a))
.collect(Collectors.toList());
return Result.success(list);
}

@ -43,6 +43,9 @@ public class SearchController {
@Autowired
private JournalService journalService;
@Autowired
private JournalMapper journalMapper;
@Autowired
private JournalSongService journalSongService;
@ -89,7 +92,7 @@ public class SearchController {
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
List<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest);
List<JournalRespDTO> list = pageResults.stream().map(JournalMapper::getJournalRespDTO)
List<JournalRespDTO> list = pageResults.stream().map(journalMapper::getJournalRespDTO)
.collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
}

@ -32,9 +32,6 @@ public interface JournalTagDao extends JpaRepository<JournalTag,String>, JpaSpec
@Query(value = "select journal_id FROM tb_journal_tag where tag_id=?1 or tag_id in (select id from tb_tag_info where parent_id=?1)", nativeQuery = true)
List<String> getJournalIdByTagId(String tagId);
@Query(value = "select tb_journal_tag.journal_id FROM tb_journal_tag, tb_tag_info where tb_tag_info.name_ch=?1 and (tb_journal_tag.tag_id=tb_tag_info.id or tb_journal_tag.tag_id in (select tb_tag_info.id from tb_tag_info where tb_tag_info.parent_id=tb_tag_info.id))", nativeQuery = true)
List<String> getJournalIdByTagName(String tag);
@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, Integer limit);
}

@ -33,4 +33,7 @@ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExec
@Query(value = "select name_ch from tb_journal_tag,tb_tag_info where journal_id = ?1 and tb_journal_tag.tag_id =tb_tag_info.id ;", nativeQuery = true)
List<String> getTagNameChByJournalId(String journalId);
@Query(value = "select * from tb_tag_info where name_ch=?1 limit 1", nativeQuery = true)
Tag findByTagName(String tagName);
}

@ -10,31 +10,60 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.luoo.music.client.UserClient;
import net.oschina.j2cache.CacheChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.MongoTemplate;
import com.apifan.common.random.RandomSource;
import com.apifan.common.random.entity.Poem;
import com.luoo.music.dao.CommentDao;
import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalFilterDTO;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.TagDTO;
import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag;
import com.luoo.music.service.TagService;
import constants.Constants;
import enums.DateTimePatternEnum;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import util.DateUtil;
import util.StringTools;
@Component
public class JournalMapper {
public static JournalRespDTO getJournalRespDTO(Journal journal) {
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private CacheChannel cacheChannel;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private CommentDao commentDao;
@Autowired
private TagDao tagDao;
@Autowired
private UserClient userClient;
public JournalRespDTO getJournalRespDTO(Journal journal) {
return getJournalRespDTO(journal, Collections.emptySet());
}
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
public JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
JournalRespDTO journalRespDTO = new JournalRespDTO();
journalRespDTO.setId(journal.getId());
journalRespDTO.setJournalNo(journal.getJournalNo());
@ -48,6 +77,8 @@ public class JournalMapper {
String nameChTags=journal.getNameChTags();
if(!StringTools.isEmpty(nameChTags)) {
List<String> tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList());
List<TagDTO> tagInfos = tags.stream().map(this::getTagDto).filter(Objects::nonNull).collect(Collectors.toList());
journalRespDTO.setTagInfos(tagInfos);
journalRespDTO.setTags(tags);
}
journalRespDTO.setContent(journal.getContent());
@ -56,9 +87,22 @@ public class JournalMapper {
return journalRespDTO;
}
private TagDTO getTagDto(String tagName) {
return (TagDTO) this.cacheChannel.get("tag", tagName, key -> getTagDtoByName(tagName), false).getValue();
}
private TagDTO getTagDtoByName(String tagName) {
Tag tag=tagDao.findByTagName(tagName);
if(null==tag) {
return null;
}
TagDTO tagDTO=new TagDTO();
tagDTO.setName(tag.getNameCh());
tagDTO.setId(tag.getId());
return tagDTO;
}
public static JournalRespDTO getJournalRespDTO(Journal journal,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, UserClient userClient, CacheChannel cacheChannel) {
public JournalRespDTO getJournalRespDTOWithComment(Journal journal) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate,userClient,cacheChannel);
@ -70,7 +114,7 @@ public class JournalMapper {
}
private static String getPublishDate(Journal journal) {
private String getPublishDate(Journal journal) {
LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime();
return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());
}

@ -18,8 +18,6 @@ public class JournalQueryReq implements Serializable {
private static final long serialVersionUID = -1198060864891902188L;
@ApiModelProperty(value = "筛选条件类目Id", example = "民谣/国语 id")
private String categoryId;
@ApiModelProperty(value = "筛选条件:期刊标签", example = "民谣/国语")
private String tag;
@ApiModelProperty(value = "筛选条件:期刊号范围", example = "900~800")
private String journalNoRange;
@ApiModelProperty(value = "分页: 页码以1开始即获取最新的几期", example = "1")
@ -33,7 +31,7 @@ public class JournalQueryReq implements Serializable {
}
public String countString() {
return getString(categoryId)+ "_" + getString(tag) + "_" + getString(journalNoRange);
return getString(categoryId) + "_" + getString(journalNoRange);
}
private String getString(String value) {

@ -20,6 +20,8 @@ public class JournalRespDTO implements Serializable {
private String image;
@ApiModelProperty(value = "期刊标签")
private List<String> tags;
@ApiModelProperty(value = "期刊标签信息")
private List<TagDTO> tagInfos;
@ApiModelProperty(value = "概要")
private String summary;
@ApiModelProperty(value = "文案")

@ -60,6 +60,9 @@ public class JournalService {
@Autowired
private JournalSongDao journalSongDao;
@Autowired
private JournalMapper journalMapper;
@Autowired
private JournalTagDao journalTagDao;
@Autowired
@ -228,14 +231,9 @@ public class JournalService {
if(StringUtils.isNotBlank(queryReq.getCategoryId())){
return journalTagDao.getJournalIdByTagId(queryReq.getCategoryId());
}
if(StringUtils.isNotBlank(queryReq.getTag())){
return journalTagDao.getJournalIdByTagName(queryReq.getTag());
}
return Collections.emptyList();
}
public boolean isLatest10ByJournalNo(String journalNo) {
return null!=journalDao.isLatest10ByJournalNo(journalNo);
}
@ -399,12 +397,12 @@ public class JournalService {
private List<JournalRespDTO> getJournalRespDTO(JournalQueryReq queryReq) {
List<Journal> pageList = queryPage(queryReq);
return pageList.stream().map(a ->
JournalMapper.getJournalRespDTO(a)).collect(Collectors.toList());
journalMapper.getJournalRespDTO(a)).collect(Collectors.toList());
}
private List<JournalRespDTO> getJournalRespDTOWithComment(JournalQueryReq queryReq) {
List<Journal> pageList = queryPage(queryReq);
return pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel)).collect(Collectors.toList());
return pageList.stream().map(journal -> journalMapper.getJournalRespDTOWithComment(journal)).collect(Collectors.toList());
}
@ -418,7 +416,7 @@ public class JournalService {
if(null==journal) {
return null;
}
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel);
return journalMapper.getJournalRespDTOWithComment(journal);
}
public JournalRespDTO queryJournalByJournalNo(String journalNo) {
@ -430,7 +428,7 @@ public class JournalService {
if(null==journal) {
return null;
}
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel);
return journalMapper.getJournalRespDTOWithComment(journal);
}
public JournalFilterDTO getJournalFilterDTO() {

Loading…
Cancel
Save