1.remove fake data

main
Gary 9 months ago
parent d94101da03
commit cef8b92cf0

@ -28,29 +28,6 @@ import util.DateUtil;
import util.StringTools; import util.StringTools;
public class JournalMapper { public class JournalMapper {
// mock data
private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
private static final Map<String, List<String>> journalTagMap = new HashMap<>();
private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" };
static {
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();
}
public static JournalRespDTO getJournalRespDTO(Journal journal) { public static JournalRespDTO getJournalRespDTO(Journal journal) {
return getJournalRespDTO(journal, Collections.emptySet()); return getJournalRespDTO(journal, Collections.emptySet());
} }
@ -70,17 +47,9 @@ public class JournalMapper {
List<String> tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList()); List<String> tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList());
journalRespDTO.setTags(tags); journalRespDTO.setTags(tags);
} }
String content = journal.getContent(); journalRespDTO.setContent(journal.getContent());
if (StringTools.isEmpty(content)) { journalRespDTO.setSummary(journal.getSummary());
Poem poem = RandomSource.languageSource().randomTangPoem(); journalRespDTO.setEditor(journal.getUserName());
journalRespDTO.setEditor(poem.getAuthor());
journalRespDTO.setContent(Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n")));
journalRespDTO.setSummary(journalRespDTO.getContent());
} else {
journalRespDTO.setContent(content);
journalRespDTO.setSummary(journal.getSummary());
journalRespDTO.setEditor(getEditor(journal.getUserName()));
}
return journalRespDTO; return journalRespDTO;
} }
@ -96,15 +65,6 @@ public class JournalMapper {
return journalRespDTO; return journalRespDTO;
} }
private static String getEditor(String userName) {
return StringTools.isEmpty(userName) ? EDITOR[RandomSource.numberSource().randomInt(0, EDITOR.length)]
: userName;
}
public static List<String> getTags(String journalNo) {
return journalTagMap.getOrDefault(journalNo, Collections.emptyList());
}
private static String getPublishDate(Journal journal) { private static String getPublishDate(Journal journal) {
LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime(); LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime();
return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()); return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());

Loading…
Cancel
Save