1.add fake data for journal

main
Gary 10 months ago
parent af6c83da22
commit 4de647f51c

@ -63,6 +63,11 @@
<groupId>software.amazon.awssdk</groupId> <groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId> <artifactId>s3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.apifan.common</groupId>
<artifactId>common-random</artifactId>
<version>1.0.21</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>app</finalName> <finalName>app</finalName>

@ -1,11 +1,16 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; 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.request.JournalQueryReq;
import com.luoo.music.dto.response.JournalRespDTO; 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.data.domain.Page;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Article; import com.luoo.music.pojo.Article;
import com.luoo.music.pojo.Tag;
import com.luoo.music.service.ArticleService; import com.luoo.music.service.ArticleService;
import com.luoo.music.service.UserCollectService; import com.luoo.music.service.UserCollectService;
@ -44,6 +50,10 @@ public class JournalController {
private UserCollectService userCollectService; private UserCollectService userCollectService;
@Autowired @Autowired
private ArticleService articleService; private ArticleService articleService;
@Autowired
private TagDao tagDao;
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@ -107,6 +117,13 @@ public class JournalController {
journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + article.getImage()); journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + article.getImage());
journalRespDTO.setDate(getEditDate(article)); journalRespDTO.setDate(getEditDate(article));
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
int limit = RandomSource.numberSource().randomInt(1, 3);
List<String> 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; return journalRespDTO;
} }

@ -1,8 +1,10 @@
package com.luoo.music.dao; package com.luoo.music.dao;
import com.luoo.music.pojo.Song;
import com.luoo.music.pojo.Tag; import com.luoo.music.pojo.Tag;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -13,4 +15,7 @@ import java.util.Set;
public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExecutor<Tag>{ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExecutor<Tag>{
List<Tag> findByIdIn(Set<String> ids); List<Tag> findByIdIn(Set<String> ids);
@Query(value = "select * from tb_tag_info where parent_id='' order by rand() limit ?1 ", nativeQuery = true)
List<Tag> random(int limit);
} }

@ -1,11 +1,14 @@
package com.luoo.user.util; package com.luoo.user.util;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import org.junit.Test; import org.junit.Test;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import com.apifan.common.random.RandomSource; import com.apifan.common.random.RandomSource;
import com.apifan.common.random.entity.Poem;
public class NickNameUtilTest { public class NickNameUtilTest {
int size = 4; int size = 4;
@ -27,6 +30,11 @@ public class NickNameUtilTest {
} }
sw.stop(); sw.stop();
System.out.println(sw.prettyPrint()); 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() { public String getRandomNickName() {

Loading…
Cancel
Save