Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save centralhardware/583d2d30673277ef4ae7725f0c0de32f to your computer and use it in GitHub Desktop.
Save centralhardware/583d2d30673277ef4ae7725f0c0de32f to your computer and use it in GitHub Desktop.
sdf.java
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