+ * JobFactory实例 + *
+ * + * @author DengMin + * @since 2020/12/9 + */ +@Component +public class JobFactory extends AdaptableJobFactory { + + private AutowireCapableBeanFactory factory; + + public JobFactory(AutowireCapableBeanFactory factory) { + this.factory = factory; + } + + @Override + protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { + Object job = super.createJobInstance(bundle); + factory.autowireBean(job); + return job; + } +} diff --git a/src/main/java/com/subsidy/common/configure/QuartzConfig.java b/src/main/java/com/subsidy/common/configure/QuartzConfig.java new file mode 100644 index 0000000..cdb7008 --- /dev/null +++ b/src/main/java/com/subsidy/common/configure/QuartzConfig.java @@ -0,0 +1,45 @@ +package com.subsidy.common.configure; + +import org.quartz.Scheduler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import javax.sql.DataSource; + +/** + *+ * Quartz配置 + *
+ * + * @author DengMin + * @since 2020/12/8 + */ +@Configuration +public class QuartzConfig { + + @Autowired + private JobFactory jobFactory; + + @Autowired + private DataSource dataSource; + + @Bean + public SchedulerFactoryBean schedulerFactoryBean() { + SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); + schedulerFactoryBean.setOverwriteExistingJobs(true); + schedulerFactoryBean.setStartupDelay(60); + schedulerFactoryBean.setJobFactory(jobFactory); + schedulerFactoryBean.setOverwriteExistingJobs(true); + schedulerFactoryBean.setStartupDelay(1); + schedulerFactoryBean.setDataSource(dataSource); + schedulerFactoryBean.setConfigLocation(new ClassPathResource("/application-quartz.properties")); + return schedulerFactoryBean; + } + + @Bean + public Scheduler scheduler() { + return schedulerFactoryBean().getScheduler(); + } +} diff --git a/src/main/java/com/subsidy/common/constant/CourseNotification.java b/src/main/java/com/subsidy/common/constant/CourseNotification.java new file mode 100644 index 0000000..449a57a --- /dev/null +++ b/src/main/java/com/subsidy/common/constant/CourseNotification.java @@ -0,0 +1,14 @@ +package com.subsidy.common.constant; + +public class CourseNotification { + + public static final String UNSENT = "待发送"; + + public static final String SENT = "已发送"; + + public static final String ALL = "全部成员"; + + public static final String NOT_SIGNED_IN = "未签到成员"; + + public static final String UNFINISHED = "未完课成员"; +} diff --git a/src/main/java/com/subsidy/controller/ClassNoticeController.java b/src/main/java/com/subsidy/controller/ClassNoticeController.java index bbe911f..8097ff0 100644 --- a/src/main/java/com/subsidy/controller/ClassNoticeController.java +++ b/src/main/java/com/subsidy/controller/ClassNoticeController.java @@ -3,6 +3,7 @@ package com.subsidy.controller; import com.subsidy.common.ResponseData; import com.subsidy.common.ResponseVO; +import com.subsidy.dto.classNotice.SendNotificationDTO; import com.subsidy.model.ClassNoticeDO; import com.subsidy.service.ClassNoticeService; import io.swagger.annotations.ApiOperation; @@ -23,7 +24,7 @@ import io.swagger.annotations.Api; * @since 2022-01-21 */ @RestController -@Api(tags = "") +@Api(tags = "课程通知") @RequestMapping("/classNotice") public class ClassNoticeController { @@ -31,7 +32,7 @@ public class ClassNoticeController { private ClassNoticeService classNoticeService; @PostMapping("addNotice") - @ApiOperation("新增一个通知 classId noticeType isAuto noticeTime") + @ApiOperation("新增一个通知 classId noticeType isAuto noticeTime") public ResponseVO addNotice(@RequestBody ClassNoticeDO classNoticeDO){ return ResponseData.generateCreatedResponse(0,classNoticeService.addNotice(classNoticeDO)); } @@ -49,12 +50,15 @@ public class ClassNoticeController { } @PostMapping("queryClassNotices") - @ApiOperation("查看某个课程的通知提醒 classId 课程id") + @ApiOperation("查看某个课程的通知提醒 classId 课程id status 状态(待发送/已发送)") public ResponseVO queryClassNotices(ClassNoticeDO classNoticeDO){ return ResponseData.generateCreatedResponse(0,classNoticeService.queryClassNotices(classNoticeDO)); } - - - + @PostMapping("sendClassNotices") + @ApiOperation("发送通知:classId/课程Id sendType/发送类型(全部成员/未签到成员/未完课成员)") + public ResponseVO sendClassNotices(@RequestBody SendNotificationDTO sendNotificationDTO) { + classNoticeService.sendNotification(sendNotificationDTO); + return ResponseData.generateCreatedResponse(0); + } } diff --git a/src/main/java/com/subsidy/dto/classNotice/SendNotificationDTO.java b/src/main/java/com/subsidy/dto/classNotice/SendNotificationDTO.java new file mode 100644 index 0000000..bfa506d --- /dev/null +++ b/src/main/java/com/subsidy/dto/classNotice/SendNotificationDTO.java @@ -0,0 +1,11 @@ +package com.subsidy.dto.classNotice; + +import lombok.Data; + +@Data +public class SendNotificationDTO { + + private Long classId; + + private String sendType; +} diff --git a/src/main/java/com/subsidy/jobs/CourseNotificationJob.java b/src/main/java/com/subsidy/jobs/CourseNotificationJob.java new file mode 100644 index 0000000..3388b6b --- /dev/null +++ b/src/main/java/com/subsidy/jobs/CourseNotificationJob.java @@ -0,0 +1,58 @@ +package com.subsidy.jobs; + +import com.subsidy.common.constant.CourseNotification; +import com.subsidy.mapper.ClassNoticeMapper; +import com.subsidy.mapper.MemberMapper; +import com.subsidy.model.ClassNoticeDO; +import com.subsidy.model.MemberDO; +import com.subsidy.util.SMSUtils; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +/** + *+ * 课程通知 + *
+ * + * @author DengMin + * @since 2022/2/14 + */ +@Component +public class CourseNotificationJob implements Job { + + @Autowired + private MemberMapper memberMapper; + + @Autowired + private ClassNoticeMapper classNoticeMapper; + + @Autowired + private SMSUtils smsUtils; + + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + Map- * 定时器 - *
- * - * @author DengMin - * @since 2021/12/21 - */ - -@Component -public class Scheduler { - - @Autowired - private OprAdmDictMapper oprAdmDictMapper; - - @Autowired - private OprMemDictMapper oprMemDictMapper; - - @Autowired - private VodPlayHistoryMapper vodPlayHistoryMapper; - - @Autowired - private SignInRecordMapper signInRecordMapper; - - @Autowired - private RedisUtil redisUtil; - - @Autowired - private MongoTemplate mongoTemplate; - /** - 删除十天前登录记录(管理端) - */ - //@Scheduled(cron = "0 42 18 * * ?") - public void delOprAdmRecord() { - List+ * 定时器 + *
+ * + * @author DengMin + * @since 2021/12/21 + */ + +@Component +public class SchedulerJob { + + @Autowired + private OprAdmDictMapper oprAdmDictMapper; + + @Autowired + private OprMemDictMapper oprMemDictMapper; + + @Autowired + private VodPlayHistoryMapper vodPlayHistoryMapper; + + @Autowired + private SignInRecordMapper signInRecordMapper; + + @Autowired + private RedisUtil redisUtil; + + @Autowired + private MongoTemplate mongoTemplate; + /** + 删除十天前登录记录(管理端) + */ + //@Scheduled(cron = "0 42 18 * * ?") + public void delOprAdmRecord() { + List
@@ -21,8 +36,34 @@ import java.util.List;
@Service
public class ClassNoticeServiceImpl extends ServiceImpl