Created
February 9, 2024 18:58
-
-
Save centralhardware/583d2d30673277ef4ae7725f0c0de32f to your computer and use it in GitHub Desktop.
sdf.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void saveStatisticOutcome(Object object){ | |
String chatId; | |
String text; | |
if (object instanceof SendMessage sendMessage){ | |
chatId = sendMessage.getChatId(); | |
text = sendMessage.getText(); | |
} else if (object instanceof SendPhoto sendPhoto){ | |
chatId = sendPhoto.getChatId(); | |
text = sendPhoto.getCaption(); | |
} else if (object instanceof DeleteMessage deleteMessage){ | |
chatId = deleteMessage.getChatId(); | |
text = deleteMessage.getMessageId().toString(); | |
} else if (object instanceof SendChatAction sendChatAction){ | |
chatId = sendChatAction.getChatId(); | |
text = sendChatAction.getActionType().toString(); | |
} else if (object instanceof AnswerCallbackQuery){ | |
return; | |
} else { | |
throw new IllegalStateException(); | |
} | |
var entry = LogEntry.builder() | |
.dateTime(LocalDateTime.now()) | |
.chatId(Long.valueOf(chatId)) | |
.username(currentUser.getUsername()) | |
.firstName(currentUser.getFirstName()) | |
.lastName(currentUser.getLastName()) | |
.isPremium(currentUser.getIsPremium()) | |
.action(clazz2action.get(object.getClass())) | |
.text(text) | |
.bookId(currentBook.getBookId()) | |
.partId(currentBook.getPartId()) | |
.authorId(engine.getAuthorId()) | |
.build(); | |
clickhouse.insert(entry); | |
log.info(""" | |
Save to clickHouse( | |
dateTime: {}, | |
chatId; {}, | |
username: {}, | |
firstName: {}, | |
lastName: {}, | |
isPremium: {}, | |
action: {}, | |
text: {}, | |
bookId: {}, | |
partId: {}, | |
authorId: {}) | |
""", | |
entry.dateTime(), | |
entry.chatId(), | |
entry.username(), | |
entry.firstName(), | |
entry.lastName(), | |
entry.isPremium(), | |
entry.action(), | |
entry.text(), | |
entry.bookId(), | |
currentBook.getPartId(), | |
entry.authorId()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment