Сообщения сохраняются в формате JSON, отправка пока не отложенная
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.context.domain.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "deferred_messages")
|
||||||
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
|
public class DeferredMessage {
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
private int id;
|
||||||
|
@Column(name = "message")
|
||||||
|
private String message;
|
||||||
|
@Column (name = "time")
|
||||||
|
private LocalDateTime time;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||||
|
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,15 @@
|
|||||||
<artifactId>jakarta.el</artifactId>
|
<artifactId>jakarta.el</artifactId>
|
||||||
<version>4.0.2</version>
|
<version>4.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.struchkov.bot.gitlab</groupId>
|
||||||
|
<artifactId>bot-data</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.core.service.impl;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.entity.DeferredMessage;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.*;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.project.NewProjectNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.task.TaskCloseNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.data.jpa.DelayedNotifyJpaRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DelayedNotifyServiceImpl {
|
||||||
|
|
||||||
|
private final DelayedNotifyJpaRepository delayedNotifyJpaRepository;
|
||||||
|
|
||||||
|
public <T extends Notify> void save(T notify) {
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
DeferredMessage deferredMessage = new DeferredMessage();
|
||||||
|
String notifyForSave = gson.toJson(notify);
|
||||||
|
deferredMessage.setMessage(notifyForSave);
|
||||||
|
deferredMessage.setTime(LocalDateTime.now().plusNanos(0));
|
||||||
|
delayedNotifyJpaRepository.save(deferredMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Notify> void getNotifyFromDb(T notify){
|
||||||
|
Class<? extends Notify> newNotify;
|
||||||
|
|
||||||
|
switch (notify.getType()) {
|
||||||
|
case ConflictMrNotify.TYPE:
|
||||||
|
newNotify = ConflictMrNotify.class;
|
||||||
|
break;
|
||||||
|
case DiscussionNewNotify.TYPE:
|
||||||
|
newNotify = DiscussionNewNotify.class;
|
||||||
|
break;
|
||||||
|
case NewCommentNotify.TYPE:
|
||||||
|
newNotify = NewCommentNotify.class;
|
||||||
|
break;
|
||||||
|
case NewMrForAssignee.TYPE:
|
||||||
|
newNotify = NewMrForAssignee.class;
|
||||||
|
break;
|
||||||
|
case NewMrForReview.TYPE:
|
||||||
|
newNotify = NewMrForReview.class;
|
||||||
|
break;
|
||||||
|
case NewProjectNotify.TYPE:
|
||||||
|
newNotify = NewProjectNotify.class;
|
||||||
|
break;
|
||||||
|
case PipelineNotify.TYPE:
|
||||||
|
newNotify = PipelineNotify.class;
|
||||||
|
break;
|
||||||
|
case StatusMrNotify.TYPE:
|
||||||
|
newNotify = StatusMrNotify.class;
|
||||||
|
break;
|
||||||
|
case TaskCloseNotify.TYPE:
|
||||||
|
newNotify = TaskCloseNotify.class;
|
||||||
|
break;
|
||||||
|
case UpdateMrNotify.TYPE:
|
||||||
|
newNotify = UpdateMrNotify.class;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,18 +12,21 @@ public class NotifyServiceImpl implements NotifyService {
|
|||||||
|
|
||||||
private final MessageSendService messageSendService;
|
private final MessageSendService messageSendService;
|
||||||
private final AppSettingService settingService;
|
private final AppSettingService settingService;
|
||||||
|
private final DelayedNotifyServiceImpl delayedNotifyService;
|
||||||
|
|
||||||
public NotifyServiceImpl(
|
public NotifyServiceImpl(
|
||||||
@Lazy MessageSendService messageSendService,
|
@Lazy MessageSendService messageSendService,
|
||||||
AppSettingService settingService
|
AppSettingService settingService,
|
||||||
) {
|
DelayedNotifyServiceImpl delayedNotifyService) {
|
||||||
this.messageSendService = messageSendService;
|
this.messageSendService = messageSendService;
|
||||||
this.settingService = settingService;
|
this.settingService = settingService;
|
||||||
|
this.delayedNotifyService = delayedNotifyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Notify> void send(T notify) {
|
public <T extends Notify> void send(T notify) {
|
||||||
if (settingService.isEnableAllNotify()) {
|
if (settingService.isEnableAllNotify()) {
|
||||||
|
delayedNotifyService.save(notify);
|
||||||
messageSendService.send(notify);
|
messageSendService.send(notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.data.jpa;
|
||||||
|
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.entity.DeferredMessage;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface DelayedNotifyJpaRepository extends JpaRepository<DeferredMessage, Long> {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user