From c8ff39afa0ea0a4a29edf8c56ab0a5ee165bbfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Tue, 11 Oct 2022 21:52:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E5=9D=97=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maku-boot-module/maku-boot-message/pom.xml | 42 ----- .../main/java/net/maku/message/api/SmsApiImpl.java | 55 ------ .../net/maku/message/cache/SmsPlatformCache.java | 48 ----- .../java/net/maku/message/cache/SmsSendCache.java | 43 ----- .../maku/message/controller/SmsLogController.java | 48 ----- .../message/controller/SmsPlatformController.java | 113 ------------ .../net/maku/message/convert/SmsLogConvert.java | 23 --- .../maku/message/convert/SmsPlatformConvert.java | 30 ---- .../main/java/net/maku/message/dao/SmsLogDao.java | 15 -- .../java/net/maku/message/dao/SmsPlatformDao.java | 15 -- .../java/net/maku/message/entity/SmsLogEntity.java | 63 ------- .../net/maku/message/entity/SmsPlatformEntity.java | 62 ------- .../net/maku/message/enums/SmsPlatformEnum.java | 33 ---- .../java/net/maku/message/query/SmsLogQuery.java | 23 --- .../net/maku/message/query/SmsPlatformQuery.java | 23 --- .../net/maku/message/service/SmsLogService.java | 18 -- .../maku/message/service/SmsPlatformService.java | 32 ---- .../message/service/impl/SmsLogServiceImpl.java | 41 ----- .../service/impl/SmsPlatformServiceImpl.java | 90 ---------- .../net/maku/message/sms/AliyunSmsStrategy.java | 64 ------- .../net/maku/message/sms/HuaweiSmsStrategy.java | 194 --------------------- .../net/maku/message/sms/QiniuSmsStrategy.java | 40 ----- .../main/java/net/maku/message/sms/SmsContext.java | 34 ---- .../java/net/maku/message/sms/SmsStrategy.java | 18 -- .../net/maku/message/sms/TencentSmsStrategy.java | 76 -------- .../net/maku/message/sms/config/SmsConfig.java | 57 ------ .../net/maku/message/sms/service/SmsService.java | 107 ------------ .../main/java/net/maku/message/vo/SmsLogVO.java | 46 ----- .../java/net/maku/message/vo/SmsPlatformVO.java | 55 ------ .../main/java/net/maku/message/vo/SmsSendVO.java | 30 ---- .../src/main/resources/mapper/SmsLogDao.xml | 6 - .../src/main/resources/mapper/SmsPlatformDao.xml | 6 - maku-boot-module/maku-boot-quartz/pom.xml | 23 --- .../net/maku/quartz/config/ScheduleConfig.java | 52 ------ .../quartz/controller/ScheduleJobController.java | 102 ----------- .../controller/ScheduleJobLogController.java | 51 ------ .../maku/quartz/convert/ScheduleJobConvert.java | 25 --- .../maku/quartz/convert/ScheduleJobLogConvert.java | 25 --- .../java/net/maku/quartz/dao/ScheduleJobDao.java | 15 -- .../net/maku/quartz/dao/ScheduleJobLogDao.java | 15 -- .../net/maku/quartz/entity/ScheduleJobEntity.java | 108 ------------ .../maku/quartz/entity/ScheduleJobLogEntity.java | 76 -------- .../maku/quartz/enums/ScheduleConcurrentEnum.java | 24 --- .../net/maku/quartz/enums/ScheduleStatusEnum.java | 24 --- .../net/maku/quartz/query/ScheduleJobLogQuery.java | 26 --- .../net/maku/quartz/query/ScheduleJobQuery.java | 26 --- .../maku/quartz/service/ScheduleJobLogService.java | 18 -- .../maku/quartz/service/ScheduleJobService.java | 29 --- .../service/impl/ScheduleJobLogServiceImpl.java | 43 ----- .../service/impl/ScheduleJobServiceImpl.java | 126 ------------- .../main/java/net/maku/quartz/task/TestTask.java | 19 -- .../net/maku/quartz/utils/AbstractScheduleJob.java | 83 --------- .../main/java/net/maku/quartz/utils/CronUtils.java | 33 ---- .../quartz/utils/ScheduleConcurrentExecution.java | 11 -- .../utils/ScheduleDisallowConcurrentExecution.java | 14 -- .../java/net/maku/quartz/utils/ScheduleUtils.java | 161 ----------------- .../java/net/maku/quartz/vo/ScheduleJobLogVO.java | 55 ------ .../java/net/maku/quartz/vo/ScheduleJobVO.java | 55 ------ maku-boot-module/maku-module-message/pom.xml | 42 +++++ .../main/java/net/maku/message/api/SmsApiImpl.java | 55 ++++++ .../net/maku/message/cache/SmsPlatformCache.java | 48 +++++ .../java/net/maku/message/cache/SmsSendCache.java | 43 +++++ .../maku/message/controller/SmsLogController.java | 48 +++++ .../message/controller/SmsPlatformController.java | 113 ++++++++++++ .../net/maku/message/convert/SmsLogConvert.java | 23 +++ .../maku/message/convert/SmsPlatformConvert.java | 30 ++++ .../main/java/net/maku/message/dao/SmsLogDao.java | 15 ++ .../java/net/maku/message/dao/SmsPlatformDao.java | 15 ++ .../java/net/maku/message/entity/SmsLogEntity.java | 63 +++++++ .../net/maku/message/entity/SmsPlatformEntity.java | 62 +++++++ .../net/maku/message/enums/SmsPlatformEnum.java | 33 ++++ .../java/net/maku/message/query/SmsLogQuery.java | 23 +++ .../net/maku/message/query/SmsPlatformQuery.java | 23 +++ .../net/maku/message/service/SmsLogService.java | 18 ++ .../maku/message/service/SmsPlatformService.java | 32 ++++ .../message/service/impl/SmsLogServiceImpl.java | 41 +++++ .../service/impl/SmsPlatformServiceImpl.java | 90 ++++++++++ .../net/maku/message/sms/AliyunSmsStrategy.java | 64 +++++++ .../net/maku/message/sms/HuaweiSmsStrategy.java | 194 +++++++++++++++++++++ .../net/maku/message/sms/QiniuSmsStrategy.java | 40 +++++ .../main/java/net/maku/message/sms/SmsContext.java | 34 ++++ .../java/net/maku/message/sms/SmsStrategy.java | 18 ++ .../net/maku/message/sms/TencentSmsStrategy.java | 76 ++++++++ .../net/maku/message/sms/config/SmsConfig.java | 57 ++++++ .../net/maku/message/sms/service/SmsService.java | 107 ++++++++++++ .../main/java/net/maku/message/vo/SmsLogVO.java | 46 +++++ .../java/net/maku/message/vo/SmsPlatformVO.java | 55 ++++++ .../main/java/net/maku/message/vo/SmsSendVO.java | 30 ++++ .../src/main/resources/mapper/SmsLogDao.xml | 6 + .../src/main/resources/mapper/SmsPlatformDao.xml | 6 + maku-boot-module/maku-module-quartz/pom.xml | 23 +++ .../net/maku/quartz/config/ScheduleConfig.java | 52 ++++++ .../quartz/controller/ScheduleJobController.java | 102 +++++++++++ .../controller/ScheduleJobLogController.java | 51 ++++++ .../maku/quartz/convert/ScheduleJobConvert.java | 25 +++ .../maku/quartz/convert/ScheduleJobLogConvert.java | 25 +++ .../java/net/maku/quartz/dao/ScheduleJobDao.java | 15 ++ .../net/maku/quartz/dao/ScheduleJobLogDao.java | 15 ++ .../net/maku/quartz/entity/ScheduleJobEntity.java | 108 ++++++++++++ .../maku/quartz/entity/ScheduleJobLogEntity.java | 76 ++++++++ .../maku/quartz/enums/ScheduleConcurrentEnum.java | 24 +++ .../net/maku/quartz/enums/ScheduleStatusEnum.java | 24 +++ .../net/maku/quartz/query/ScheduleJobLogQuery.java | 26 +++ .../net/maku/quartz/query/ScheduleJobQuery.java | 26 +++ .../maku/quartz/service/ScheduleJobLogService.java | 18 ++ .../maku/quartz/service/ScheduleJobService.java | 29 +++ .../service/impl/ScheduleJobLogServiceImpl.java | 43 +++++ .../service/impl/ScheduleJobServiceImpl.java | 126 +++++++++++++ .../main/java/net/maku/quartz/task/TestTask.java | 19 ++ .../net/maku/quartz/utils/AbstractScheduleJob.java | 83 +++++++++ .../main/java/net/maku/quartz/utils/CronUtils.java | 33 ++++ .../quartz/utils/ScheduleConcurrentExecution.java | 11 ++ .../utils/ScheduleDisallowConcurrentExecution.java | 14 ++ .../java/net/maku/quartz/utils/ScheduleUtils.java | 161 +++++++++++++++++ .../java/net/maku/quartz/vo/ScheduleJobLogVO.java | 55 ++++++ .../java/net/maku/quartz/vo/ScheduleJobVO.java | 55 ++++++ maku-boot-module/pom.xml | 4 +- maku-server/pom.xml | 4 +- 118 files changed, 2793 insertions(+), 2793 deletions(-) delete mode 100644 maku-boot-module/maku-boot-message/pom.xml delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/api/SmsApiImpl.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsSendCache.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsLogController.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsPlatformController.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsLogConvert.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsLogDao.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsLogEntity.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsLogQuery.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsLogService.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsPlatformService.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsContext.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsStrategy.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/config/SmsConfig.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/service/SmsService.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsLogVO.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsSendVO.java delete mode 100644 maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsLogDao.xml delete mode 100644 maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsPlatformDao.xml delete mode 100644 maku-boot-module/maku-boot-quartz/pom.xml delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/task/TestTask.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java delete mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java create mode 100644 maku-boot-module/maku-module-message/pom.xml create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsSendCache.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsLogController.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsPlatformController.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsLogConvert.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsLogDao.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsLogEntity.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsLogQuery.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsLogService.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsPlatformService.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsContext.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsStrategy.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/config/SmsConfig.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/service/SmsService.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsLogVO.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java create mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsSendVO.java create mode 100644 maku-boot-module/maku-module-message/src/main/resources/mapper/SmsLogDao.xml create mode 100644 maku-boot-module/maku-module-message/src/main/resources/mapper/SmsPlatformDao.xml create mode 100644 maku-boot-module/maku-module-quartz/pom.xml create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/task/TestTask.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java create mode 100644 maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java diff --git a/maku-boot-module/maku-boot-message/pom.xml b/maku-boot-module/maku-boot-message/pom.xml deleted file mode 100644 index 0115a13..0000000 --- a/maku-boot-module/maku-boot-message/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - net.maku - maku-boot-module - ${revision} - - 4.0.0 - maku-boot-message - jar - - - - net.maku - maku-framework - ${revision} - - - net.maku - maku-boot-api - ${revision} - - - com.aliyun - dysmsapi20170525 - - - com.squareup.okhttp3 - okhttp - - - com.tencentcloudapi - tencentcloud-sdk-java - - - com.qiniu - qiniu-java-sdk - - - - - \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/api/SmsApiImpl.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/api/SmsApiImpl.java deleted file mode 100644 index 1c7fce1..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/api/SmsApiImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.maku.message.api; - -import lombok.AllArgsConstructor; -import net.maku.api.module.message.SmsApi; -import net.maku.message.cache.SmsSendCache; -import net.maku.message.sms.service.SmsService; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * 短信服务Api - * - * @author 阿沐 babamu@126.com - */ -@Component -@AllArgsConstructor -public class SmsApiImpl implements SmsApi { - private final SmsService smsService; - private final SmsSendCache smsSendCache; - - @Override - public boolean send(String mobile, Map params) { - return smsService.send(mobile, params); - } - - @Override - public boolean sendCode(String mobile, String key, String value) { - // 短信参数 - Map params = new HashMap<>(); - params.put(key, value); - - // 发送短信 - boolean flag = smsService.send(mobile, params); - if (flag) { - smsSendCache.saveCode(mobile, value); - } - return flag; - } - - @Override - public boolean verifyCode(String mobile, String code) { - String value = smsSendCache.getCode(mobile); - if (value != null) { - // 删除短信验证码 - smsSendCache.deleteCode(mobile); - - // 效验 - return value.equalsIgnoreCase(code); - } - - return false; - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java deleted file mode 100644 index fa810cf..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.maku.message.cache; - -import lombok.AllArgsConstructor; -import net.maku.framework.common.cache.RedisCache; -import net.maku.message.sms.config.SmsConfig; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * 短信平台 Cache - * - * @author 阿沐 babamu@126.com - */ -@Service -@AllArgsConstructor -public class SmsPlatformCache { - private final RedisCache redisCache; - - /** - * 短信平台轮询KEY - */ - private final String SMS_ROUND_KEY = "message:sms:round"; - - /** - * 短信平台列表KEY - */ - private final String SMS_PLATFORM_KEY = "message:sms:platform"; - - /** - * 获取短信轮询值 - */ - public Long getRoundValue() { - return redisCache.increment(SMS_ROUND_KEY); - } - - public List list() { - return (List) redisCache.get(SMS_PLATFORM_KEY); - } - - public void save(List list) { - redisCache.set(SMS_PLATFORM_KEY, list); - } - - public void delete() { - redisCache.delete(SMS_PLATFORM_KEY); - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsSendCache.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsSendCache.java deleted file mode 100644 index de13918..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/cache/SmsSendCache.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.maku.message.cache; - -import lombok.AllArgsConstructor; -import net.maku.framework.common.cache.RedisCache; -import org.springframework.stereotype.Service; - -/** - * 短信发送 Cache - * - * @author 阿沐 babamu@126.com - */ -@Service -@AllArgsConstructor -public class SmsSendCache { - private final RedisCache redisCache; - - /** - * 获取发送手机短信验证码KEY - * - * @param mobile 手机号 - * @return KEY - */ - private String getCodeKey(String mobile) { - return "message:sms:code" + mobile; - } - - public void saveCode(String mobile, String code) { - String key = getCodeKey(mobile); - - // 保存到Redis,有效期10分钟 - redisCache.set(key, code, 10 * 60); - } - - public String getCode(String mobile) { - String key = getCodeKey(mobile); - return (String) redisCache.get(key); - } - - public void deleteCode(String mobile) { - String key = getCodeKey(mobile); - redisCache.delete(key); - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsLogController.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsLogController.java deleted file mode 100644 index 309a4e8..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsLogController.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.maku.message.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.utils.Result; -import net.maku.message.convert.SmsLogConvert; -import net.maku.message.entity.SmsLogEntity; -import net.maku.message.query.SmsLogQuery; -import net.maku.message.service.SmsLogService; -import net.maku.message.vo.SmsLogVO; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; - -/** -* 短信日志 -* -* @author 阿沐 babamu@126.com -*/ -@RestController -@RequestMapping("message/sms/log") -@Tag(name="短信日志") -@AllArgsConstructor -public class SmsLogController { - private final SmsLogService smsLogService; - - @GetMapping("page") - @Operation(summary = "分页") - @PreAuthorize("hasAuthority('sms:log')") - public Result> page(@Valid SmsLogQuery query){ - PageResult page = smsLogService.page(query); - - return Result.ok(page); - } - - @GetMapping("{id}") - @Operation(summary = "信息") - @PreAuthorize("hasAuthority('sms:log')") - public Result get(@PathVariable("id") Long id){ - SmsLogEntity entity = smsLogService.getById(id); - - return Result.ok(SmsLogConvert.INSTANCE.convert(entity)); - } - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsPlatformController.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsPlatformController.java deleted file mode 100644 index 2a32079..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/controller/SmsPlatformController.java +++ /dev/null @@ -1,113 +0,0 @@ -package net.maku.message.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.utils.ExceptionUtils; -import net.maku.framework.common.utils.Result; -import net.maku.message.convert.SmsPlatformConvert; -import net.maku.message.entity.SmsPlatformEntity; -import net.maku.message.query.SmsPlatformQuery; -import net.maku.message.service.SmsPlatformService; -import net.maku.message.sms.SmsContext; -import net.maku.message.sms.config.SmsConfig; -import net.maku.message.sms.service.SmsService; -import net.maku.message.vo.SmsPlatformVO; -import net.maku.message.vo.SmsSendVO; -import org.apache.commons.lang3.StringUtils; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * 短信平台 - * - * @author 阿沐 babamu@126.com - */ -@RestController -@RequestMapping("message/sms/platform") -@Tag(name = "短信平台") -@AllArgsConstructor -public class SmsPlatformController { - private final SmsPlatformService smsPlatformService; - private final SmsService smsService; - - @GetMapping("page") - @Operation(summary = "分页") - @PreAuthorize("hasAuthority('sms:platform:page')") - public Result> page(@Valid SmsPlatformQuery query) { - PageResult page = smsPlatformService.page(query); - - return Result.ok(page); - } - - @GetMapping("{id}") - @Operation(summary = "信息") - @PreAuthorize("hasAuthority('sms:platform:info')") - public Result get(@PathVariable("id") Long id) { - SmsPlatformEntity entity = smsPlatformService.getById(id); - - return Result.ok(SmsPlatformConvert.INSTANCE.convert(entity)); - } - - @PostMapping - @Operation(summary = "保存") - @PreAuthorize("hasAuthority('sms:platform:save')") - public Result save(@RequestBody SmsPlatformVO vo) { - smsPlatformService.save(vo); - - return Result.ok(); - } - - @PostMapping("send") - @Operation(summary = "发送短信") - @PreAuthorize("hasAuthority('sms:platform:update')") - public Result send(@RequestBody SmsSendVO vo) { - SmsPlatformEntity entity = smsPlatformService.getById(vo.getId()); - SmsConfig config = SmsPlatformConvert.INSTANCE.convert2(entity); - - // 短信参数 - Map params = new LinkedHashMap<>(); - if (StringUtils.isNotBlank(vo.getParamValue())) { - params.put(vo.getParamKey(), vo.getParamValue()); - } - - try { - // 发送短信 - new SmsContext(config).send(vo.getMobile(), params); - - // 保存日志 - smsService.saveLog(config, vo.getMobile(), params, null); - - return Result.ok(); - } catch (Exception e) { - // 保存日志 - smsService.saveLog(config, vo.getMobile(), params, e); - - return Result.error(ExceptionUtils.getExceptionMessage(e)); - } - } - - @PutMapping - @Operation(summary = "修改") - @PreAuthorize("hasAuthority('sms:platform:update')") - public Result update(@RequestBody @Valid SmsPlatformVO vo) { - smsPlatformService.update(vo); - - return Result.ok(); - } - - @DeleteMapping - @Operation(summary = "删除") - @PreAuthorize("hasAuthority('sms:platform:delete')") - public Result delete(@RequestBody List idList) { - smsPlatformService.delete(idList); - - return Result.ok(); - } -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsLogConvert.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsLogConvert.java deleted file mode 100644 index fb38ff7..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsLogConvert.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.maku.message.convert; - -import net.maku.message.entity.SmsLogEntity; -import net.maku.message.vo.SmsLogVO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** -* 短信日志 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface SmsLogConvert { - SmsLogConvert INSTANCE = Mappers.getMapper(SmsLogConvert.class); - - SmsLogVO convert(SmsLogEntity entity); - - List convertList(List list); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java deleted file mode 100644 index 1c8fd71..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.maku.message.convert; - -import net.maku.message.entity.SmsPlatformEntity; -import net.maku.message.sms.config.SmsConfig; -import net.maku.message.vo.SmsPlatformVO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** -* 短信平台 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface SmsPlatformConvert { - SmsPlatformConvert INSTANCE = Mappers.getMapper(SmsPlatformConvert.class); - - SmsPlatformEntity convert(SmsPlatformVO vo); - - SmsPlatformVO convert(SmsPlatformEntity entity); - - List convertList(List list); - - SmsConfig convert2(SmsPlatformEntity entity); - - List convertList2(List list); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsLogDao.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsLogDao.java deleted file mode 100644 index 01a9968..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsLogDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.maku.message.dao; - -import net.maku.framework.common.dao.BaseDao; -import net.maku.message.entity.SmsLogEntity; -import org.apache.ibatis.annotations.Mapper; - -/** -* 短信日志 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface SmsLogDao extends BaseDao { - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java deleted file mode 100644 index 33c6643..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.maku.message.dao; - -import net.maku.framework.common.dao.BaseDao; -import net.maku.message.entity.SmsPlatformEntity; -import org.apache.ibatis.annotations.Mapper; - -/** -* 短信平台 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface SmsPlatformDao extends BaseDao { - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsLogEntity.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsLogEntity.java deleted file mode 100644 index 9bcd179..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsLogEntity.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.maku.message.entity; - -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.Date; - -/** - * 短信日志 - * - * @author 阿沐 babamu@126.com - */ -@Data -@EqualsAndHashCode(callSuper=false) -@TableName("sms_log") -public class SmsLogEntity { - /** - * id - */ - @TableId - private Long id; - - /** - * 平台ID - */ - private Long platformId; - - /** - * 平台类型 - */ - private Integer platform; - - /** - * 手机号 - */ - private String mobile; - - /** - * 状态 0:失败 1:成功 - */ - private Integer status; - - /** - * 参数 - */ - private String params; - - /** - * 异常信息 - */ - private String error; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java deleted file mode 100644 index d91a0c0..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.maku.message.entity; - -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import net.maku.framework.common.entity.BaseEntity; - -/** - * 短信平台 - * - * @author 阿沐 babamu@126.com - */ -@Data -@EqualsAndHashCode(callSuper = false) -@TableName("sms_platform") -public class SmsPlatformEntity extends BaseEntity { - /** - * 平台类型 0:阿里云 1:腾讯云 2:七牛云 3:华为云 - */ - private Integer platform; - - /** - * 短信签名 - */ - private String signName; - - /** - * 短信模板 - */ - private String templateId; - - /** - * 短信应用的ID,如:腾讯云等 - */ - private String appId; - - /** - * 腾讯云国际短信、华为云等需要 - */ - private String senderId; - - /** - * 接入地址,如:华为云 - */ - private String url; - - /** - * AccessKey - */ - private String accessKey; - - /** - * SecretKey - */ - private String secretKey; - - /** - * 状态 0:禁用 1:启用 - */ - private Integer status; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java deleted file mode 100644 index c58ddec..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.maku.message.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信平台枚举 - * - * @author 阿沐 babamu@126.com - */ -@Getter -@AllArgsConstructor -public enum SmsPlatformEnum { - /** - * 阿里云 - */ - ALIYUN(0), - /** - * 腾讯云 - */ - TENCENT(1), - /** - * 七牛云 - */ - QINIU(2), - /** - * 华为云 - */ - HUAWEI(3); - - private final int value; - -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsLogQuery.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsLogQuery.java deleted file mode 100644 index c39453a..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsLogQuery.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.maku.message.query; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import net.maku.framework.common.query.Query; - -/** -* 短信日志查询 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "短信日志查询") -public class SmsLogQuery extends Query { - @Schema(description = "平台ID") - private Long platformId; - - @Schema(description = "平台类型") - private Integer platform; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java deleted file mode 100644 index c7e2d88..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.maku.message.query; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import net.maku.framework.common.query.Query; - -/** -* 短信平台查询 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "短信平台查询") -public class SmsPlatformQuery extends Query { - @Schema(description = "平台类型 0:阿里云 1:腾讯云") - private Integer platform; - - @Schema(description = "短信签名") - private String signName; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsLogService.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsLogService.java deleted file mode 100644 index 9332abe..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsLogService.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.maku.message.service; - -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.BaseService; -import net.maku.message.entity.SmsLogEntity; -import net.maku.message.query.SmsLogQuery; -import net.maku.message.vo.SmsLogVO; - -/** - * 短信日志 - * - * @author 阿沐 babamu@126.com - */ -public interface SmsLogService extends BaseService { - - PageResult page(SmsLogQuery query); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsPlatformService.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsPlatformService.java deleted file mode 100644 index a1a64fa..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/SmsPlatformService.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.maku.message.service; - -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.BaseService; -import net.maku.message.entity.SmsPlatformEntity; -import net.maku.message.query.SmsPlatformQuery; -import net.maku.message.sms.config.SmsConfig; -import net.maku.message.vo.SmsPlatformVO; - -import java.util.List; - -/** - * 短信平台 - * - * @author 阿沐 babamu@126.com - */ -public interface SmsPlatformService extends BaseService { - - PageResult page(SmsPlatformQuery query); - - /** - * 启用的短信平台列表 - */ - List listByEnable(); - - void save(SmsPlatformVO vo); - - void update(SmsPlatformVO vo); - - void delete(List idList); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java deleted file mode 100644 index efae8d8..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.maku.message.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.impl.BaseServiceImpl; -import net.maku.message.convert.SmsLogConvert; -import net.maku.message.dao.SmsLogDao; -import net.maku.message.entity.SmsLogEntity; -import net.maku.message.query.SmsLogQuery; -import net.maku.message.service.SmsLogService; -import net.maku.message.vo.SmsLogVO; -import org.springframework.stereotype.Service; - -/** - * 短信日志 - * - * @author 阿沐 babamu@126.com - */ -@Service -@AllArgsConstructor -public class SmsLogServiceImpl extends BaseServiceImpl implements SmsLogService { - - @Override - public PageResult page(SmsLogQuery query) { - IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); - - return new PageResult<>(SmsLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); - } - - private LambdaQueryWrapper getWrapper(SmsLogQuery query){ - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.eq(query.getPlatform() != null, SmsLogEntity::getPlatform, query.getPlatform()); - wrapper.like(query.getPlatformId() != null, SmsLogEntity::getPlatformId, query.getPlatformId()); - wrapper.orderByDesc(SmsLogEntity::getId); - return wrapper; - } - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java deleted file mode 100644 index 28c5c87..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -package net.maku.message.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import lombok.AllArgsConstructor; -import net.maku.framework.common.constant.Constant; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.impl.BaseServiceImpl; -import net.maku.message.cache.SmsPlatformCache; -import net.maku.message.convert.SmsPlatformConvert; -import net.maku.message.dao.SmsPlatformDao; -import net.maku.message.entity.SmsPlatformEntity; -import net.maku.message.query.SmsPlatformQuery; -import net.maku.message.service.SmsPlatformService; -import net.maku.message.sms.config.SmsConfig; -import net.maku.message.vo.SmsPlatformVO; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -/** - * 短信平台 - * - * @author 阿沐 babamu@126.com - */ -@Service -@AllArgsConstructor -public class SmsPlatformServiceImpl extends BaseServiceImpl implements SmsPlatformService { - private final SmsPlatformCache smsPlatformCache; - - @Override - public PageResult page(SmsPlatformQuery query) { - IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); - - return new PageResult<>(SmsPlatformConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); - } - - private LambdaQueryWrapper getWrapper(SmsPlatformQuery query){ - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.eq(query.getPlatform() != null, SmsPlatformEntity::getPlatform, query.getPlatform()); - wrapper.like(StrUtil.isNotBlank(query.getSignName()), SmsPlatformEntity::getSignName, query.getSignName()); - return wrapper; - } - - @Override - public List listByEnable() { - // 从缓存读取 - List cacheList = smsPlatformCache.list(); - - // 如果缓存没有,则从DB读取,然后保存到缓存里 - if(cacheList == null) { - List list = this.list(new LambdaQueryWrapper().in(SmsPlatformEntity::getStatus, Constant.ENABLE)); - - cacheList = SmsPlatformConvert.INSTANCE.convertList2(list); - smsPlatformCache.save(cacheList); - } - - return cacheList; - } - - @Override - public void save(SmsPlatformVO vo) { - SmsPlatformEntity entity = SmsPlatformConvert.INSTANCE.convert(vo); - - baseMapper.insert(entity); - - smsPlatformCache.delete(); - } - - @Override - public void update(SmsPlatformVO vo) { - SmsPlatformEntity entity = SmsPlatformConvert.INSTANCE.convert(vo); - - updateById(entity); - - smsPlatformCache.delete(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(List idList) { - removeByIds(idList); - - smsPlatformCache.delete(); - } - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java deleted file mode 100644 index a1095f9..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.maku.message.sms; - -import cn.hutool.core.map.MapUtil; -import com.aliyun.dysmsapi20170525.Client; -import com.aliyun.dysmsapi20170525.models.SendSmsRequest; -import com.aliyun.dysmsapi20170525.models.SendSmsResponse; -import com.aliyun.teaopenapi.models.Config; -import lombok.extern.slf4j.Slf4j; -import net.maku.framework.common.constant.Constant; -import net.maku.framework.common.exception.ServerException; -import net.maku.framework.common.utils.JsonUtils; -import net.maku.message.sms.config.SmsConfig; - -import java.util.Map; - -/** - * 阿里云短信 - * - * @author 阿沐 babamu@126.com - */ -@Slf4j -public class AliyunSmsStrategy implements SmsStrategy { - private final Client client; - private final SmsConfig smsConfig; - - public AliyunSmsStrategy(SmsConfig smsConfig) { - this.smsConfig = smsConfig; - - try { - Config config = new Config(); - config.setAccessKeyId(smsConfig.getAccessKey()); - config.setAccessKeySecret(smsConfig.getSecretKey()); - config.endpoint = "dysmsapi.aliyuncs.com"; - - this.client = new Client(config); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public void send(String mobile, Map params) { - SendSmsRequest request = new SendSmsRequest(); - request.setSignName(smsConfig.getSignName()); - request.setTemplateCode(smsConfig.getTemplateId()); - request.setPhoneNumbers(mobile); -// request.setTemplateParam("{\"code\":\"1234\"}"); - if (MapUtil.isNotEmpty(params)) { - request.setTemplateParam(JsonUtils.toJsonString(params)); - } - - try { - // 发送短信 - SendSmsResponse response = client.sendSms(request); - - // 发送失败 - if (!Constant.OK.equalsIgnoreCase(response.getBody().getCode())) { - throw new ServerException(response.getBody().getMessage()); - } - } catch (Exception e) { - throw new ServerException(e.getMessage()); - } - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java deleted file mode 100644 index f3fd4a2..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java +++ /dev/null @@ -1,194 +0,0 @@ -package net.maku.message.sms; - -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.CharsetUtil; -import lombok.Data; -import net.maku.framework.common.exception.ServerException; -import net.maku.framework.common.utils.JsonUtils; -import net.maku.message.sms.config.SmsConfig; -import org.apache.commons.lang3.StringUtils; -import org.springframework.http.HttpStatus; - -import javax.net.ssl.*; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLEncoder; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.cert.X509Certificate; -import java.text.SimpleDateFormat; -import java.util.*; - -/** - * 华为云短信 - * - * @author 阿沐 babamu@126.com - */ -public class HuaweiSmsStrategy implements SmsStrategy { - // 无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值 - private static final String WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\""; - // 无需修改,用于格式化鉴权头域,给"Authorization"参数赋值 - private static final String AUTH_HEADER_VALUE = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""; - private final SmsConfig smsConfig; - - public HuaweiSmsStrategy(SmsConfig smsConfig) { - this.smsConfig = smsConfig; - } - - @Override - public void send(String mobile, Map params) { - // 有参数则设置 - String templateParas = null; - if (MapUtil.isNotEmpty(params)) { - templateParas = JsonUtils.toJsonString(params.values().toArray(new String[0])); - } - - // 请求Body,不携带签名名称时,signature请填null - String body = buildRequestBody(smsConfig.getSenderId(), "+86" + mobile, smsConfig.getTemplateId(), templateParas, null, smsConfig.getSignName()); - if (StringUtils.isBlank(body)) { - throw new ServerException("body is null."); - } - - // 请求Headers中的X-WSSE参数值 - String wsseHeader = buildWsseHeader(smsConfig.getAccessKey(), smsConfig.getSecretKey()); - if (StringUtils.isBlank(wsseHeader)) { - throw new ServerException("wsse header is null."); - } - - try { - // 使用 https - trustAllHttpsCertificates(); - - // 接入地址 - String url = smsConfig.getUrl() + "/sms/batchSendSms/v1"; - URL realUrl = new URL(url); - HttpsURLConnection connection = (HttpsURLConnection) realUrl.openConnection(); - HostnameVerifier hv = (hostname, session) -> true; - connection.setHostnameVerifier(hv); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setUseCaches(true); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - connection.setRequestProperty("Authorization", AUTH_HEADER_VALUE); - connection.setRequestProperty("X-WSSE", wsseHeader); - connection.connect(); - - IoUtil.writeUtf8(connection.getOutputStream(), true, body); - - int status = connection.getResponseCode(); - if (status == HttpStatus.OK.value()) { - String response = IoUtil.read(connection.getInputStream(), CharsetUtil.CHARSET_UTF_8); - HuaweiSmsResult result = JsonUtils.parseObject(response, HuaweiSmsResult.class); - - // 短信是否发送成功 - assert result != null; - if (!"000000".equals(result.code)) { - throw new ServerException(result.description); - } - } else { //400 401 - throw new ServerException(IoUtil.read(connection.getErrorStream(), CharsetUtil.CHARSET_UTF_8)); - } - } catch (Exception e) { - throw new ServerException(e.getMessage()); - } - } - - /** - * 构造请求Body体 - * - * @param signature | 签名名称,使用国内短信通用模板时填写 - */ - static String buildRequestBody(String sender, String receiver, String templateId, String templateParas, - String statusCallBack, String signature) { - if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() - || templateId.isEmpty()) { - throw new ServerException("buildRequestBody(): sender, receiver or templateId is null."); - } - Map map = new HashMap<>(); - - map.put("from", sender); - map.put("to", receiver); - map.put("templateId", templateId); - if (null != templateParas && !templateParas.isEmpty()) { - map.put("templateParas", templateParas); - } - if (null != statusCallBack && !statusCallBack.isEmpty()) { - map.put("statusCallback", statusCallBack); - } - if (null != signature && !signature.isEmpty()) { - map.put("signature", signature); - } - - StringBuilder sb = new StringBuilder(); - String temp = ""; - - for (String s : map.keySet()) { - try { - temp = URLEncoder.encode(map.get(s), "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - sb.append(s).append("=").append(temp).append("&"); - } - - return sb.deleteCharAt(sb.length() - 1).toString(); - } - - /** - * 构造X-WSSE参数值 - */ - static String buildWsseHeader(String appKey, String appSecret) { - if (null == appKey || null == appSecret || appKey.isEmpty() || appSecret.isEmpty()) { - throw new ServerException("buildWsseHeader(): appKey or appSecret is null."); - } - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - String time = sdf.format(new Date()); - String nonce = UUID.randomUUID().toString().replace("-", ""); - - MessageDigest md; - byte[] passwordDigest = null; - - try { - md = MessageDigest.getInstance("SHA-256"); - md.update((nonce + time + appSecret).getBytes()); - passwordDigest = md.digest(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - - String passwordDigestBase64Str = Base64.getEncoder().encodeToString(passwordDigest); - - return String.format(WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time); - } - - static void trustAllHttpsCertificates() throws Exception { - TrustManager[] trustAllCerts = new TrustManager[]{ - new X509TrustManager() { - public void checkClientTrusted(X509Certificate[] chain, String authType) { - - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) { - - } - - public X509Certificate[] getAcceptedIssuers() { - return null; - } - } - }; - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, null); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - } - - @Data - static class HuaweiSmsResult { - // code为000000,表示成功 - private String code; - private String description; - private List result; - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java deleted file mode 100644 index 29891fd..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.maku.message.sms; - -import com.qiniu.http.Response; -import com.qiniu.sms.SmsManager; -import com.qiniu.util.Auth; -import net.maku.framework.common.exception.ServerException; -import net.maku.message.sms.config.SmsConfig; - -import java.util.Map; - -/** - * 七牛云短信 - * - * @author 阿沐 babamu@126.com - */ -public class QiniuSmsStrategy implements SmsStrategy { - private final SmsConfig smsConfig; - private final SmsManager smsManager; - - public QiniuSmsStrategy(SmsConfig smsConfig) { - this.smsConfig = smsConfig; - - Auth auth = Auth.create(smsConfig.getAccessKey(), smsConfig.getSecretKey()); - smsManager = new SmsManager(auth); - } - - @Override - public void send(String mobile, Map params) { - try { - Response response = smsManager.sendSingleMessage(smsConfig.getTemplateId(), mobile, params); - - // 是否发送成功 - if (!response.isOK()) { - throw new ServerException(response.error); - } - } catch (Exception e) { - throw new ServerException(e.getMessage()); - } - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsContext.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsContext.java deleted file mode 100644 index ccbb688..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsContext.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.maku.message.sms; - -import net.maku.framework.common.exception.ServerException; -import net.maku.message.enums.SmsPlatformEnum; -import net.maku.message.sms.config.SmsConfig; - -import java.util.Map; - -/** - * 短信 Context - * - * @author 阿沐 babamu@126.com - */ -public class SmsContext { - private final SmsStrategy smsStrategy; - - public SmsContext(SmsConfig config) { - if (config.getPlatform() == SmsPlatformEnum.ALIYUN.getValue()) { - this.smsStrategy = new AliyunSmsStrategy(config); - } else if (config.getPlatform() == SmsPlatformEnum.TENCENT.getValue()) { - this.smsStrategy = new TencentSmsStrategy(config); - } else if (config.getPlatform() == SmsPlatformEnum.QINIU.getValue()) { - this.smsStrategy = new QiniuSmsStrategy(config); - } else if (config.getPlatform() == SmsPlatformEnum.HUAWEI.getValue()) { - this.smsStrategy = new HuaweiSmsStrategy(config); - } else { - throw new ServerException("未知的短信平台"); - } - } - - public void send(String mobile, Map params) { - smsStrategy.send(mobile, params); - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsStrategy.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsStrategy.java deleted file mode 100644 index ef372b7..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/SmsStrategy.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.maku.message.sms; - -import java.util.Map; - -/** - * 短信 - * - * @author 阿沐 babamu@126.com - */ -public interface SmsStrategy { - - /** - * 发送短信 - * @param mobile 手机号 - * @param params 参数 - */ - void send(String mobile, Map params); -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java deleted file mode 100644 index 49582e4..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.maku.message.sms; - -import cn.hutool.core.map.MapUtil; -import com.tencentcloudapi.common.Credential; -import com.tencentcloudapi.common.profile.ClientProfile; -import com.tencentcloudapi.common.profile.HttpProfile; -import com.tencentcloudapi.sms.v20210111.SmsClient; -import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; -import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; -import com.tencentcloudapi.sms.v20210111.models.SendStatus; -import net.maku.framework.common.constant.Constant; -import net.maku.framework.common.exception.ServerException; -import net.maku.message.sms.config.SmsConfig; - -import java.util.Map; - -/** - * 腾讯云短信 - * - * @author 阿沐 babamu@126.com - */ -public class TencentSmsStrategy implements SmsStrategy { - private final SmsConfig smsConfig; - private SmsClient client; - - public TencentSmsStrategy(SmsConfig smsConfig) { - this.smsConfig = smsConfig; - - try { - HttpProfile httpProfile = new HttpProfile(); - httpProfile.setReqMethod("POST"); - httpProfile.setEndpoint("sms.tencentcloudapi.com"); - - ClientProfile clientProfile = new ClientProfile(); - clientProfile.setHttpProfile(httpProfile); - - Credential cred = new Credential(smsConfig.getAccessKey(), smsConfig.getSecretKey()); - this.client = new SmsClient(cred, "ap-guangzhou", clientProfile); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void send(String mobile, Map params) { - SendSmsRequest request = new SendSmsRequest(); - request.setSmsSdkAppId(smsConfig.getAppId()); - request.setSignName(smsConfig.getSignName()); - request.setTemplateId(smsConfig.getTemplateId()); - - // 有参数则设置 - if (MapUtil.isNotEmpty(params)) { - request.setTemplateParamSet(params.values().toArray(new String[0])); - } - - // 手机号 - String[] phoneNumberSet = {"+86" + mobile}; - request.setPhoneNumberSet(phoneNumberSet); - - // 国际、港澳台短信,需要添加SenderId,国内短信填空,默认未开通 - request.setSenderId(smsConfig.getSenderId()); - - try { - // 发送短信 - SendSmsResponse response = client.SendSms(request); - SendStatus sendStatus = response.getSendStatusSet()[0]; - - // 发送失败 - if (!Constant.OK.equalsIgnoreCase(sendStatus.getCode())) { - throw new ServerException(sendStatus.getMessage()); - } - } catch (Exception e) { - throw new ServerException(e.getMessage()); - } - } -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/config/SmsConfig.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/config/SmsConfig.java deleted file mode 100644 index 9020773..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/config/SmsConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -package net.maku.message.sms.config; - -import lombok.Data; - -/** - * 短信配置项 - * - * @author 阿沐 babamu@126.com - */ -@Data -public class SmsConfig { - /** - * 平台ID - */ - private Long id; - - /** - * 平台类型 - */ - private Integer platform; - - /** - * 短信签名 - */ - private String signName; - - /** - * 短信模板 - */ - private String templateId; - - /** - * 短信应用的ID,如:腾讯云等 - */ - private String appId; - - /** - * 腾讯云国际短信、华为云等需要 - */ - private String senderId; - - /** - * 接入地址,如:华为云 - */ - private String url; - - /** - * AccessKey - */ - private String accessKey; - - /** - * SecretKey - */ - private String secretKey; - -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/service/SmsService.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/service/SmsService.java deleted file mode 100644 index 6544e28..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/sms/service/SmsService.java +++ /dev/null @@ -1,107 +0,0 @@ -package net.maku.message.sms.service; - -import cn.hutool.core.map.MapUtil; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import net.maku.framework.common.constant.Constant; -import net.maku.framework.common.exception.ServerException; -import net.maku.framework.common.utils.ExceptionUtils; -import net.maku.framework.common.utils.JsonUtils; -import net.maku.message.entity.SmsLogEntity; -import net.maku.message.service.SmsLogService; -import net.maku.message.service.SmsPlatformService; -import net.maku.message.cache.SmsPlatformCache; -import net.maku.message.sms.SmsContext; -import net.maku.message.sms.config.SmsConfig; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; - -/** - * 短信服务 - * - * @author 阿沐 babamu@126.com - */ -@Slf4j -@Service -@AllArgsConstructor -public class SmsService { - private final SmsPlatformService smsPlatformService; - private final SmsLogService smsLogService; - private final SmsPlatformCache smsCacheService; - - /** - * 发送短信 - * @param mobile 手机号 - * @return 是否发送成功 - */ - public boolean send(String mobile){ - return this.send(mobile, MapUtil.newHashMap()); - } - - /** - * 发送短信 - * @param mobile 手机号 - * @param params 参数 - * @return 是否发送成功 - */ - public boolean send(String mobile, Map params){ - SmsConfig config = roundSmsConfig();; - - try { - // 发送短信 - new SmsContext(config).send(mobile, params); - - saveLog(config, mobile, params, null); - return true; - }catch (Exception e) { - log.error("短信发送失败,手机号:{}", mobile, e); - - saveLog(config, mobile, params, e); - - return false; - } - } - - /** - * 保存短信日志 - */ - public void saveLog(SmsConfig config, String mobile, Map params, Exception e) { - SmsLogEntity logEntity = new SmsLogEntity(); - logEntity.setPlatform(config.getPlatform()); - logEntity.setPlatformId(config.getId()); - logEntity.setMobile(mobile); - logEntity.setParams(JsonUtils.toJsonString(params)); - - if(e != null) { - String error = StringUtils.substring(ExceptionUtils.getExceptionMessage(e), 0, 2000); - logEntity.setStatus(Constant.FAIL); - logEntity.setError(error); - }else { - logEntity.setStatus(Constant.SUCCESS); - } - - smsLogService.save(logEntity); - } - - /** - * 通过轮询算法,获取短信平台的配置 - */ - private SmsConfig roundSmsConfig() { - List platformList = smsPlatformService.listByEnable(); - - // 是否有可用的短信平台 - int count = platformList.size(); - if(count == 0) { - throw new ServerException("没有可用的短信平台,请先添加"); - } - - // 采用轮询算法,发送短信 - long round = smsCacheService.getRoundValue(); - - return platformList.get((int)round % count); - } - -} diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsLogVO.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsLogVO.java deleted file mode 100644 index 09fc84a..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsLogVO.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.maku.message.vo; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import net.maku.framework.common.utils.DateUtils; - -import java.io.Serializable; -import java.util.Date; - -/** -* 短信日志 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@Schema(description = "短信日志") -public class SmsLogVO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "平台ID") - private Long platformId; - - @Schema(description = "平台类型") - private Integer platform; - - @Schema(description = "手机号") - private String mobile; - - @Schema(description = "状态 0:失败 1:成功") - private Integer status; - - @Schema(description = "参数") - private String params; - - @Schema(description = "异常信息") - private String error; - - @Schema(description = "创建时间") - @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) - private Date createTime; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java deleted file mode 100644 index 79a216f..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.maku.message.vo; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import net.maku.framework.common.utils.DateUtils; - -import java.io.Serializable; -import java.util.Date; - -/** - * 短信平台 - * - * @author 阿沐 babamu@126.com - */ -@Data -@Schema(description = "短信平台") -public class SmsPlatformVO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "平台类型 0:阿里云 1:腾讯云") - private Integer platform; - - @Schema(description = "短信签名") - private String signName; - - @Schema(description = "短信模板") - private String templateId; - - @Schema(description = "短信应用的ID,如:腾讯云等") - private String appId; - - @Schema(description = "腾讯云国际短信、华为云等需要") - private String senderId; - - @Schema(description = "接入地址,如:华为云") - private String url; - - @Schema(description = "AccessKey") - private String accessKey; - - @Schema(description = "SecretKey") - private String secretKey; - - @Schema(description = "状态 0:禁用 1:启用") - private Integer status; - - @Schema(description = "创建时间") - @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) - private Date createTime; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsSendVO.java b/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsSendVO.java deleted file mode 100644 index 15b51b5..0000000 --- a/maku-boot-module/maku-boot-message/src/main/java/net/maku/message/vo/SmsSendVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.maku.message.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.io.Serializable; - -/** -* 短信发送 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@Schema(description = "短信发送") -public class SmsSendVO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "手机号") - private String mobile; - - @Schema(description = "参数Key") - private String paramKey; - - @Schema(description = "参数Value") - private String paramValue; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsLogDao.xml b/maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsLogDao.xml deleted file mode 100644 index 4fbe9d4..0000000 --- a/maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsLogDao.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsPlatformDao.xml b/maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsPlatformDao.xml deleted file mode 100644 index c0beb27..0000000 --- a/maku-boot-module/maku-boot-message/src/main/resources/mapper/SmsPlatformDao.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/pom.xml b/maku-boot-module/maku-boot-quartz/pom.xml deleted file mode 100644 index e80dce7..0000000 --- a/maku-boot-module/maku-boot-quartz/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - net.maku - maku-boot-module - ${revision} - - 4.0.0 - maku-boot-quartz - jar - - - - net.maku - maku-framework - ${revision} - - - org.quartz-scheduler - quartz - - - - \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java deleted file mode 100644 index 7598e0b..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.maku.quartz.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; - -import javax.sql.DataSource; -import java.util.Properties; - -/** - * 定时任务配置 - * - * @author 阿沐 babamu@126.com - */ -@Configuration -public class ScheduleConfig { - - @Bean - public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) { - // quartz参数 - Properties prop = new Properties(); - prop.put("org.quartz.scheduler.instanceName", "MakuScheduler"); - prop.put("org.quartz.scheduler.instanceId", "AUTO"); - // 线程池配置 - prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); - prop.put("org.quartz.threadPool.threadCount", "20"); - prop.put("org.quartz.threadPool.threadPriority", "5"); - // jobStore配置 - prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore"); - // 集群配置 - prop.put("org.quartz.jobStore.isClustered", "true"); - prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); - prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); - prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); - - prop.put("org.quartz.jobStore.misfireThreshold", "12000"); - prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); - prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); - - SchedulerFactoryBean factory = new SchedulerFactoryBean(); - factory.setSchedulerName("MakuScheduler"); - factory.setDataSource(dataSource); - factory.setQuartzProperties(prop); - // 延时启动 - factory.setStartupDelay(10); - factory.setApplicationContextSchedulerContextKey("applicationContextKey"); - // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 - factory.setOverwriteExistingJobs(true); - - return factory; - } -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java deleted file mode 100644 index 48e2455..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java +++ /dev/null @@ -1,102 +0,0 @@ -package net.maku.quartz.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.utils.Result; -import net.maku.quartz.convert.ScheduleJobConvert; -import net.maku.quartz.entity.ScheduleJobEntity; -import net.maku.quartz.query.ScheduleJobQuery; -import net.maku.quartz.service.ScheduleJobService; -import net.maku.quartz.utils.CronUtils; -import net.maku.quartz.vo.ScheduleJobVO; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; - -/** -* 定时任务 -* -* @author 阿沐 babamu@126.com -*/ -@RestController -@RequestMapping("schedule") -@Tag(name="定时任务") -@AllArgsConstructor -public class ScheduleJobController { - private final ScheduleJobService scheduleJobService; - - @GetMapping("page") - @Operation(summary = "分页") - @PreAuthorize("hasAuthority('schedule:page')") - public Result> page(@Valid ScheduleJobQuery query){ - PageResult page = scheduleJobService.page(query); - - return Result.ok(page); - } - - @GetMapping("{id}") - @Operation(summary = "信息") - @PreAuthorize("hasAuthority('schedule:info')") - public Result get(@PathVariable("id") Long id){ - ScheduleJobEntity entity = scheduleJobService.getById(id); - - return Result.ok(ScheduleJobConvert.INSTANCE.convert(entity)); - } - - @PostMapping - @Operation(summary = "保存") - @PreAuthorize("hasAuthority('schedule:save')") - public Result save(@RequestBody ScheduleJobVO vo){ - if (!CronUtils.isValid(vo.getCronExpression())) { - return Result.error("操作失败,Cron表达式不正确"); - } - - scheduleJobService.save(vo); - - return Result.ok(); - } - - @PutMapping - @Operation(summary = "修改") - @PreAuthorize("hasAuthority('schedule:update')") - public Result update(@RequestBody @Valid ScheduleJobVO vo) { - if (!CronUtils.isValid(vo.getCronExpression())) { - return Result.error("操作失败,Cron表达式不正确"); - } - - scheduleJobService.update(vo); - - return Result.ok(); - } - - @DeleteMapping - @Operation(summary = "删除") - @PreAuthorize("hasAuthority('schedule:delete')") - public Result delete(@RequestBody List idList){ - scheduleJobService.delete(idList); - - return Result.ok(); - } - - @PutMapping("run") - @Operation(summary = "立即执行") - @PreAuthorize("hasAuthority('schedule:run')") - public Result run(@RequestBody ScheduleJobVO vo){ - scheduleJobService.run(vo); - - return Result.ok(); - } - - @PutMapping("change-status") - @Operation(summary = "修改状态") - @PreAuthorize("hasAuthority('schedule:update')") - public Result changeStatus(@RequestBody ScheduleJobVO vo){ - scheduleJobService.changeStatus(vo); - - return Result.ok(); - } -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java deleted file mode 100644 index 09ee49f..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java +++ /dev/null @@ -1,51 +0,0 @@ -package net.maku.quartz.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.utils.Result; -import net.maku.quartz.convert.ScheduleJobLogConvert; -import net.maku.quartz.entity.ScheduleJobLogEntity; -import net.maku.quartz.query.ScheduleJobLogQuery; -import net.maku.quartz.service.ScheduleJobLogService; -import net.maku.quartz.vo.ScheduleJobLogVO; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.validation.Valid; - -/** -* 定时任务日志 -* -* @author 阿沐 babamu@126.com -*/ -@RestController -@RequestMapping("schedule/log") -@Tag(name="定时任务日志") -@AllArgsConstructor -public class ScheduleJobLogController { - private final ScheduleJobLogService scheduleJobLogService; - - @GetMapping("page") - @Operation(summary = "分页") - @PreAuthorize("hasAuthority('schedule:log')") - public Result> page(@Valid ScheduleJobLogQuery query){ - PageResult page = scheduleJobLogService.page(query); - - return Result.ok(page); - } - - @GetMapping("{id}") - @Operation(summary = "信息") - @PreAuthorize("hasAuthority('schedule:log')") - public Result get(@PathVariable("id") Long id){ - ScheduleJobLogEntity entity = scheduleJobLogService.getById(id); - - return Result.ok(ScheduleJobLogConvert.INSTANCE.convert(entity)); - } - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java deleted file mode 100644 index 1ab7574..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.maku.quartz.convert; - -import net.maku.quartz.entity.ScheduleJobEntity; -import net.maku.quartz.vo.ScheduleJobVO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** -* 定时任务 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface ScheduleJobConvert { - ScheduleJobConvert INSTANCE = Mappers.getMapper(ScheduleJobConvert.class); - - ScheduleJobEntity convert(ScheduleJobVO vo); - - ScheduleJobVO convert(ScheduleJobEntity entity); - - List convertList(List list); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java deleted file mode 100644 index b3620f6..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.maku.quartz.convert; - -import net.maku.quartz.entity.ScheduleJobLogEntity; -import net.maku.quartz.vo.ScheduleJobLogVO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** -* 定时任务日志 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface ScheduleJobLogConvert { - ScheduleJobLogConvert INSTANCE = Mappers.getMapper(ScheduleJobLogConvert.class); - - ScheduleJobLogEntity convert(ScheduleJobLogVO vo); - - ScheduleJobLogVO convert(ScheduleJobLogEntity entity); - - List convertList(List list); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java deleted file mode 100644 index 2328b47..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.maku.quartz.dao; - -import net.maku.framework.common.dao.BaseDao; -import net.maku.quartz.entity.ScheduleJobEntity; -import org.apache.ibatis.annotations.Mapper; - -/** -* 定时任务 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface ScheduleJobDao extends BaseDao { - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java deleted file mode 100644 index a03e425..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.maku.quartz.dao; - -import net.maku.framework.common.dao.BaseDao; -import net.maku.quartz.entity.ScheduleJobLogEntity; -import org.apache.ibatis.annotations.Mapper; - -/** -* 定时任务日志 -* -* @author 阿沐 babamu@126.com -*/ -@Mapper -public interface ScheduleJobLogDao extends BaseDao { - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java deleted file mode 100644 index 5ece222..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java +++ /dev/null @@ -1,108 +0,0 @@ -package net.maku.quartz.entity; - -import com.baomidou.mybatisplus.annotation.*; -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - * 定时任务 - * - * @author 阿沐 babamu@126.com - */ -@Data -@TableName("schedule_job") -public class ScheduleJobEntity implements Serializable { - private static final long serialVersionUID = 1L; - - /** - * id - */ - @TableId - private Long id; - - /** - * 任务名称 - */ - private String jobName; - - /** - * 任务组名 - */ - private String jobGroup; - - /** - * bean名称 - */ - private String beanName; - - /** - * 执行方法 - */ - private String method; - - /** - * 方法参数 - */ - private String params; - - /** - * cron表达式 - */ - private String cronExpression; - - /** - * 状态 - */ - private Integer status; - - /** - * 是否并发 0:禁止 1:允许 - */ - private Integer concurrent; - - /** - * 备注 - */ - private String remark; - - /** - * 创建者 - */ - @TableField(fill = FieldFill.INSERT) - private Long creator; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - - /** - * 更新者 - */ - @TableField(fill = FieldFill.INSERT_UPDATE) - private Long updater; - - /** - * 更新时间 - */ - @TableField(fill = FieldFill.INSERT_UPDATE) - private Date updateTime; - - /** - * 版本号 - */ - @Version - @TableField(fill = FieldFill.INSERT) - private Integer version; - - /** - * 删除标记 - */ - @TableLogic - @TableField(fill = FieldFill.INSERT) - private Integer deleted; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java deleted file mode 100644 index e5f5734..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.maku.quartz.entity; - -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -import java.util.Date; - -/** - * 定时任务日志 - * - * @author 阿沐 babamu@126.com - */ -@Data -@TableName("schedule_job_log") -public class ScheduleJobLogEntity { - /** - * id - */ - @TableId - private Long id; - - /** - * 任务id - */ - private Long jobId; - - /** - * 任务名称 - */ - private String jobName; - - /** - * 任务组名 - */ - private String jobGroup; - - /** - * spring bean名称 - */ - private String beanName; - - /** - * 执行方法 - */ - private String method; - - /** - * 参数 - */ - private String params; - - /** - * 任务状态 - */ - private Integer status; - - /** - * 异常信息 - */ - private String error; - - /** - * 耗时(单位:毫秒) - */ - private Long times; - - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createTime; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java deleted file mode 100644 index 436f375..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.maku.quartz.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 定时任务并发枚举 - * - * @author 阿沐 babamu@126.com - */ -@Getter -@AllArgsConstructor -public enum ScheduleConcurrentEnum { - /** - * 禁止 - */ - NO(0), - /** - * 允许 - */ - YES(1); - - private final int value; -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java deleted file mode 100644 index 1d27f46..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.maku.quartz.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 定时任务状态枚举 - * - * @author 阿沐 babamu@126.com - */ -@Getter -@AllArgsConstructor -public enum ScheduleStatusEnum { - /** - * 暂停 - */ - PAUSE(0), - /** - * 正常 - */ - NORMAL(1); - - private final int value; -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java deleted file mode 100644 index 4fa134a..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.maku.quartz.query; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import net.maku.framework.common.query.Query; - -/** -* 定时任务日志查询 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "定时任务日志查询") -public class ScheduleJobLogQuery extends Query { - @Schema(description = "任务id") - private Long jobId; - - @Schema(description = "任务名称") - private String jobName; - - @Schema(description = "任务组名") - private String jobGroup; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java deleted file mode 100644 index 061b793..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.maku.quartz.query; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import net.maku.framework.common.query.Query; - -/** -* 定时任务查询 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "定时任务查询") -public class ScheduleJobQuery extends Query { - @Schema(description = "任务名称") - private String jobName; - - @Schema(description = "任务组名") - private String jobGroup; - - @Schema(description = "状态") - private Integer status; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java deleted file mode 100644 index 71532de..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.maku.quartz.service; - -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.BaseService; -import net.maku.quartz.entity.ScheduleJobLogEntity; -import net.maku.quartz.query.ScheduleJobLogQuery; -import net.maku.quartz.vo.ScheduleJobLogVO; - -/** - * 定时任务日志 - * - * @author 阿沐 babamu@126.com - */ -public interface ScheduleJobLogService extends BaseService { - - PageResult page(ScheduleJobLogQuery query); - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java deleted file mode 100644 index bf4ed9e..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.maku.quartz.service; - -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.BaseService; -import net.maku.quartz.entity.ScheduleJobEntity; -import net.maku.quartz.query.ScheduleJobQuery; -import net.maku.quartz.vo.ScheduleJobVO; - -import java.util.List; - -/** - * 定时任务 - * - * @author 阿沐 babamu@126.com - */ -public interface ScheduleJobService extends BaseService { - - PageResult page(ScheduleJobQuery query); - - void save(ScheduleJobVO vo); - - void update(ScheduleJobVO vo); - - void delete(List idList); - - void run(ScheduleJobVO vo); - - void changeStatus(ScheduleJobVO vo); -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java deleted file mode 100644 index ed5d816..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.maku.quartz.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.impl.BaseServiceImpl; -import net.maku.quartz.convert.ScheduleJobLogConvert; -import net.maku.quartz.dao.ScheduleJobLogDao; -import net.maku.quartz.entity.ScheduleJobLogEntity; -import net.maku.quartz.query.ScheduleJobLogQuery; -import net.maku.quartz.service.ScheduleJobLogService; -import net.maku.quartz.vo.ScheduleJobLogVO; -import org.springframework.stereotype.Service; - -/** - * 定时任务日志 - * - * @author 阿沐 babamu@126.com - */ -@Service -@AllArgsConstructor -public class ScheduleJobLogServiceImpl extends BaseServiceImpl implements ScheduleJobLogService { - - @Override - public PageResult page(ScheduleJobLogQuery query) { - IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); - - return new PageResult<>(ScheduleJobLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); - } - - private LambdaQueryWrapper getWrapper(ScheduleJobLogQuery query){ - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.like(StrUtil.isNotBlank(query.getJobName()), ScheduleJobLogEntity::getJobName, query.getJobName()); - wrapper.like(StrUtil.isNotBlank(query.getJobGroup()), ScheduleJobLogEntity::getJobGroup, query.getJobGroup()); - wrapper.eq(query.getJobId() != null, ScheduleJobLogEntity::getJobId, query.getJobId()); - wrapper.orderByDesc(ScheduleJobLogEntity::getId); - return wrapper; - } - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java deleted file mode 100644 index df39824..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java +++ /dev/null @@ -1,126 +0,0 @@ -package net.maku.quartz.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import lombok.AllArgsConstructor; -import net.maku.framework.common.page.PageResult; -import net.maku.framework.common.service.impl.BaseServiceImpl; -import net.maku.quartz.convert.ScheduleJobConvert; -import net.maku.quartz.dao.ScheduleJobDao; -import net.maku.quartz.entity.ScheduleJobEntity; -import net.maku.quartz.enums.ScheduleStatusEnum; -import net.maku.quartz.query.ScheduleJobQuery; -import net.maku.quartz.service.ScheduleJobService; -import net.maku.quartz.utils.ScheduleUtils; -import net.maku.quartz.vo.ScheduleJobVO; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.PostConstruct; -import java.util.List; - -/** - * 定时任务 - * - * @author 阿沐 babamu@126.com - */ -@Service -@AllArgsConstructor -public class ScheduleJobServiceImpl extends BaseServiceImpl implements ScheduleJobService { - private final Scheduler scheduler; - - /** - * 启动项目时,初始化定时器 - */ - @PostConstruct - public void init() throws SchedulerException { - scheduler.clear(); - List scheduleJobList = baseMapper.selectList(null); - for (ScheduleJobEntity scheduleJob : scheduleJobList) { - ScheduleUtils.createScheduleJob(scheduler, scheduleJob); - } - } - - @Override - public PageResult page(ScheduleJobQuery query) { - IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); - - return new PageResult<>(ScheduleJobConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); - } - - private LambdaQueryWrapper getWrapper(ScheduleJobQuery query){ - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.like(StrUtil.isNotBlank(query.getJobName()), ScheduleJobEntity::getJobName, query.getJobName()); - wrapper.like(StrUtil.isNotBlank(query.getJobGroup()), ScheduleJobEntity::getJobGroup, query.getJobGroup()); - wrapper.eq(query.getStatus() != null, ScheduleJobEntity::getStatus, query.getStatus()); - - return wrapper; - } - - @Override - public void save(ScheduleJobVO vo) { - ScheduleJobEntity entity = ScheduleJobConvert.INSTANCE.convert(vo); - - entity.setStatus(ScheduleStatusEnum.PAUSE.getValue()); - if(baseMapper.insert(entity) > 0) { - ScheduleUtils.createScheduleJob(scheduler, entity); - } - } - - @Override - public void update(ScheduleJobVO vo) { - ScheduleJobEntity entity = ScheduleJobConvert.INSTANCE.convert(vo); - - // 更新定时任务 - if(updateById(entity)) { - ScheduleJobEntity scheduleJob = getById(entity.getId()); - ScheduleUtils.updateSchedulerJob(scheduler, scheduleJob); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(List idList) { - for(Long id: idList){ - ScheduleJobEntity scheduleJob = getById(id); - - // 删除定时任务 - if (removeById(id)) { - ScheduleUtils.deleteScheduleJob(scheduler, scheduleJob); - } - } - } - - @Override - public void run(ScheduleJobVO vo) { - ScheduleJobEntity scheduleJob = getById(vo.getId()); - if(scheduleJob == null) { - return; - } - - ScheduleUtils.run(scheduler, scheduleJob); - } - - @Override - public void changeStatus(ScheduleJobVO vo) { - ScheduleJobEntity scheduleJob = getById(vo.getId()); - if(scheduleJob == null) { - return; - } - - // 更新数据 - scheduleJob.setStatus(vo.getStatus()); - updateById(scheduleJob); - - if(ScheduleStatusEnum.PAUSE.getValue() == vo.getStatus()) { - ScheduleUtils.pauseJob(scheduler, scheduleJob); - }else if(ScheduleStatusEnum.NORMAL.getValue() == vo.getStatus()) { - ScheduleUtils.resumeJob(scheduler, scheduleJob); - } - } - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/task/TestTask.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/task/TestTask.java deleted file mode 100644 index 27f9c0c..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/task/TestTask.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.maku.quartz.task; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -/** - * 测试定时任务 - * - * @author 阿沐 babamu@126.com - */ -@Slf4j -@Component -public class TestTask { - - public void run(String params) throws InterruptedException { - log.info("我是testTask.run(),参数:{},正在被执行。", params); - Thread.sleep(1000); - } -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java deleted file mode 100644 index 5d54566..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.maku.quartz.utils; - -import cn.hutool.extra.spring.SpringUtil; -import lombok.extern.slf4j.Slf4j; -import net.maku.framework.common.utils.ExceptionUtils; -import net.maku.quartz.entity.ScheduleJobEntity; -import net.maku.quartz.entity.ScheduleJobLogEntity; -import net.maku.quartz.enums.ScheduleStatusEnum; -import net.maku.quartz.service.ScheduleJobLogService; -import org.apache.commons.lang3.StringUtils; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.springframework.beans.BeanUtils; - -import java.lang.reflect.Method; -import java.util.Date; - -@Slf4j -public abstract class AbstractScheduleJob implements Job { - private static final ThreadLocal threadLocal = new ThreadLocal<>(); - - @Override - public void execute(JobExecutionContext context) { - ScheduleJobEntity scheduleJob = new ScheduleJobEntity(); - BeanUtils.copyProperties(context.getMergedJobDataMap().get(ScheduleUtils.JOB_PARAM_KEY), scheduleJob); - - try { - threadLocal.set(new Date()); - doExecute(scheduleJob); - saveLog(scheduleJob, null); - } catch (Exception e) { - log.error("任务执行失败,任务ID:{}", scheduleJob.getId(), e); - saveLog(scheduleJob, e); - } - } - - /** - * 执行spring bean方法 - */ - protected void doExecute(ScheduleJobEntity scheduleJob) throws Exception { - log.info("准备执行任务,任务ID:{}", scheduleJob.getId()); - - Object bean = SpringUtil.getBean(scheduleJob.getBeanName()); - Method method = bean.getClass().getDeclaredMethod(scheduleJob.getMethod(), String.class); - method.invoke(bean, scheduleJob.getParams()); - - log.info("任务执行完毕,任务ID:{}", scheduleJob.getId()); - } - - /** - * 保存 log - */ - protected void saveLog(ScheduleJobEntity scheduleJob, Exception e) { - Date startTime = threadLocal.get(); - threadLocal.remove(); - - // 执行总时长 - long times = System.currentTimeMillis() - startTime.getTime(); - - // 保存执行记录 - ScheduleJobLogEntity log = new ScheduleJobLogEntity(); - log.setJobId(scheduleJob.getId()); - log.setJobName(scheduleJob.getJobName()); - log.setJobGroup(scheduleJob.getJobGroup()); - log.setBeanName(scheduleJob.getBeanName()); - log.setMethod(scheduleJob.getMethod()); - log.setParams(scheduleJob.getParams()); - log.setTimes(times); - log.setCreateTime(new Date()); - - if (e != null) { - log.setStatus(ScheduleStatusEnum.PAUSE.getValue()); - String error = StringUtils.substring(ExceptionUtils.getExceptionMessage(e), 0, 2000); - log.setError(error); - } else { - log.setStatus(ScheduleStatusEnum.NORMAL.getValue()); - } - - // 保存日志 - SpringUtil.getBean(ScheduleJobLogService.class).save(log); - } - -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java deleted file mode 100644 index b5d5e13..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.maku.quartz.utils; - -import org.quartz.CronExpression; - -import java.text.ParseException; -import java.util.Date; - -/** - * cron 工具类 - * - * @author 阿沐 babamu@126.com - * - */ -public class CronUtils { - /** - * 验证Cron表达式是否有效 - */ - public static boolean isValid(String cronExpression) { - return CronExpression.isValidExpression(cronExpression); - } - - /** - * 根据给定的Cron表达式,返回下一个执行时间 - */ - public static Date getNextExecution(String cronExpression) { - try { - CronExpression cron = new CronExpression(cronExpression); - return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); - } catch (ParseException e) { - throw new IllegalArgumentException(e.getMessage()); - } - } -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java deleted file mode 100644 index 2bdb7fb..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.maku.quartz.utils; - -/** - * 允许并发(不会等待上一次任务执行完毕,只要时间到就会执行) - * - * @author 阿沐 babamu@126.com - * - */ -public class ScheduleConcurrentExecution extends AbstractScheduleJob { - -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java deleted file mode 100644 index 0d46460..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.maku.quartz.utils; - -import org.quartz.DisallowConcurrentExecution; - -/** - * 禁止并发 - * - * @author 阿沐 babamu@126.com - * - */ -@DisallowConcurrentExecution -public class ScheduleDisallowConcurrentExecution extends AbstractScheduleJob { - -} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java deleted file mode 100644 index 31dea46..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java +++ /dev/null @@ -1,161 +0,0 @@ -package net.maku.quartz.utils; - -import net.maku.framework.common.exception.ServerException; -import net.maku.quartz.entity.ScheduleJobEntity; -import net.maku.quartz.enums.ScheduleConcurrentEnum; -import net.maku.quartz.enums.ScheduleStatusEnum; -import org.quartz.*; - -/** - * 定时任务工具类 - * - * @author 阿沐 babamu@126.com - */ -public class ScheduleUtils { - private final static String JOB_NAME = "TASK_NAME_"; - /** - * 任务调度参数key - */ - public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY"; - - /** - * 获取quartz任务类 - */ - public static Class getJobClass(ScheduleJobEntity scheduleJob) { - if(scheduleJob.getConcurrent().equals(ScheduleConcurrentEnum.NO.getValue())){ - return ScheduleDisallowConcurrentExecution.class; - }else { - return ScheduleConcurrentExecution.class; - } - } - - /** - * 获取触发器key - */ - public static TriggerKey getTriggerKey(ScheduleJobEntity scheduleJob) { - return TriggerKey.triggerKey(JOB_NAME + scheduleJob.getId(), scheduleJob.getJobGroup()); - } - - /** - * 获取jobKey - */ - public static JobKey getJobKey(ScheduleJobEntity scheduleJob) { - return JobKey.jobKey(JOB_NAME + scheduleJob.getId(), scheduleJob.getJobGroup()); - } - - /** - * 创建定时任务 - */ - public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { - try { - // job key - JobKey jobKey = getJobKey(scheduleJob); - // 构建job信息 - JobDetail jobDetail = JobBuilder.newJob(getJobClass(scheduleJob)).withIdentity(jobKey).build(); - - // 表达式调度构建器 - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()) - .withMisfireHandlingInstructionDoNothing(); - - // 按新的cronExpression表达式构建一个新的trigger - CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob)) - .withSchedule(scheduleBuilder).build(); - - // 放入参数,运行时的方法可以获取 - jobDetail.getJobDataMap().put(JOB_PARAM_KEY, scheduleJob); - - scheduler.scheduleJob(jobDetail, trigger); - - // 判断是否存在 - if (scheduler.checkExists(jobKey)){ - // 防止创建时存在数据问题,先移除,然后再执行创建操作 - scheduler.deleteJob(jobKey); - } - - // 判断任务是否过期 - if (CronUtils.getNextExecution(scheduleJob.getCronExpression()) != null){ - // 执行调度任务 - scheduler.scheduleJob(jobDetail, trigger); - } - - // 暂停任务 - if (scheduleJob.getStatus().equals(ScheduleStatusEnum.PAUSE.getValue())){ - scheduler.pauseJob(jobKey); - } - } catch (SchedulerException e) { - throw new ServerException("创建定时任务失败", e); - } - } - - - - /** - * 立即执行任务 - */ - public static void run(Scheduler scheduler, ScheduleJobEntity scheduleJob) { - try { - // 参数 - JobDataMap dataMap = new JobDataMap(); - dataMap.put(JOB_PARAM_KEY, scheduleJob); - - JobKey jobKey = getJobKey(scheduleJob); - if (scheduler.checkExists(jobKey)) { - scheduler.triggerJob(jobKey, dataMap); - } - } catch (SchedulerException e) { - throw new ServerException("执行定时任务失败", e); - } - } - - /** - * 暂停任务 - */ - public static void pauseJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { - try { - scheduler.pauseJob(getJobKey(scheduleJob)); - } catch (SchedulerException e) { - throw new ServerException("暂停定时任务失败", e); - } - } - - /** - * 恢复任务 - */ - public static void resumeJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { - try { - scheduler.resumeJob(getJobKey(scheduleJob)); - } catch (SchedulerException e) { - throw new ServerException("恢复定时任务失败", e); - } - } - - /** - * 更新定时任务 - */ - public static void updateSchedulerJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { - // 判断是否存在 - JobKey jobKey = ScheduleUtils.getJobKey(scheduleJob); - - try { - // 防止创建时存在数据问题,先移除,然后再执行创建操作 - if (scheduler.checkExists(jobKey)) { - scheduler.deleteJob(jobKey); - } - }catch (SchedulerException e){ - throw new ServerException("更新定时任务失败", e); - } - - ScheduleUtils.createScheduleJob(scheduler, scheduleJob); - } - - /** - * 删除定时任务 - */ - public static void deleteScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { - try { - scheduler.deleteJob(getJobKey(scheduleJob)); - } catch (SchedulerException e) { - throw new ServerException("删除定时任务失败", e); - } - } -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java deleted file mode 100644 index 2701248..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.maku.quartz.vo; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import net.maku.framework.common.utils.DateUtils; - -import java.io.Serializable; -import java.util.Date; - -/** -* 定时任务日志 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@Schema(description = "定时任务日志") -public class ScheduleJobLogVO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "任务id") - private Long jobId; - - @Schema(description = "任务名称") - private String jobName; - - @Schema(description = "任务组名") - private String jobGroup; - - @Schema(description = "spring bean名称") - private String beanName; - - @Schema(description = "执行方法") - private String method; - - @Schema(description = "参数") - private String params; - - @Schema(description = "任务状态") - private Integer status; - - @Schema(description = "异常信息") - private String error; - - @Schema(description = "耗时(单位:毫秒)") - private Integer times; - - @Schema(description = "创建时间") - @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) - private Date createTime; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java deleted file mode 100644 index fea3674..0000000 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.maku.quartz.vo; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import net.maku.framework.common.utils.DateUtils; - -import java.io.Serializable; -import java.util.Date; - -/** -* 定时任务 -* -* @author 阿沐 babamu@126.com -*/ -@Data -@Schema(description = "定时任务") -public class ScheduleJobVO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "任务名称") - private String jobName; - - @Schema(description = "任务组名") - private String jobGroup; - - @Schema(description = "bean名称") - private String beanName; - - @Schema(description = "执行方法") - private String method; - - @Schema(description = "参数") - private String params; - - @Schema(description = "cron表达式") - private String cronExpression; - - @Schema(description = "状态 ") - private Integer status; - - @Schema(description = "是否并发") - private Integer concurrent; - - @Schema(description = "备注") - private String remark; - - @Schema(description = "创建时间") - @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) - private Date createTime; - -} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/pom.xml b/maku-boot-module/maku-module-message/pom.xml new file mode 100644 index 0000000..e66f9ba --- /dev/null +++ b/maku-boot-module/maku-module-message/pom.xml @@ -0,0 +1,42 @@ + + + net.maku + maku-boot-module + ${revision} + + 4.0.0 + maku-module-message + jar + + + + net.maku + maku-framework + ${revision} + + + net.maku + maku-boot-api + ${revision} + + + com.aliyun + dysmsapi20170525 + + + com.squareup.okhttp3 + okhttp + + + com.tencentcloudapi + tencentcloud-sdk-java + + + com.qiniu + qiniu-java-sdk + + + + + \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java new file mode 100644 index 0000000..1c7fce1 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java @@ -0,0 +1,55 @@ +package net.maku.message.api; + +import lombok.AllArgsConstructor; +import net.maku.api.module.message.SmsApi; +import net.maku.message.cache.SmsSendCache; +import net.maku.message.sms.service.SmsService; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * 短信服务Api + * + * @author 阿沐 babamu@126.com + */ +@Component +@AllArgsConstructor +public class SmsApiImpl implements SmsApi { + private final SmsService smsService; + private final SmsSendCache smsSendCache; + + @Override + public boolean send(String mobile, Map params) { + return smsService.send(mobile, params); + } + + @Override + public boolean sendCode(String mobile, String key, String value) { + // 短信参数 + Map params = new HashMap<>(); + params.put(key, value); + + // 发送短信 + boolean flag = smsService.send(mobile, params); + if (flag) { + smsSendCache.saveCode(mobile, value); + } + return flag; + } + + @Override + public boolean verifyCode(String mobile, String code) { + String value = smsSendCache.getCode(mobile); + if (value != null) { + // 删除短信验证码 + smsSendCache.deleteCode(mobile); + + // 效验 + return value.equalsIgnoreCase(code); + } + + return false; + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java new file mode 100644 index 0000000..fa810cf --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsPlatformCache.java @@ -0,0 +1,48 @@ +package net.maku.message.cache; + +import lombok.AllArgsConstructor; +import net.maku.framework.common.cache.RedisCache; +import net.maku.message.sms.config.SmsConfig; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 短信平台 Cache + * + * @author 阿沐 babamu@126.com + */ +@Service +@AllArgsConstructor +public class SmsPlatformCache { + private final RedisCache redisCache; + + /** + * 短信平台轮询KEY + */ + private final String SMS_ROUND_KEY = "message:sms:round"; + + /** + * 短信平台列表KEY + */ + private final String SMS_PLATFORM_KEY = "message:sms:platform"; + + /** + * 获取短信轮询值 + */ + public Long getRoundValue() { + return redisCache.increment(SMS_ROUND_KEY); + } + + public List list() { + return (List) redisCache.get(SMS_PLATFORM_KEY); + } + + public void save(List list) { + redisCache.set(SMS_PLATFORM_KEY, list); + } + + public void delete() { + redisCache.delete(SMS_PLATFORM_KEY); + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsSendCache.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsSendCache.java new file mode 100644 index 0000000..de13918 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/cache/SmsSendCache.java @@ -0,0 +1,43 @@ +package net.maku.message.cache; + +import lombok.AllArgsConstructor; +import net.maku.framework.common.cache.RedisCache; +import org.springframework.stereotype.Service; + +/** + * 短信发送 Cache + * + * @author 阿沐 babamu@126.com + */ +@Service +@AllArgsConstructor +public class SmsSendCache { + private final RedisCache redisCache; + + /** + * 获取发送手机短信验证码KEY + * + * @param mobile 手机号 + * @return KEY + */ + private String getCodeKey(String mobile) { + return "message:sms:code" + mobile; + } + + public void saveCode(String mobile, String code) { + String key = getCodeKey(mobile); + + // 保存到Redis,有效期10分钟 + redisCache.set(key, code, 10 * 60); + } + + public String getCode(String mobile) { + String key = getCodeKey(mobile); + return (String) redisCache.get(key); + } + + public void deleteCode(String mobile) { + String key = getCodeKey(mobile); + redisCache.delete(key); + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsLogController.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsLogController.java new file mode 100644 index 0000000..309a4e8 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsLogController.java @@ -0,0 +1,48 @@ +package net.maku.message.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.utils.Result; +import net.maku.message.convert.SmsLogConvert; +import net.maku.message.entity.SmsLogEntity; +import net.maku.message.query.SmsLogQuery; +import net.maku.message.service.SmsLogService; +import net.maku.message.vo.SmsLogVO; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** +* 短信日志 +* +* @author 阿沐 babamu@126.com +*/ +@RestController +@RequestMapping("message/sms/log") +@Tag(name="短信日志") +@AllArgsConstructor +public class SmsLogController { + private final SmsLogService smsLogService; + + @GetMapping("page") + @Operation(summary = "分页") + @PreAuthorize("hasAuthority('sms:log')") + public Result> page(@Valid SmsLogQuery query){ + PageResult page = smsLogService.page(query); + + return Result.ok(page); + } + + @GetMapping("{id}") + @Operation(summary = "信息") + @PreAuthorize("hasAuthority('sms:log')") + public Result get(@PathVariable("id") Long id){ + SmsLogEntity entity = smsLogService.getById(id); + + return Result.ok(SmsLogConvert.INSTANCE.convert(entity)); + } + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsPlatformController.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsPlatformController.java new file mode 100644 index 0000000..2a32079 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/controller/SmsPlatformController.java @@ -0,0 +1,113 @@ +package net.maku.message.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.utils.ExceptionUtils; +import net.maku.framework.common.utils.Result; +import net.maku.message.convert.SmsPlatformConvert; +import net.maku.message.entity.SmsPlatformEntity; +import net.maku.message.query.SmsPlatformQuery; +import net.maku.message.service.SmsPlatformService; +import net.maku.message.sms.SmsContext; +import net.maku.message.sms.config.SmsConfig; +import net.maku.message.sms.service.SmsService; +import net.maku.message.vo.SmsPlatformVO; +import net.maku.message.vo.SmsSendVO; +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 短信平台 + * + * @author 阿沐 babamu@126.com + */ +@RestController +@RequestMapping("message/sms/platform") +@Tag(name = "短信平台") +@AllArgsConstructor +public class SmsPlatformController { + private final SmsPlatformService smsPlatformService; + private final SmsService smsService; + + @GetMapping("page") + @Operation(summary = "分页") + @PreAuthorize("hasAuthority('sms:platform:page')") + public Result> page(@Valid SmsPlatformQuery query) { + PageResult page = smsPlatformService.page(query); + + return Result.ok(page); + } + + @GetMapping("{id}") + @Operation(summary = "信息") + @PreAuthorize("hasAuthority('sms:platform:info')") + public Result get(@PathVariable("id") Long id) { + SmsPlatformEntity entity = smsPlatformService.getById(id); + + return Result.ok(SmsPlatformConvert.INSTANCE.convert(entity)); + } + + @PostMapping + @Operation(summary = "保存") + @PreAuthorize("hasAuthority('sms:platform:save')") + public Result save(@RequestBody SmsPlatformVO vo) { + smsPlatformService.save(vo); + + return Result.ok(); + } + + @PostMapping("send") + @Operation(summary = "发送短信") + @PreAuthorize("hasAuthority('sms:platform:update')") + public Result send(@RequestBody SmsSendVO vo) { + SmsPlatformEntity entity = smsPlatformService.getById(vo.getId()); + SmsConfig config = SmsPlatformConvert.INSTANCE.convert2(entity); + + // 短信参数 + Map params = new LinkedHashMap<>(); + if (StringUtils.isNotBlank(vo.getParamValue())) { + params.put(vo.getParamKey(), vo.getParamValue()); + } + + try { + // 发送短信 + new SmsContext(config).send(vo.getMobile(), params); + + // 保存日志 + smsService.saveLog(config, vo.getMobile(), params, null); + + return Result.ok(); + } catch (Exception e) { + // 保存日志 + smsService.saveLog(config, vo.getMobile(), params, e); + + return Result.error(ExceptionUtils.getExceptionMessage(e)); + } + } + + @PutMapping + @Operation(summary = "修改") + @PreAuthorize("hasAuthority('sms:platform:update')") + public Result update(@RequestBody @Valid SmsPlatformVO vo) { + smsPlatformService.update(vo); + + return Result.ok(); + } + + @DeleteMapping + @Operation(summary = "删除") + @PreAuthorize("hasAuthority('sms:platform:delete')") + public Result delete(@RequestBody List idList) { + smsPlatformService.delete(idList); + + return Result.ok(); + } +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsLogConvert.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsLogConvert.java new file mode 100644 index 0000000..fb38ff7 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsLogConvert.java @@ -0,0 +1,23 @@ +package net.maku.message.convert; + +import net.maku.message.entity.SmsLogEntity; +import net.maku.message.vo.SmsLogVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** +* 短信日志 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface SmsLogConvert { + SmsLogConvert INSTANCE = Mappers.getMapper(SmsLogConvert.class); + + SmsLogVO convert(SmsLogEntity entity); + + List convertList(List list); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java new file mode 100644 index 0000000..1c8fd71 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/convert/SmsPlatformConvert.java @@ -0,0 +1,30 @@ +package net.maku.message.convert; + +import net.maku.message.entity.SmsPlatformEntity; +import net.maku.message.sms.config.SmsConfig; +import net.maku.message.vo.SmsPlatformVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** +* 短信平台 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface SmsPlatformConvert { + SmsPlatformConvert INSTANCE = Mappers.getMapper(SmsPlatformConvert.class); + + SmsPlatformEntity convert(SmsPlatformVO vo); + + SmsPlatformVO convert(SmsPlatformEntity entity); + + List convertList(List list); + + SmsConfig convert2(SmsPlatformEntity entity); + + List convertList2(List list); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsLogDao.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsLogDao.java new file mode 100644 index 0000000..01a9968 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsLogDao.java @@ -0,0 +1,15 @@ +package net.maku.message.dao; + +import net.maku.framework.common.dao.BaseDao; +import net.maku.message.entity.SmsLogEntity; +import org.apache.ibatis.annotations.Mapper; + +/** +* 短信日志 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface SmsLogDao extends BaseDao { + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java new file mode 100644 index 0000000..33c6643 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/dao/SmsPlatformDao.java @@ -0,0 +1,15 @@ +package net.maku.message.dao; + +import net.maku.framework.common.dao.BaseDao; +import net.maku.message.entity.SmsPlatformEntity; +import org.apache.ibatis.annotations.Mapper; + +/** +* 短信平台 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface SmsPlatformDao extends BaseDao { + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsLogEntity.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsLogEntity.java new file mode 100644 index 0000000..9bcd179 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsLogEntity.java @@ -0,0 +1,63 @@ +package net.maku.message.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 短信日志 + * + * @author 阿沐 babamu@126.com + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sms_log") +public class SmsLogEntity { + /** + * id + */ + @TableId + private Long id; + + /** + * 平台ID + */ + private Long platformId; + + /** + * 平台类型 + */ + private Integer platform; + + /** + * 手机号 + */ + private String mobile; + + /** + * 状态 0:失败 1:成功 + */ + private Integer status; + + /** + * 参数 + */ + private String params; + + /** + * 异常信息 + */ + private String error; + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Date createTime; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java new file mode 100644 index 0000000..d91a0c0 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/entity/SmsPlatformEntity.java @@ -0,0 +1,62 @@ +package net.maku.message.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.maku.framework.common.entity.BaseEntity; + +/** + * 短信平台 + * + * @author 阿沐 babamu@126.com + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sms_platform") +public class SmsPlatformEntity extends BaseEntity { + /** + * 平台类型 0:阿里云 1:腾讯云 2:七牛云 3:华为云 + */ + private Integer platform; + + /** + * 短信签名 + */ + private String signName; + + /** + * 短信模板 + */ + private String templateId; + + /** + * 短信应用的ID,如:腾讯云等 + */ + private String appId; + + /** + * 腾讯云国际短信、华为云等需要 + */ + private String senderId; + + /** + * 接入地址,如:华为云 + */ + private String url; + + /** + * AccessKey + */ + private String accessKey; + + /** + * SecretKey + */ + private String secretKey; + + /** + * 状态 0:禁用 1:启用 + */ + private Integer status; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java new file mode 100644 index 0000000..c58ddec --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/enums/SmsPlatformEnum.java @@ -0,0 +1,33 @@ +package net.maku.message.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 短信平台枚举 + * + * @author 阿沐 babamu@126.com + */ +@Getter +@AllArgsConstructor +public enum SmsPlatformEnum { + /** + * 阿里云 + */ + ALIYUN(0), + /** + * 腾讯云 + */ + TENCENT(1), + /** + * 七牛云 + */ + QINIU(2), + /** + * 华为云 + */ + HUAWEI(3); + + private final int value; + +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsLogQuery.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsLogQuery.java new file mode 100644 index 0000000..c39453a --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsLogQuery.java @@ -0,0 +1,23 @@ +package net.maku.message.query; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.maku.framework.common.query.Query; + +/** +* 短信日志查询 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@EqualsAndHashCode(callSuper = false) +@Schema(description = "短信日志查询") +public class SmsLogQuery extends Query { + @Schema(description = "平台ID") + private Long platformId; + + @Schema(description = "平台类型") + private Integer platform; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java new file mode 100644 index 0000000..c7e2d88 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/query/SmsPlatformQuery.java @@ -0,0 +1,23 @@ +package net.maku.message.query; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.maku.framework.common.query.Query; + +/** +* 短信平台查询 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@EqualsAndHashCode(callSuper = false) +@Schema(description = "短信平台查询") +public class SmsPlatformQuery extends Query { + @Schema(description = "平台类型 0:阿里云 1:腾讯云") + private Integer platform; + + @Schema(description = "短信签名") + private String signName; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsLogService.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsLogService.java new file mode 100644 index 0000000..9332abe --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsLogService.java @@ -0,0 +1,18 @@ +package net.maku.message.service; + +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.BaseService; +import net.maku.message.entity.SmsLogEntity; +import net.maku.message.query.SmsLogQuery; +import net.maku.message.vo.SmsLogVO; + +/** + * 短信日志 + * + * @author 阿沐 babamu@126.com + */ +public interface SmsLogService extends BaseService { + + PageResult page(SmsLogQuery query); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsPlatformService.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsPlatformService.java new file mode 100644 index 0000000..a1a64fa --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/SmsPlatformService.java @@ -0,0 +1,32 @@ +package net.maku.message.service; + +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.BaseService; +import net.maku.message.entity.SmsPlatformEntity; +import net.maku.message.query.SmsPlatformQuery; +import net.maku.message.sms.config.SmsConfig; +import net.maku.message.vo.SmsPlatformVO; + +import java.util.List; + +/** + * 短信平台 + * + * @author 阿沐 babamu@126.com + */ +public interface SmsPlatformService extends BaseService { + + PageResult page(SmsPlatformQuery query); + + /** + * 启用的短信平台列表 + */ + List listByEnable(); + + void save(SmsPlatformVO vo); + + void update(SmsPlatformVO vo); + + void delete(List idList); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java new file mode 100644 index 0000000..efae8d8 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsLogServiceImpl.java @@ -0,0 +1,41 @@ +package net.maku.message.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.impl.BaseServiceImpl; +import net.maku.message.convert.SmsLogConvert; +import net.maku.message.dao.SmsLogDao; +import net.maku.message.entity.SmsLogEntity; +import net.maku.message.query.SmsLogQuery; +import net.maku.message.service.SmsLogService; +import net.maku.message.vo.SmsLogVO; +import org.springframework.stereotype.Service; + +/** + * 短信日志 + * + * @author 阿沐 babamu@126.com + */ +@Service +@AllArgsConstructor +public class SmsLogServiceImpl extends BaseServiceImpl implements SmsLogService { + + @Override + public PageResult page(SmsLogQuery query) { + IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); + + return new PageResult<>(SmsLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); + } + + private LambdaQueryWrapper getWrapper(SmsLogQuery query){ + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(query.getPlatform() != null, SmsLogEntity::getPlatform, query.getPlatform()); + wrapper.like(query.getPlatformId() != null, SmsLogEntity::getPlatformId, query.getPlatformId()); + wrapper.orderByDesc(SmsLogEntity::getId); + return wrapper; + } + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java new file mode 100644 index 0000000..28c5c87 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/service/impl/SmsPlatformServiceImpl.java @@ -0,0 +1,90 @@ +package net.maku.message.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.AllArgsConstructor; +import net.maku.framework.common.constant.Constant; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.impl.BaseServiceImpl; +import net.maku.message.cache.SmsPlatformCache; +import net.maku.message.convert.SmsPlatformConvert; +import net.maku.message.dao.SmsPlatformDao; +import net.maku.message.entity.SmsPlatformEntity; +import net.maku.message.query.SmsPlatformQuery; +import net.maku.message.service.SmsPlatformService; +import net.maku.message.sms.config.SmsConfig; +import net.maku.message.vo.SmsPlatformVO; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 短信平台 + * + * @author 阿沐 babamu@126.com + */ +@Service +@AllArgsConstructor +public class SmsPlatformServiceImpl extends BaseServiceImpl implements SmsPlatformService { + private final SmsPlatformCache smsPlatformCache; + + @Override + public PageResult page(SmsPlatformQuery query) { + IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); + + return new PageResult<>(SmsPlatformConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); + } + + private LambdaQueryWrapper getWrapper(SmsPlatformQuery query){ + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(query.getPlatform() != null, SmsPlatformEntity::getPlatform, query.getPlatform()); + wrapper.like(StrUtil.isNotBlank(query.getSignName()), SmsPlatformEntity::getSignName, query.getSignName()); + return wrapper; + } + + @Override + public List listByEnable() { + // 从缓存读取 + List cacheList = smsPlatformCache.list(); + + // 如果缓存没有,则从DB读取,然后保存到缓存里 + if(cacheList == null) { + List list = this.list(new LambdaQueryWrapper().in(SmsPlatformEntity::getStatus, Constant.ENABLE)); + + cacheList = SmsPlatformConvert.INSTANCE.convertList2(list); + smsPlatformCache.save(cacheList); + } + + return cacheList; + } + + @Override + public void save(SmsPlatformVO vo) { + SmsPlatformEntity entity = SmsPlatformConvert.INSTANCE.convert(vo); + + baseMapper.insert(entity); + + smsPlatformCache.delete(); + } + + @Override + public void update(SmsPlatformVO vo) { + SmsPlatformEntity entity = SmsPlatformConvert.INSTANCE.convert(vo); + + updateById(entity); + + smsPlatformCache.delete(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(List idList) { + removeByIds(idList); + + smsPlatformCache.delete(); + } + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java new file mode 100644 index 0000000..a1095f9 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java @@ -0,0 +1,64 @@ +package net.maku.message.sms; + +import cn.hutool.core.map.MapUtil; +import com.aliyun.dysmsapi20170525.Client; +import com.aliyun.dysmsapi20170525.models.SendSmsRequest; +import com.aliyun.dysmsapi20170525.models.SendSmsResponse; +import com.aliyun.teaopenapi.models.Config; +import lombok.extern.slf4j.Slf4j; +import net.maku.framework.common.constant.Constant; +import net.maku.framework.common.exception.ServerException; +import net.maku.framework.common.utils.JsonUtils; +import net.maku.message.sms.config.SmsConfig; + +import java.util.Map; + +/** + * 阿里云短信 + * + * @author 阿沐 babamu@126.com + */ +@Slf4j +public class AliyunSmsStrategy implements SmsStrategy { + private final Client client; + private final SmsConfig smsConfig; + + public AliyunSmsStrategy(SmsConfig smsConfig) { + this.smsConfig = smsConfig; + + try { + Config config = new Config(); + config.setAccessKeyId(smsConfig.getAccessKey()); + config.setAccessKeySecret(smsConfig.getSecretKey()); + config.endpoint = "dysmsapi.aliyuncs.com"; + + this.client = new Client(config); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void send(String mobile, Map params) { + SendSmsRequest request = new SendSmsRequest(); + request.setSignName(smsConfig.getSignName()); + request.setTemplateCode(smsConfig.getTemplateId()); + request.setPhoneNumbers(mobile); +// request.setTemplateParam("{\"code\":\"1234\"}"); + if (MapUtil.isNotEmpty(params)) { + request.setTemplateParam(JsonUtils.toJsonString(params)); + } + + try { + // 发送短信 + SendSmsResponse response = client.sendSms(request); + + // 发送失败 + if (!Constant.OK.equalsIgnoreCase(response.getBody().getCode())) { + throw new ServerException(response.getBody().getMessage()); + } + } catch (Exception e) { + throw new ServerException(e.getMessage()); + } + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java new file mode 100644 index 0000000..f3fd4a2 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java @@ -0,0 +1,194 @@ +package net.maku.message.sms; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.CharsetUtil; +import lombok.Data; +import net.maku.framework.common.exception.ServerException; +import net.maku.framework.common.utils.JsonUtils; +import net.maku.message.sms.config.SmsConfig; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpStatus; + +import javax.net.ssl.*; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLEncoder; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * 华为云短信 + * + * @author 阿沐 babamu@126.com + */ +public class HuaweiSmsStrategy implements SmsStrategy { + // 无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值 + private static final String WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\""; + // 无需修改,用于格式化鉴权头域,给"Authorization"参数赋值 + private static final String AUTH_HEADER_VALUE = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""; + private final SmsConfig smsConfig; + + public HuaweiSmsStrategy(SmsConfig smsConfig) { + this.smsConfig = smsConfig; + } + + @Override + public void send(String mobile, Map params) { + // 有参数则设置 + String templateParas = null; + if (MapUtil.isNotEmpty(params)) { + templateParas = JsonUtils.toJsonString(params.values().toArray(new String[0])); + } + + // 请求Body,不携带签名名称时,signature请填null + String body = buildRequestBody(smsConfig.getSenderId(), "+86" + mobile, smsConfig.getTemplateId(), templateParas, null, smsConfig.getSignName()); + if (StringUtils.isBlank(body)) { + throw new ServerException("body is null."); + } + + // 请求Headers中的X-WSSE参数值 + String wsseHeader = buildWsseHeader(smsConfig.getAccessKey(), smsConfig.getSecretKey()); + if (StringUtils.isBlank(wsseHeader)) { + throw new ServerException("wsse header is null."); + } + + try { + // 使用 https + trustAllHttpsCertificates(); + + // 接入地址 + String url = smsConfig.getUrl() + "/sms/batchSendSms/v1"; + URL realUrl = new URL(url); + HttpsURLConnection connection = (HttpsURLConnection) realUrl.openConnection(); + HostnameVerifier hv = (hostname, session) -> true; + connection.setHostnameVerifier(hv); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(true); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("Authorization", AUTH_HEADER_VALUE); + connection.setRequestProperty("X-WSSE", wsseHeader); + connection.connect(); + + IoUtil.writeUtf8(connection.getOutputStream(), true, body); + + int status = connection.getResponseCode(); + if (status == HttpStatus.OK.value()) { + String response = IoUtil.read(connection.getInputStream(), CharsetUtil.CHARSET_UTF_8); + HuaweiSmsResult result = JsonUtils.parseObject(response, HuaweiSmsResult.class); + + // 短信是否发送成功 + assert result != null; + if (!"000000".equals(result.code)) { + throw new ServerException(result.description); + } + } else { //400 401 + throw new ServerException(IoUtil.read(connection.getErrorStream(), CharsetUtil.CHARSET_UTF_8)); + } + } catch (Exception e) { + throw new ServerException(e.getMessage()); + } + } + + /** + * 构造请求Body体 + * + * @param signature | 签名名称,使用国内短信通用模板时填写 + */ + static String buildRequestBody(String sender, String receiver, String templateId, String templateParas, + String statusCallBack, String signature) { + if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() + || templateId.isEmpty()) { + throw new ServerException("buildRequestBody(): sender, receiver or templateId is null."); + } + Map map = new HashMap<>(); + + map.put("from", sender); + map.put("to", receiver); + map.put("templateId", templateId); + if (null != templateParas && !templateParas.isEmpty()) { + map.put("templateParas", templateParas); + } + if (null != statusCallBack && !statusCallBack.isEmpty()) { + map.put("statusCallback", statusCallBack); + } + if (null != signature && !signature.isEmpty()) { + map.put("signature", signature); + } + + StringBuilder sb = new StringBuilder(); + String temp = ""; + + for (String s : map.keySet()) { + try { + temp = URLEncoder.encode(map.get(s), "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + sb.append(s).append("=").append(temp).append("&"); + } + + return sb.deleteCharAt(sb.length() - 1).toString(); + } + + /** + * 构造X-WSSE参数值 + */ + static String buildWsseHeader(String appKey, String appSecret) { + if (null == appKey || null == appSecret || appKey.isEmpty() || appSecret.isEmpty()) { + throw new ServerException("buildWsseHeader(): appKey or appSecret is null."); + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + String time = sdf.format(new Date()); + String nonce = UUID.randomUUID().toString().replace("-", ""); + + MessageDigest md; + byte[] passwordDigest = null; + + try { + md = MessageDigest.getInstance("SHA-256"); + md.update((nonce + time + appSecret).getBytes()); + passwordDigest = md.digest(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + + String passwordDigestBase64Str = Base64.getEncoder().encodeToString(passwordDigest); + + return String.format(WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time); + } + + static void trustAllHttpsCertificates() throws Exception { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public void checkClientTrusted(X509Certificate[] chain, String authType) { + + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) { + + } + + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } + }; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + + @Data + static class HuaweiSmsResult { + // code为000000,表示成功 + private String code; + private String description; + private List result; + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java new file mode 100644 index 0000000..29891fd --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java @@ -0,0 +1,40 @@ +package net.maku.message.sms; + +import com.qiniu.http.Response; +import com.qiniu.sms.SmsManager; +import com.qiniu.util.Auth; +import net.maku.framework.common.exception.ServerException; +import net.maku.message.sms.config.SmsConfig; + +import java.util.Map; + +/** + * 七牛云短信 + * + * @author 阿沐 babamu@126.com + */ +public class QiniuSmsStrategy implements SmsStrategy { + private final SmsConfig smsConfig; + private final SmsManager smsManager; + + public QiniuSmsStrategy(SmsConfig smsConfig) { + this.smsConfig = smsConfig; + + Auth auth = Auth.create(smsConfig.getAccessKey(), smsConfig.getSecretKey()); + smsManager = new SmsManager(auth); + } + + @Override + public void send(String mobile, Map params) { + try { + Response response = smsManager.sendSingleMessage(smsConfig.getTemplateId(), mobile, params); + + // 是否发送成功 + if (!response.isOK()) { + throw new ServerException(response.error); + } + } catch (Exception e) { + throw new ServerException(e.getMessage()); + } + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsContext.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsContext.java new file mode 100644 index 0000000..ccbb688 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsContext.java @@ -0,0 +1,34 @@ +package net.maku.message.sms; + +import net.maku.framework.common.exception.ServerException; +import net.maku.message.enums.SmsPlatformEnum; +import net.maku.message.sms.config.SmsConfig; + +import java.util.Map; + +/** + * 短信 Context + * + * @author 阿沐 babamu@126.com + */ +public class SmsContext { + private final SmsStrategy smsStrategy; + + public SmsContext(SmsConfig config) { + if (config.getPlatform() == SmsPlatformEnum.ALIYUN.getValue()) { + this.smsStrategy = new AliyunSmsStrategy(config); + } else if (config.getPlatform() == SmsPlatformEnum.TENCENT.getValue()) { + this.smsStrategy = new TencentSmsStrategy(config); + } else if (config.getPlatform() == SmsPlatformEnum.QINIU.getValue()) { + this.smsStrategy = new QiniuSmsStrategy(config); + } else if (config.getPlatform() == SmsPlatformEnum.HUAWEI.getValue()) { + this.smsStrategy = new HuaweiSmsStrategy(config); + } else { + throw new ServerException("未知的短信平台"); + } + } + + public void send(String mobile, Map params) { + smsStrategy.send(mobile, params); + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsStrategy.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsStrategy.java new file mode 100644 index 0000000..ef372b7 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/SmsStrategy.java @@ -0,0 +1,18 @@ +package net.maku.message.sms; + +import java.util.Map; + +/** + * 短信 + * + * @author 阿沐 babamu@126.com + */ +public interface SmsStrategy { + + /** + * 发送短信 + * @param mobile 手机号 + * @param params 参数 + */ + void send(String mobile, Map params); +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java new file mode 100644 index 0000000..49582e4 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java @@ -0,0 +1,76 @@ +package net.maku.message.sms; + +import cn.hutool.core.map.MapUtil; +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.profile.ClientProfile; +import com.tencentcloudapi.common.profile.HttpProfile; +import com.tencentcloudapi.sms.v20210111.SmsClient; +import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; +import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; +import com.tencentcloudapi.sms.v20210111.models.SendStatus; +import net.maku.framework.common.constant.Constant; +import net.maku.framework.common.exception.ServerException; +import net.maku.message.sms.config.SmsConfig; + +import java.util.Map; + +/** + * 腾讯云短信 + * + * @author 阿沐 babamu@126.com + */ +public class TencentSmsStrategy implements SmsStrategy { + private final SmsConfig smsConfig; + private SmsClient client; + + public TencentSmsStrategy(SmsConfig smsConfig) { + this.smsConfig = smsConfig; + + try { + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setReqMethod("POST"); + httpProfile.setEndpoint("sms.tencentcloudapi.com"); + + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + + Credential cred = new Credential(smsConfig.getAccessKey(), smsConfig.getSecretKey()); + this.client = new SmsClient(cred, "ap-guangzhou", clientProfile); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void send(String mobile, Map params) { + SendSmsRequest request = new SendSmsRequest(); + request.setSmsSdkAppId(smsConfig.getAppId()); + request.setSignName(smsConfig.getSignName()); + request.setTemplateId(smsConfig.getTemplateId()); + + // 有参数则设置 + if (MapUtil.isNotEmpty(params)) { + request.setTemplateParamSet(params.values().toArray(new String[0])); + } + + // 手机号 + String[] phoneNumberSet = {"+86" + mobile}; + request.setPhoneNumberSet(phoneNumberSet); + + // 国际、港澳台短信,需要添加SenderId,国内短信填空,默认未开通 + request.setSenderId(smsConfig.getSenderId()); + + try { + // 发送短信 + SendSmsResponse response = client.SendSms(request); + SendStatus sendStatus = response.getSendStatusSet()[0]; + + // 发送失败 + if (!Constant.OK.equalsIgnoreCase(sendStatus.getCode())) { + throw new ServerException(sendStatus.getMessage()); + } + } catch (Exception e) { + throw new ServerException(e.getMessage()); + } + } +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/config/SmsConfig.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/config/SmsConfig.java new file mode 100644 index 0000000..9020773 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/config/SmsConfig.java @@ -0,0 +1,57 @@ +package net.maku.message.sms.config; + +import lombok.Data; + +/** + * 短信配置项 + * + * @author 阿沐 babamu@126.com + */ +@Data +public class SmsConfig { + /** + * 平台ID + */ + private Long id; + + /** + * 平台类型 + */ + private Integer platform; + + /** + * 短信签名 + */ + private String signName; + + /** + * 短信模板 + */ + private String templateId; + + /** + * 短信应用的ID,如:腾讯云等 + */ + private String appId; + + /** + * 腾讯云国际短信、华为云等需要 + */ + private String senderId; + + /** + * 接入地址,如:华为云 + */ + private String url; + + /** + * AccessKey + */ + private String accessKey; + + /** + * SecretKey + */ + private String secretKey; + +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/service/SmsService.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/service/SmsService.java new file mode 100644 index 0000000..6544e28 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/sms/service/SmsService.java @@ -0,0 +1,107 @@ +package net.maku.message.sms.service; + +import cn.hutool.core.map.MapUtil; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.maku.framework.common.constant.Constant; +import net.maku.framework.common.exception.ServerException; +import net.maku.framework.common.utils.ExceptionUtils; +import net.maku.framework.common.utils.JsonUtils; +import net.maku.message.entity.SmsLogEntity; +import net.maku.message.service.SmsLogService; +import net.maku.message.service.SmsPlatformService; +import net.maku.message.cache.SmsPlatformCache; +import net.maku.message.sms.SmsContext; +import net.maku.message.sms.config.SmsConfig; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * 短信服务 + * + * @author 阿沐 babamu@126.com + */ +@Slf4j +@Service +@AllArgsConstructor +public class SmsService { + private final SmsPlatformService smsPlatformService; + private final SmsLogService smsLogService; + private final SmsPlatformCache smsCacheService; + + /** + * 发送短信 + * @param mobile 手机号 + * @return 是否发送成功 + */ + public boolean send(String mobile){ + return this.send(mobile, MapUtil.newHashMap()); + } + + /** + * 发送短信 + * @param mobile 手机号 + * @param params 参数 + * @return 是否发送成功 + */ + public boolean send(String mobile, Map params){ + SmsConfig config = roundSmsConfig();; + + try { + // 发送短信 + new SmsContext(config).send(mobile, params); + + saveLog(config, mobile, params, null); + return true; + }catch (Exception e) { + log.error("短信发送失败,手机号:{}", mobile, e); + + saveLog(config, mobile, params, e); + + return false; + } + } + + /** + * 保存短信日志 + */ + public void saveLog(SmsConfig config, String mobile, Map params, Exception e) { + SmsLogEntity logEntity = new SmsLogEntity(); + logEntity.setPlatform(config.getPlatform()); + logEntity.setPlatformId(config.getId()); + logEntity.setMobile(mobile); + logEntity.setParams(JsonUtils.toJsonString(params)); + + if(e != null) { + String error = StringUtils.substring(ExceptionUtils.getExceptionMessage(e), 0, 2000); + logEntity.setStatus(Constant.FAIL); + logEntity.setError(error); + }else { + logEntity.setStatus(Constant.SUCCESS); + } + + smsLogService.save(logEntity); + } + + /** + * 通过轮询算法,获取短信平台的配置 + */ + private SmsConfig roundSmsConfig() { + List platformList = smsPlatformService.listByEnable(); + + // 是否有可用的短信平台 + int count = platformList.size(); + if(count == 0) { + throw new ServerException("没有可用的短信平台,请先添加"); + } + + // 采用轮询算法,发送短信 + long round = smsCacheService.getRoundValue(); + + return platformList.get((int)round % count); + } + +} diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsLogVO.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsLogVO.java new file mode 100644 index 0000000..09fc84a --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsLogVO.java @@ -0,0 +1,46 @@ +package net.maku.message.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import net.maku.framework.common.utils.DateUtils; + +import java.io.Serializable; +import java.util.Date; + +/** +* 短信日志 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@Schema(description = "短信日志") +public class SmsLogVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "平台ID") + private Long platformId; + + @Schema(description = "平台类型") + private Integer platform; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "状态 0:失败 1:成功") + private Integer status; + + @Schema(description = "参数") + private String params; + + @Schema(description = "异常信息") + private String error; + + @Schema(description = "创建时间") + @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) + private Date createTime; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java new file mode 100644 index 0000000..79a216f --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsPlatformVO.java @@ -0,0 +1,55 @@ +package net.maku.message.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import net.maku.framework.common.utils.DateUtils; + +import java.io.Serializable; +import java.util.Date; + +/** + * 短信平台 + * + * @author 阿沐 babamu@126.com + */ +@Data +@Schema(description = "短信平台") +public class SmsPlatformVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "平台类型 0:阿里云 1:腾讯云") + private Integer platform; + + @Schema(description = "短信签名") + private String signName; + + @Schema(description = "短信模板") + private String templateId; + + @Schema(description = "短信应用的ID,如:腾讯云等") + private String appId; + + @Schema(description = "腾讯云国际短信、华为云等需要") + private String senderId; + + @Schema(description = "接入地址,如:华为云") + private String url; + + @Schema(description = "AccessKey") + private String accessKey; + + @Schema(description = "SecretKey") + private String secretKey; + + @Schema(description = "状态 0:禁用 1:启用") + private Integer status; + + @Schema(description = "创建时间") + @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) + private Date createTime; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsSendVO.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsSendVO.java new file mode 100644 index 0000000..15b51b5 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/vo/SmsSendVO.java @@ -0,0 +1,30 @@ +package net.maku.message.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** +* 短信发送 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@Schema(description = "短信发送") +public class SmsSendVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "参数Key") + private String paramKey; + + @Schema(description = "参数Value") + private String paramValue; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/resources/mapper/SmsLogDao.xml b/maku-boot-module/maku-module-message/src/main/resources/mapper/SmsLogDao.xml new file mode 100644 index 0000000..4fbe9d4 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/resources/mapper/SmsLogDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/maku-boot-module/maku-module-message/src/main/resources/mapper/SmsPlatformDao.xml b/maku-boot-module/maku-module-message/src/main/resources/mapper/SmsPlatformDao.xml new file mode 100644 index 0000000..c0beb27 --- /dev/null +++ b/maku-boot-module/maku-module-message/src/main/resources/mapper/SmsPlatformDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/pom.xml b/maku-boot-module/maku-module-quartz/pom.xml new file mode 100644 index 0000000..7c94033 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/pom.xml @@ -0,0 +1,23 @@ + + + net.maku + maku-boot-module + ${revision} + + 4.0.0 + maku-module-quartz + jar + + + + net.maku + maku-framework + ${revision} + + + org.quartz-scheduler + quartz + + + + \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java new file mode 100644 index 0000000..7598e0b --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java @@ -0,0 +1,52 @@ +package net.maku.quartz.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; + +import javax.sql.DataSource; +import java.util.Properties; + +/** + * 定时任务配置 + * + * @author 阿沐 babamu@126.com + */ +@Configuration +public class ScheduleConfig { + + @Bean + public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) { + // quartz参数 + Properties prop = new Properties(); + prop.put("org.quartz.scheduler.instanceName", "MakuScheduler"); + prop.put("org.quartz.scheduler.instanceId", "AUTO"); + // 线程池配置 + prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); + prop.put("org.quartz.threadPool.threadCount", "20"); + prop.put("org.quartz.threadPool.threadPriority", "5"); + // jobStore配置 + prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore"); + // 集群配置 + prop.put("org.quartz.jobStore.isClustered", "true"); + prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); + prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); + prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); + + prop.put("org.quartz.jobStore.misfireThreshold", "12000"); + prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); + prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); + + SchedulerFactoryBean factory = new SchedulerFactoryBean(); + factory.setSchedulerName("MakuScheduler"); + factory.setDataSource(dataSource); + factory.setQuartzProperties(prop); + // 延时启动 + factory.setStartupDelay(10); + factory.setApplicationContextSchedulerContextKey("applicationContextKey"); + // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 + factory.setOverwriteExistingJobs(true); + + return factory; + } +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java new file mode 100644 index 0000000..48e2455 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobController.java @@ -0,0 +1,102 @@ +package net.maku.quartz.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.utils.Result; +import net.maku.quartz.convert.ScheduleJobConvert; +import net.maku.quartz.entity.ScheduleJobEntity; +import net.maku.quartz.query.ScheduleJobQuery; +import net.maku.quartz.service.ScheduleJobService; +import net.maku.quartz.utils.CronUtils; +import net.maku.quartz.vo.ScheduleJobVO; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +/** +* 定时任务 +* +* @author 阿沐 babamu@126.com +*/ +@RestController +@RequestMapping("schedule") +@Tag(name="定时任务") +@AllArgsConstructor +public class ScheduleJobController { + private final ScheduleJobService scheduleJobService; + + @GetMapping("page") + @Operation(summary = "分页") + @PreAuthorize("hasAuthority('schedule:page')") + public Result> page(@Valid ScheduleJobQuery query){ + PageResult page = scheduleJobService.page(query); + + return Result.ok(page); + } + + @GetMapping("{id}") + @Operation(summary = "信息") + @PreAuthorize("hasAuthority('schedule:info')") + public Result get(@PathVariable("id") Long id){ + ScheduleJobEntity entity = scheduleJobService.getById(id); + + return Result.ok(ScheduleJobConvert.INSTANCE.convert(entity)); + } + + @PostMapping + @Operation(summary = "保存") + @PreAuthorize("hasAuthority('schedule:save')") + public Result save(@RequestBody ScheduleJobVO vo){ + if (!CronUtils.isValid(vo.getCronExpression())) { + return Result.error("操作失败,Cron表达式不正确"); + } + + scheduleJobService.save(vo); + + return Result.ok(); + } + + @PutMapping + @Operation(summary = "修改") + @PreAuthorize("hasAuthority('schedule:update')") + public Result update(@RequestBody @Valid ScheduleJobVO vo) { + if (!CronUtils.isValid(vo.getCronExpression())) { + return Result.error("操作失败,Cron表达式不正确"); + } + + scheduleJobService.update(vo); + + return Result.ok(); + } + + @DeleteMapping + @Operation(summary = "删除") + @PreAuthorize("hasAuthority('schedule:delete')") + public Result delete(@RequestBody List idList){ + scheduleJobService.delete(idList); + + return Result.ok(); + } + + @PutMapping("run") + @Operation(summary = "立即执行") + @PreAuthorize("hasAuthority('schedule:run')") + public Result run(@RequestBody ScheduleJobVO vo){ + scheduleJobService.run(vo); + + return Result.ok(); + } + + @PutMapping("change-status") + @Operation(summary = "修改状态") + @PreAuthorize("hasAuthority('schedule:update')") + public Result changeStatus(@RequestBody ScheduleJobVO vo){ + scheduleJobService.changeStatus(vo); + + return Result.ok(); + } +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java new file mode 100644 index 0000000..09ee49f --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/controller/ScheduleJobLogController.java @@ -0,0 +1,51 @@ +package net.maku.quartz.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.utils.Result; +import net.maku.quartz.convert.ScheduleJobLogConvert; +import net.maku.quartz.entity.ScheduleJobLogEntity; +import net.maku.quartz.query.ScheduleJobLogQuery; +import net.maku.quartz.service.ScheduleJobLogService; +import net.maku.quartz.vo.ScheduleJobLogVO; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; + +/** +* 定时任务日志 +* +* @author 阿沐 babamu@126.com +*/ +@RestController +@RequestMapping("schedule/log") +@Tag(name="定时任务日志") +@AllArgsConstructor +public class ScheduleJobLogController { + private final ScheduleJobLogService scheduleJobLogService; + + @GetMapping("page") + @Operation(summary = "分页") + @PreAuthorize("hasAuthority('schedule:log')") + public Result> page(@Valid ScheduleJobLogQuery query){ + PageResult page = scheduleJobLogService.page(query); + + return Result.ok(page); + } + + @GetMapping("{id}") + @Operation(summary = "信息") + @PreAuthorize("hasAuthority('schedule:log')") + public Result get(@PathVariable("id") Long id){ + ScheduleJobLogEntity entity = scheduleJobLogService.getById(id); + + return Result.ok(ScheduleJobLogConvert.INSTANCE.convert(entity)); + } + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java new file mode 100644 index 0000000..1ab7574 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobConvert.java @@ -0,0 +1,25 @@ +package net.maku.quartz.convert; + +import net.maku.quartz.entity.ScheduleJobEntity; +import net.maku.quartz.vo.ScheduleJobVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** +* 定时任务 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface ScheduleJobConvert { + ScheduleJobConvert INSTANCE = Mappers.getMapper(ScheduleJobConvert.class); + + ScheduleJobEntity convert(ScheduleJobVO vo); + + ScheduleJobVO convert(ScheduleJobEntity entity); + + List convertList(List list); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java new file mode 100644 index 0000000..b3620f6 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/convert/ScheduleJobLogConvert.java @@ -0,0 +1,25 @@ +package net.maku.quartz.convert; + +import net.maku.quartz.entity.ScheduleJobLogEntity; +import net.maku.quartz.vo.ScheduleJobLogVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** +* 定时任务日志 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface ScheduleJobLogConvert { + ScheduleJobLogConvert INSTANCE = Mappers.getMapper(ScheduleJobLogConvert.class); + + ScheduleJobLogEntity convert(ScheduleJobLogVO vo); + + ScheduleJobLogVO convert(ScheduleJobLogEntity entity); + + List convertList(List list); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java new file mode 100644 index 0000000..2328b47 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobDao.java @@ -0,0 +1,15 @@ +package net.maku.quartz.dao; + +import net.maku.framework.common.dao.BaseDao; +import net.maku.quartz.entity.ScheduleJobEntity; +import org.apache.ibatis.annotations.Mapper; + +/** +* 定时任务 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface ScheduleJobDao extends BaseDao { + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java new file mode 100644 index 0000000..a03e425 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/dao/ScheduleJobLogDao.java @@ -0,0 +1,15 @@ +package net.maku.quartz.dao; + +import net.maku.framework.common.dao.BaseDao; +import net.maku.quartz.entity.ScheduleJobLogEntity; +import org.apache.ibatis.annotations.Mapper; + +/** +* 定时任务日志 +* +* @author 阿沐 babamu@126.com +*/ +@Mapper +public interface ScheduleJobLogDao extends BaseDao { + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java new file mode 100644 index 0000000..5ece222 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java @@ -0,0 +1,108 @@ +package net.maku.quartz.entity; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 定时任务 + * + * @author 阿沐 babamu@126.com + */ +@Data +@TableName("schedule_job") +public class ScheduleJobEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @TableId + private Long id; + + /** + * 任务名称 + */ + private String jobName; + + /** + * 任务组名 + */ + private String jobGroup; + + /** + * bean名称 + */ + private String beanName; + + /** + * 执行方法 + */ + private String method; + + /** + * 方法参数 + */ + private String params; + + /** + * cron表达式 + */ + private String cronExpression; + + /** + * 状态 + */ + private Integer status; + + /** + * 是否并发 0:禁止 1:允许 + */ + private Integer concurrent; + + /** + * 备注 + */ + private String remark; + + /** + * 创建者 + */ + @TableField(fill = FieldFill.INSERT) + private Long creator; + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Date createTime; + + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateTime; + + /** + * 版本号 + */ + @Version + @TableField(fill = FieldFill.INSERT) + private Integer version; + + /** + * 删除标记 + */ + @TableLogic + @TableField(fill = FieldFill.INSERT) + private Integer deleted; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java new file mode 100644 index 0000000..e5f5734 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobLogEntity.java @@ -0,0 +1,76 @@ +package net.maku.quartz.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +/** + * 定时任务日志 + * + * @author 阿沐 babamu@126.com + */ +@Data +@TableName("schedule_job_log") +public class ScheduleJobLogEntity { + /** + * id + */ + @TableId + private Long id; + + /** + * 任务id + */ + private Long jobId; + + /** + * 任务名称 + */ + private String jobName; + + /** + * 任务组名 + */ + private String jobGroup; + + /** + * spring bean名称 + */ + private String beanName; + + /** + * 执行方法 + */ + private String method; + + /** + * 参数 + */ + private String params; + + /** + * 任务状态 + */ + private Integer status; + + /** + * 异常信息 + */ + private String error; + + /** + * 耗时(单位:毫秒) + */ + private Long times; + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Date createTime; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java new file mode 100644 index 0000000..436f375 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleConcurrentEnum.java @@ -0,0 +1,24 @@ +package net.maku.quartz.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 定时任务并发枚举 + * + * @author 阿沐 babamu@126.com + */ +@Getter +@AllArgsConstructor +public enum ScheduleConcurrentEnum { + /** + * 禁止 + */ + NO(0), + /** + * 允许 + */ + YES(1); + + private final int value; +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java new file mode 100644 index 0000000..1d27f46 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/enums/ScheduleStatusEnum.java @@ -0,0 +1,24 @@ +package net.maku.quartz.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 定时任务状态枚举 + * + * @author 阿沐 babamu@126.com + */ +@Getter +@AllArgsConstructor +public enum ScheduleStatusEnum { + /** + * 暂停 + */ + PAUSE(0), + /** + * 正常 + */ + NORMAL(1); + + private final int value; +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java new file mode 100644 index 0000000..4fa134a --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobLogQuery.java @@ -0,0 +1,26 @@ +package net.maku.quartz.query; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.maku.framework.common.query.Query; + +/** +* 定时任务日志查询 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@EqualsAndHashCode(callSuper = false) +@Schema(description = "定时任务日志查询") +public class ScheduleJobLogQuery extends Query { + @Schema(description = "任务id") + private Long jobId; + + @Schema(description = "任务名称") + private String jobName; + + @Schema(description = "任务组名") + private String jobGroup; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java new file mode 100644 index 0000000..061b793 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/query/ScheduleJobQuery.java @@ -0,0 +1,26 @@ +package net.maku.quartz.query; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.maku.framework.common.query.Query; + +/** +* 定时任务查询 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@EqualsAndHashCode(callSuper = false) +@Schema(description = "定时任务查询") +public class ScheduleJobQuery extends Query { + @Schema(description = "任务名称") + private String jobName; + + @Schema(description = "任务组名") + private String jobGroup; + + @Schema(description = "状态") + private Integer status; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java new file mode 100644 index 0000000..71532de --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobLogService.java @@ -0,0 +1,18 @@ +package net.maku.quartz.service; + +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.BaseService; +import net.maku.quartz.entity.ScheduleJobLogEntity; +import net.maku.quartz.query.ScheduleJobLogQuery; +import net.maku.quartz.vo.ScheduleJobLogVO; + +/** + * 定时任务日志 + * + * @author 阿沐 babamu@126.com + */ +public interface ScheduleJobLogService extends BaseService { + + PageResult page(ScheduleJobLogQuery query); + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java new file mode 100644 index 0000000..bf4ed9e --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/ScheduleJobService.java @@ -0,0 +1,29 @@ +package net.maku.quartz.service; + +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.BaseService; +import net.maku.quartz.entity.ScheduleJobEntity; +import net.maku.quartz.query.ScheduleJobQuery; +import net.maku.quartz.vo.ScheduleJobVO; + +import java.util.List; + +/** + * 定时任务 + * + * @author 阿沐 babamu@126.com + */ +public interface ScheduleJobService extends BaseService { + + PageResult page(ScheduleJobQuery query); + + void save(ScheduleJobVO vo); + + void update(ScheduleJobVO vo); + + void delete(List idList); + + void run(ScheduleJobVO vo); + + void changeStatus(ScheduleJobVO vo); +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java new file mode 100644 index 0000000..ed5d816 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobLogServiceImpl.java @@ -0,0 +1,43 @@ +package net.maku.quartz.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.impl.BaseServiceImpl; +import net.maku.quartz.convert.ScheduleJobLogConvert; +import net.maku.quartz.dao.ScheduleJobLogDao; +import net.maku.quartz.entity.ScheduleJobLogEntity; +import net.maku.quartz.query.ScheduleJobLogQuery; +import net.maku.quartz.service.ScheduleJobLogService; +import net.maku.quartz.vo.ScheduleJobLogVO; +import org.springframework.stereotype.Service; + +/** + * 定时任务日志 + * + * @author 阿沐 babamu@126.com + */ +@Service +@AllArgsConstructor +public class ScheduleJobLogServiceImpl extends BaseServiceImpl implements ScheduleJobLogService { + + @Override + public PageResult page(ScheduleJobLogQuery query) { + IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); + + return new PageResult<>(ScheduleJobLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); + } + + private LambdaQueryWrapper getWrapper(ScheduleJobLogQuery query){ + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.like(StrUtil.isNotBlank(query.getJobName()), ScheduleJobLogEntity::getJobName, query.getJobName()); + wrapper.like(StrUtil.isNotBlank(query.getJobGroup()), ScheduleJobLogEntity::getJobGroup, query.getJobGroup()); + wrapper.eq(query.getJobId() != null, ScheduleJobLogEntity::getJobId, query.getJobId()); + wrapper.orderByDesc(ScheduleJobLogEntity::getId); + return wrapper; + } + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java new file mode 100644 index 0000000..df39824 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/service/impl/ScheduleJobServiceImpl.java @@ -0,0 +1,126 @@ +package net.maku.quartz.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.AllArgsConstructor; +import net.maku.framework.common.page.PageResult; +import net.maku.framework.common.service.impl.BaseServiceImpl; +import net.maku.quartz.convert.ScheduleJobConvert; +import net.maku.quartz.dao.ScheduleJobDao; +import net.maku.quartz.entity.ScheduleJobEntity; +import net.maku.quartz.enums.ScheduleStatusEnum; +import net.maku.quartz.query.ScheduleJobQuery; +import net.maku.quartz.service.ScheduleJobService; +import net.maku.quartz.utils.ScheduleUtils; +import net.maku.quartz.vo.ScheduleJobVO; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.PostConstruct; +import java.util.List; + +/** + * 定时任务 + * + * @author 阿沐 babamu@126.com + */ +@Service +@AllArgsConstructor +public class ScheduleJobServiceImpl extends BaseServiceImpl implements ScheduleJobService { + private final Scheduler scheduler; + + /** + * 启动项目时,初始化定时器 + */ + @PostConstruct + public void init() throws SchedulerException { + scheduler.clear(); + List scheduleJobList = baseMapper.selectList(null); + for (ScheduleJobEntity scheduleJob : scheduleJobList) { + ScheduleUtils.createScheduleJob(scheduler, scheduleJob); + } + } + + @Override + public PageResult page(ScheduleJobQuery query) { + IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); + + return new PageResult<>(ScheduleJobConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); + } + + private LambdaQueryWrapper getWrapper(ScheduleJobQuery query){ + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.like(StrUtil.isNotBlank(query.getJobName()), ScheduleJobEntity::getJobName, query.getJobName()); + wrapper.like(StrUtil.isNotBlank(query.getJobGroup()), ScheduleJobEntity::getJobGroup, query.getJobGroup()); + wrapper.eq(query.getStatus() != null, ScheduleJobEntity::getStatus, query.getStatus()); + + return wrapper; + } + + @Override + public void save(ScheduleJobVO vo) { + ScheduleJobEntity entity = ScheduleJobConvert.INSTANCE.convert(vo); + + entity.setStatus(ScheduleStatusEnum.PAUSE.getValue()); + if(baseMapper.insert(entity) > 0) { + ScheduleUtils.createScheduleJob(scheduler, entity); + } + } + + @Override + public void update(ScheduleJobVO vo) { + ScheduleJobEntity entity = ScheduleJobConvert.INSTANCE.convert(vo); + + // 更新定时任务 + if(updateById(entity)) { + ScheduleJobEntity scheduleJob = getById(entity.getId()); + ScheduleUtils.updateSchedulerJob(scheduler, scheduleJob); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(List idList) { + for(Long id: idList){ + ScheduleJobEntity scheduleJob = getById(id); + + // 删除定时任务 + if (removeById(id)) { + ScheduleUtils.deleteScheduleJob(scheduler, scheduleJob); + } + } + } + + @Override + public void run(ScheduleJobVO vo) { + ScheduleJobEntity scheduleJob = getById(vo.getId()); + if(scheduleJob == null) { + return; + } + + ScheduleUtils.run(scheduler, scheduleJob); + } + + @Override + public void changeStatus(ScheduleJobVO vo) { + ScheduleJobEntity scheduleJob = getById(vo.getId()); + if(scheduleJob == null) { + return; + } + + // 更新数据 + scheduleJob.setStatus(vo.getStatus()); + updateById(scheduleJob); + + if(ScheduleStatusEnum.PAUSE.getValue() == vo.getStatus()) { + ScheduleUtils.pauseJob(scheduler, scheduleJob); + }else if(ScheduleStatusEnum.NORMAL.getValue() == vo.getStatus()) { + ScheduleUtils.resumeJob(scheduler, scheduleJob); + } + } + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/task/TestTask.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/task/TestTask.java new file mode 100644 index 0000000..27f9c0c --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/task/TestTask.java @@ -0,0 +1,19 @@ +package net.maku.quartz.task; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 测试定时任务 + * + * @author 阿沐 babamu@126.com + */ +@Slf4j +@Component +public class TestTask { + + public void run(String params) throws InterruptedException { + log.info("我是testTask.run(),参数:{},正在被执行。", params); + Thread.sleep(1000); + } +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java new file mode 100644 index 0000000..5d54566 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/AbstractScheduleJob.java @@ -0,0 +1,83 @@ +package net.maku.quartz.utils; + +import cn.hutool.extra.spring.SpringUtil; +import lombok.extern.slf4j.Slf4j; +import net.maku.framework.common.utils.ExceptionUtils; +import net.maku.quartz.entity.ScheduleJobEntity; +import net.maku.quartz.entity.ScheduleJobLogEntity; +import net.maku.quartz.enums.ScheduleStatusEnum; +import net.maku.quartz.service.ScheduleJobLogService; +import org.apache.commons.lang3.StringUtils; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.springframework.beans.BeanUtils; + +import java.lang.reflect.Method; +import java.util.Date; + +@Slf4j +public abstract class AbstractScheduleJob implements Job { + private static final ThreadLocal threadLocal = new ThreadLocal<>(); + + @Override + public void execute(JobExecutionContext context) { + ScheduleJobEntity scheduleJob = new ScheduleJobEntity(); + BeanUtils.copyProperties(context.getMergedJobDataMap().get(ScheduleUtils.JOB_PARAM_KEY), scheduleJob); + + try { + threadLocal.set(new Date()); + doExecute(scheduleJob); + saveLog(scheduleJob, null); + } catch (Exception e) { + log.error("任务执行失败,任务ID:{}", scheduleJob.getId(), e); + saveLog(scheduleJob, e); + } + } + + /** + * 执行spring bean方法 + */ + protected void doExecute(ScheduleJobEntity scheduleJob) throws Exception { + log.info("准备执行任务,任务ID:{}", scheduleJob.getId()); + + Object bean = SpringUtil.getBean(scheduleJob.getBeanName()); + Method method = bean.getClass().getDeclaredMethod(scheduleJob.getMethod(), String.class); + method.invoke(bean, scheduleJob.getParams()); + + log.info("任务执行完毕,任务ID:{}", scheduleJob.getId()); + } + + /** + * 保存 log + */ + protected void saveLog(ScheduleJobEntity scheduleJob, Exception e) { + Date startTime = threadLocal.get(); + threadLocal.remove(); + + // 执行总时长 + long times = System.currentTimeMillis() - startTime.getTime(); + + // 保存执行记录 + ScheduleJobLogEntity log = new ScheduleJobLogEntity(); + log.setJobId(scheduleJob.getId()); + log.setJobName(scheduleJob.getJobName()); + log.setJobGroup(scheduleJob.getJobGroup()); + log.setBeanName(scheduleJob.getBeanName()); + log.setMethod(scheduleJob.getMethod()); + log.setParams(scheduleJob.getParams()); + log.setTimes(times); + log.setCreateTime(new Date()); + + if (e != null) { + log.setStatus(ScheduleStatusEnum.PAUSE.getValue()); + String error = StringUtils.substring(ExceptionUtils.getExceptionMessage(e), 0, 2000); + log.setError(error); + } else { + log.setStatus(ScheduleStatusEnum.NORMAL.getValue()); + } + + // 保存日志 + SpringUtil.getBean(ScheduleJobLogService.class).save(log); + } + +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java new file mode 100644 index 0000000..b5d5e13 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/CronUtils.java @@ -0,0 +1,33 @@ +package net.maku.quartz.utils; + +import org.quartz.CronExpression; + +import java.text.ParseException; +import java.util.Date; + +/** + * cron 工具类 + * + * @author 阿沐 babamu@126.com + * + */ +public class CronUtils { + /** + * 验证Cron表达式是否有效 + */ + public static boolean isValid(String cronExpression) { + return CronExpression.isValidExpression(cronExpression); + } + + /** + * 根据给定的Cron表达式,返回下一个执行时间 + */ + public static Date getNextExecution(String cronExpression) { + try { + CronExpression cron = new CronExpression(cronExpression); + return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); + } catch (ParseException e) { + throw new IllegalArgumentException(e.getMessage()); + } + } +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java new file mode 100644 index 0000000..2bdb7fb --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleConcurrentExecution.java @@ -0,0 +1,11 @@ +package net.maku.quartz.utils; + +/** + * 允许并发(不会等待上一次任务执行完毕,只要时间到就会执行) + * + * @author 阿沐 babamu@126.com + * + */ +public class ScheduleConcurrentExecution extends AbstractScheduleJob { + +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java new file mode 100644 index 0000000..0d46460 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleDisallowConcurrentExecution.java @@ -0,0 +1,14 @@ +package net.maku.quartz.utils; + +import org.quartz.DisallowConcurrentExecution; + +/** + * 禁止并发 + * + * @author 阿沐 babamu@126.com + * + */ +@DisallowConcurrentExecution +public class ScheduleDisallowConcurrentExecution extends AbstractScheduleJob { + +} diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java new file mode 100644 index 0000000..31dea46 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/utils/ScheduleUtils.java @@ -0,0 +1,161 @@ +package net.maku.quartz.utils; + +import net.maku.framework.common.exception.ServerException; +import net.maku.quartz.entity.ScheduleJobEntity; +import net.maku.quartz.enums.ScheduleConcurrentEnum; +import net.maku.quartz.enums.ScheduleStatusEnum; +import org.quartz.*; + +/** + * 定时任务工具类 + * + * @author 阿沐 babamu@126.com + */ +public class ScheduleUtils { + private final static String JOB_NAME = "TASK_NAME_"; + /** + * 任务调度参数key + */ + public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY"; + + /** + * 获取quartz任务类 + */ + public static Class getJobClass(ScheduleJobEntity scheduleJob) { + if(scheduleJob.getConcurrent().equals(ScheduleConcurrentEnum.NO.getValue())){ + return ScheduleDisallowConcurrentExecution.class; + }else { + return ScheduleConcurrentExecution.class; + } + } + + /** + * 获取触发器key + */ + public static TriggerKey getTriggerKey(ScheduleJobEntity scheduleJob) { + return TriggerKey.triggerKey(JOB_NAME + scheduleJob.getId(), scheduleJob.getJobGroup()); + } + + /** + * 获取jobKey + */ + public static JobKey getJobKey(ScheduleJobEntity scheduleJob) { + return JobKey.jobKey(JOB_NAME + scheduleJob.getId(), scheduleJob.getJobGroup()); + } + + /** + * 创建定时任务 + */ + public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { + try { + // job key + JobKey jobKey = getJobKey(scheduleJob); + // 构建job信息 + JobDetail jobDetail = JobBuilder.newJob(getJobClass(scheduleJob)).withIdentity(jobKey).build(); + + // 表达式调度构建器 + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()) + .withMisfireHandlingInstructionDoNothing(); + + // 按新的cronExpression表达式构建一个新的trigger + CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob)) + .withSchedule(scheduleBuilder).build(); + + // 放入参数,运行时的方法可以获取 + jobDetail.getJobDataMap().put(JOB_PARAM_KEY, scheduleJob); + + scheduler.scheduleJob(jobDetail, trigger); + + // 判断是否存在 + if (scheduler.checkExists(jobKey)){ + // 防止创建时存在数据问题,先移除,然后再执行创建操作 + scheduler.deleteJob(jobKey); + } + + // 判断任务是否过期 + if (CronUtils.getNextExecution(scheduleJob.getCronExpression()) != null){ + // 执行调度任务 + scheduler.scheduleJob(jobDetail, trigger); + } + + // 暂停任务 + if (scheduleJob.getStatus().equals(ScheduleStatusEnum.PAUSE.getValue())){ + scheduler.pauseJob(jobKey); + } + } catch (SchedulerException e) { + throw new ServerException("创建定时任务失败", e); + } + } + + + + /** + * 立即执行任务 + */ + public static void run(Scheduler scheduler, ScheduleJobEntity scheduleJob) { + try { + // 参数 + JobDataMap dataMap = new JobDataMap(); + dataMap.put(JOB_PARAM_KEY, scheduleJob); + + JobKey jobKey = getJobKey(scheduleJob); + if (scheduler.checkExists(jobKey)) { + scheduler.triggerJob(jobKey, dataMap); + } + } catch (SchedulerException e) { + throw new ServerException("执行定时任务失败", e); + } + } + + /** + * 暂停任务 + */ + public static void pauseJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { + try { + scheduler.pauseJob(getJobKey(scheduleJob)); + } catch (SchedulerException e) { + throw new ServerException("暂停定时任务失败", e); + } + } + + /** + * 恢复任务 + */ + public static void resumeJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { + try { + scheduler.resumeJob(getJobKey(scheduleJob)); + } catch (SchedulerException e) { + throw new ServerException("恢复定时任务失败", e); + } + } + + /** + * 更新定时任务 + */ + public static void updateSchedulerJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { + // 判断是否存在 + JobKey jobKey = ScheduleUtils.getJobKey(scheduleJob); + + try { + // 防止创建时存在数据问题,先移除,然后再执行创建操作 + if (scheduler.checkExists(jobKey)) { + scheduler.deleteJob(jobKey); + } + }catch (SchedulerException e){ + throw new ServerException("更新定时任务失败", e); + } + + ScheduleUtils.createScheduleJob(scheduler, scheduleJob); + } + + /** + * 删除定时任务 + */ + public static void deleteScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) { + try { + scheduler.deleteJob(getJobKey(scheduleJob)); + } catch (SchedulerException e) { + throw new ServerException("删除定时任务失败", e); + } + } +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java new file mode 100644 index 0000000..2701248 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobLogVO.java @@ -0,0 +1,55 @@ +package net.maku.quartz.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import net.maku.framework.common.utils.DateUtils; + +import java.io.Serializable; +import java.util.Date; + +/** +* 定时任务日志 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@Schema(description = "定时任务日志") +public class ScheduleJobLogVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "任务id") + private Long jobId; + + @Schema(description = "任务名称") + private String jobName; + + @Schema(description = "任务组名") + private String jobGroup; + + @Schema(description = "spring bean名称") + private String beanName; + + @Schema(description = "执行方法") + private String method; + + @Schema(description = "参数") + private String params; + + @Schema(description = "任务状态") + private Integer status; + + @Schema(description = "异常信息") + private String error; + + @Schema(description = "耗时(单位:毫秒)") + private Integer times; + + @Schema(description = "创建时间") + @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) + private Date createTime; + +} \ No newline at end of file diff --git a/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java new file mode 100644 index 0000000..fea3674 --- /dev/null +++ b/maku-boot-module/maku-module-quartz/src/main/java/net/maku/quartz/vo/ScheduleJobVO.java @@ -0,0 +1,55 @@ +package net.maku.quartz.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import net.maku.framework.common.utils.DateUtils; + +import java.io.Serializable; +import java.util.Date; + +/** +* 定时任务 +* +* @author 阿沐 babamu@126.com +*/ +@Data +@Schema(description = "定时任务") +public class ScheduleJobVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "任务名称") + private String jobName; + + @Schema(description = "任务组名") + private String jobGroup; + + @Schema(description = "bean名称") + private String beanName; + + @Schema(description = "执行方法") + private String method; + + @Schema(description = "参数") + private String params; + + @Schema(description = "cron表达式") + private String cronExpression; + + @Schema(description = "状态 ") + private Integer status; + + @Schema(description = "是否并发") + private Integer concurrent; + + @Schema(description = "备注") + private String remark; + + @Schema(description = "创建时间") + @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) + private Date createTime; + +} \ No newline at end of file diff --git a/maku-boot-module/pom.xml b/maku-boot-module/pom.xml index e24155f..d67f8c1 100644 --- a/maku-boot-module/pom.xml +++ b/maku-boot-module/pom.xml @@ -9,8 +9,8 @@ pom - maku-boot-quartz - maku-boot-message + maku-module-quartz + maku-module-message \ No newline at end of file diff --git a/maku-server/pom.xml b/maku-server/pom.xml index 74d1075..15d4829 100644 --- a/maku-server/pom.xml +++ b/maku-server/pom.xml @@ -22,12 +22,12 @@ - + net.maku - maku-boot-message + maku-module-message ${revision}