diff --git a/luoo_music/pom.xml b/luoo_music/pom.xml index d1a57fd..275b800 100644 --- a/luoo_music/pom.xml +++ b/luoo_music/pom.xml @@ -63,6 +63,11 @@ software.amazon.awssdk s3 + + com.apifan.common + common-random + 1.0.21 + app diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 46c7131..396e712 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -1,11 +1,16 @@ package com.luoo.music.controller; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; + +import com.apifan.common.random.RandomSource; +import com.apifan.common.random.entity.Poem; +import com.luoo.music.dao.TagDao; import com.luoo.music.dto.request.JournalQueryReq; import com.luoo.music.dto.response.JournalRespDTO; @@ -13,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Article; +import com.luoo.music.pojo.Tag; import com.luoo.music.service.ArticleService; import com.luoo.music.service.UserCollectService; @@ -44,6 +50,10 @@ public class JournalController { private UserCollectService userCollectService; @Autowired private ArticleService articleService; + + @Autowired + private TagDao tagDao; + @Autowired private JwtUtil jwtUtil; @@ -107,6 +117,13 @@ public class JournalController { journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + article.getImage()); journalRespDTO.setDate(getEditDate(article)); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); + + int limit = RandomSource.numberSource().randomInt(1, 3); + List tags=tagDao.random(limit).stream().map(Tag::getNameCh).sorted().collect(Collectors.toList()); + journalRespDTO.setTags(tags); + Poem poem=RandomSource.languageSource().randomTangPoem(); + journalRespDTO.setEditor(poem.getAuthor()); + journalRespDTO.setContent(Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n"))); return journalRespDTO; } diff --git a/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java b/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java index b8eb885..d45968f 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java @@ -1,8 +1,10 @@ package com.luoo.music.dao; +import com.luoo.music.pojo.Song; import com.luoo.music.pojo.Tag; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.Set; @@ -13,4 +15,7 @@ import java.util.Set; public interface TagDao extends JpaRepository, JpaSpecificationExecutor{ List findByIdIn(Set ids); + + @Query(value = "select * from tb_tag_info where parent_id='' order by rand() limit ?1 ", nativeQuery = true) + List random(int limit); } diff --git a/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java b/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java index 7860338..2fdfc41 100644 --- a/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java +++ b/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java @@ -1,11 +1,14 @@ package com.luoo.user.util; +import java.util.Arrays; +import java.util.stream.Collectors; import java.util.stream.IntStream; import org.junit.Test; import org.springframework.util.StopWatch; import com.apifan.common.random.RandomSource; +import com.apifan.common.random.entity.Poem; public class NickNameUtilTest { int size = 4; @@ -27,6 +30,11 @@ public class NickNameUtilTest { } sw.stop(); System.out.println(sw.prettyPrint()); + + Poem poem=RandomSource.languageSource().randomTangPoem(); + System.out.println(poem.getAuthor()); + String content=Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n")); + System.out.println(content); } public String getRandomNickName() {