mirror of
https://github.com/1Panel-dev/CordysCRM.git
synced 2026-05-24 03:38:42 +08:00
refactor: job centralized management
This commit is contained in:
@@ -23,7 +23,7 @@ spring.datasource.hikari.connection-test-query=SELECT 1
|
||||
|
||||
# Quartz Scheduler DataSource Settings
|
||||
quartz.enabled=true
|
||||
quartz.scheduler-name=cordysCRMScheduler
|
||||
quartz.scheduler-name=CORDYS-CRM-QUARTZ
|
||||
quartz.thread-count=10
|
||||
quartz.properties.org.quartz.jobStore.acquireTriggersWithinLock=true
|
||||
|
||||
|
||||
@@ -16,14 +16,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class AddAnnounceNoticeJob {
|
||||
public class AnnounceToNotifyJob {
|
||||
@Resource
|
||||
private ExtAnnouncementMapper extAnnouncementMapper;
|
||||
|
||||
@Resource
|
||||
private AnnouncementService announcementService;
|
||||
|
||||
|
||||
/**
|
||||
* 将到期发布的公告转成通知 每天凌晨三点执行
|
||||
*/
|
||||
@@ -43,13 +41,13 @@ public class AddAnnounceNoticeJob {
|
||||
return;
|
||||
}
|
||||
//将公告根据接收人生成相关的通知
|
||||
List<String>ids = new ArrayList<>();
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (AnnouncementDTO announcementDTO : announcementDTOS) {
|
||||
List<String> userIds = JSON.parseArray(new String(announcementDTO.getReceiver()), String.class);
|
||||
announcementService.convertNotification("admin",announcementDTO,userIds);
|
||||
announcementService.convertNotification("admin", announcementDTO, userIds);
|
||||
ids.add(announcementDTO.getId());
|
||||
}
|
||||
extAnnouncementMapper.updateNotice(ids,true,announcementDTOS.getFirst().getOrganizationId());
|
||||
extAnnouncementMapper.updateNotice(ids, true, announcementDTOS.getFirst().getOrganizationId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.cordys.crm.system.job;
|
||||
|
||||
import com.fit2cloud.quartz.anno.QuartzScheduled;
|
||||
import io.cordys.crm.system.notice.sse.SseService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SSENotificationJob {
|
||||
|
||||
@Resource
|
||||
private SseService sseService;
|
||||
|
||||
/**
|
||||
* 每 5 秒向对应客户端推送一次消息
|
||||
*/
|
||||
@QuartzScheduled(fixedRate = 5000)
|
||||
public void broadcastPeriodically() {
|
||||
sseService.broadcastPeriodically();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package io.cordys.crm.system.notice.sse;
|
||||
|
||||
import io.cordys.common.util.LogUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
@@ -61,7 +60,6 @@ public class SseService {
|
||||
/**
|
||||
* 每隔 5 秒向所有客户端广播一次事件
|
||||
*/
|
||||
@Scheduled(fixedRate = 5000) // 单位:毫秒
|
||||
public void broadcastPeriodically() {
|
||||
// 如果没有客户端连接,则不广播
|
||||
if (emitters.isEmpty()) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.cordys.crm.system.domain.Announcement;
|
||||
import io.cordys.crm.system.domain.Notification;
|
||||
import io.cordys.crm.system.dto.AnnouncementReceiveTypeDTO;
|
||||
import io.cordys.crm.system.dto.response.NotificationDTO;
|
||||
import io.cordys.crm.system.job.AddAnnounceNoticeJob;
|
||||
import io.cordys.crm.system.job.AnnounceToNotifyJob;
|
||||
import io.cordys.crm.system.mapper.ExtNotificationMapper;
|
||||
import io.cordys.mybatis.BaseMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
public class AddNotificationJobTests {
|
||||
|
||||
@Resource
|
||||
private AddAnnounceNoticeJob addAnnounceNoticeJob;
|
||||
private AnnounceToNotifyJob announceToNotifyJob;
|
||||
|
||||
@Resource
|
||||
private BaseMapper<Announcement> announcementBaseMapper;
|
||||
@@ -57,7 +57,7 @@ public class AddNotificationJobTests {
|
||||
saveNotice();
|
||||
List<Announcement> createTimeAsc = announcementBaseMapper.selectAll("create_time asc");
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(createTimeAsc));
|
||||
addAnnounceNoticeJob.addNotification();
|
||||
announceToNotifyJob.addNotification();
|
||||
Notification notification = new Notification();
|
||||
notification.setOrganizationId("100001");
|
||||
notification.setResourceId("SDDFDJJND");
|
||||
|
||||
Reference in New Issue
Block a user