Explorar el Código

feat(): quartz任务适配DM数据库

chenjianhua hace 7 meses
padre
commit
8fc5af481d

+ 0 - 23
service-deploy/src/main/resources/application.yml

@@ -62,7 +62,6 @@ spring:
           auth: true
           ssl:
             enable: true
-
 email-rule:
   nav: "净值,业绩报酬,规模"
   valuation: "估值表"
@@ -101,25 +100,3 @@ simuwang:
     - path: "/**"
       filters: anon
 
-quartz:
-  #quartz相关属性配置
-  org:
-    quartz:
-      scheduler:
-        instanceName: DefaultQuartzScheduler #调度器的实例名
-        instanceId: AUTO #调度器编号自动生成
-      jobStore:
-        class: org.quartz.impl.jdbcjobstore.JobStoreTX
-        driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
-        tablePrefix: database.QRTZ_  #数据库表名前缀
-        isClustered: true #开启分布式部署
-        clusterCheckinInterval: 10000 #分布式节点有效性检查时间间隔,单位:秒
-        useProperties: false #是否读取自己写的配置文件
-        dataSource: qzds
-      dataSource:
-        qzds:
-          driver: dm.jdbc.driver.DmDriver #达梦数据库驱动
-          url: jdbc:dm://192.168.1.39:5236/PPW_EMAIL?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&clobAsString=true
-          user: PPW_EMAIL
-          password: Dmppw2024
-          validationQuery: select 0 from dual

+ 84 - 84
service-manage/src/main/java/com/simuwang/manage/init/QuartzInitConfig.java

@@ -1,84 +1,84 @@
-package com.simuwang.manage.init;
-
-import cn.hutool.crypto.asymmetric.KeyType;
-import cn.hutool.crypto.asymmetric.RSA;
-import com.alibaba.fastjson2.JSON;
-import com.simuwang.base.common.enums.OpenStatusType;
-import com.simuwang.base.common.util.DateUtils;
-import com.simuwang.base.common.util.QuartzUtils;
-import com.simuwang.base.config.DaqProperties;
-import com.simuwang.base.pojo.dos.MailboxInfoDO;
-import com.simuwang.base.pojo.dto.MailboxInfoDTO;
-import com.simuwang.base.pojo.dto.QuartzBean;
-import com.simuwang.manage.service.EmailConfigService;
-import org.quartz.Scheduler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
-
-import java.util.List;
-
-/**
- * 定时任务启动类
- * Author:   chenjianhua
- * Date:     2024/9/17 11:55
- * Description: ${DESCRIPTION}
- */
-@Configuration
-@Order(2)
-public class QuartzInitConfig implements ApplicationRunner {
-    @Autowired
-    private Scheduler scheduler;
-    private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
-    @Autowired
-    private EmailConfigService emailConfigService;
-
-    @Value("${spring.task.groupName}")
-    private String groupName;
-
-    @Autowired
-    private DaqProperties properties;
-    private String JOB_CLASS="com.simuwang.manage.task.ParseSchedulerTask";
-
-    @Override
-    public void run(ApplicationArguments args){
-        List<MailboxInfoDO> mailboxInfoDOS = emailConfigService.getAll();
-        for(MailboxInfoDO mailboxInfoDO : mailboxInfoDOS){
-            try{
-                QuartzBean quartzBean = new QuartzBean();
-                quartzBean.setCronExpression(mailboxInfoDO.getCron());
-                quartzBean.setStatus(mailboxInfoDO.getOpenStatus());
-                quartzBean.setGroupName(groupName);
-                quartzBean.setJobName(mailboxInfoDO.getEmail());
-                quartzBean.setJobClass(JOB_CLASS);
-                //请求参数
-                MailboxInfoDTO paramDTO = new MailboxInfoDTO();
-                paramDTO.setAccount(mailboxInfoDO.getEmail());
-                String password = mailboxInfoDO.getPassword();
-                try{
-                    String privateKey = this.properties.getSecurityRsa().getPrivateKey();
-                    password = new RSA(privateKey, null).decryptStr(password, KeyType.PrivateKey);
-                }catch (Exception e){
-                    logger.error(e.getMessage(),e);
-                }
-                paramDTO.setPassword(password);
-                paramDTO.setPort(mailboxInfoDO.getPort());
-                paramDTO.setHost(mailboxInfoDO.getServer());
-                paramDTO.setProtocol(mailboxInfoDO.getProtocol());
-                quartzBean.setJobParam(JSON.toJSONString(paramDTO));
-                if(mailboxInfoDO.getOpenStatus() != null && mailboxInfoDO.getOpenStatus().equals(OpenStatusType.YES.getCode())){
-                    logger.info(quartzBean.getJobName()+":创建定时任务,cron:"+quartzBean.getCronExpression()+"--"+ DateUtils.getNowDate());
-                    QuartzUtils.createScheduleJob(scheduler,quartzBean);
-                }
-            }catch (Exception e) {
-                logger.error(e.getMessage(),e);
-            }
-        }
-    }
-}
+//package com.simuwang.manage.init;
+//
+//import cn.hutool.crypto.asymmetric.KeyType;
+//import cn.hutool.crypto.asymmetric.RSA;
+//import com.alibaba.fastjson2.JSON;
+//import com.simuwang.base.common.enums.OpenStatusType;
+//import com.simuwang.base.common.util.DateUtils;
+//import com.simuwang.base.common.util.QuartzUtils;
+//import com.simuwang.base.config.DaqProperties;
+//import com.simuwang.base.pojo.dos.MailboxInfoDO;
+//import com.simuwang.base.pojo.dto.MailboxInfoDTO;
+//import com.simuwang.base.pojo.dto.QuartzBean;
+//import com.simuwang.manage.service.EmailConfigService;
+//import org.quartz.Scheduler;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.boot.ApplicationArguments;
+//import org.springframework.boot.ApplicationRunner;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.core.annotation.Order;
+//
+//import java.util.List;
+//
+///**
+// * 定时任务启动类
+// * Author:   chenjianhua
+// * Date:     2024/9/17 11:55
+// * Description: ${DESCRIPTION}
+// */
+//@Configuration
+//@Order(2)
+//public class QuartzInitConfig implements ApplicationRunner {
+//    @Autowired
+//    private Scheduler scheduler;
+//    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+//
+//    @Autowired
+//    private EmailConfigService emailConfigService;
+//
+//    @Value("${spring.task.groupName}")
+//    private String groupName;
+//
+//    @Autowired
+//    private DaqProperties properties;
+//    private String JOB_CLASS="com.simuwang.manage.task.ParseSchedulerTask";
+//
+//    @Override
+//    public void run(ApplicationArguments args){
+//        List<MailboxInfoDO> mailboxInfoDOS = emailConfigService.getAll();
+//        for(MailboxInfoDO mailboxInfoDO : mailboxInfoDOS){
+//            try{
+//                QuartzBean quartzBean = new QuartzBean();
+//                quartzBean.setCronExpression(mailboxInfoDO.getCron());
+//                quartzBean.setStatus(mailboxInfoDO.getOpenStatus());
+//                quartzBean.setGroupName(groupName);
+//                quartzBean.setJobName(mailboxInfoDO.getEmail());
+//                quartzBean.setJobClass(JOB_CLASS);
+//                //请求参数
+//                MailboxInfoDTO paramDTO = new MailboxInfoDTO();
+//                paramDTO.setAccount(mailboxInfoDO.getEmail());
+//                String password = mailboxInfoDO.getPassword();
+//                try{
+//                    String privateKey = this.properties.getSecurityRsa().getPrivateKey();
+//                    password = new RSA(privateKey, null).decryptStr(password, KeyType.PrivateKey);
+//                }catch (Exception e){
+//                    logger.error(e.getMessage(),e);
+//                }
+//                paramDTO.setPassword(password);
+//                paramDTO.setPort(mailboxInfoDO.getPort());
+//                paramDTO.setHost(mailboxInfoDO.getServer());
+//                paramDTO.setProtocol(mailboxInfoDO.getProtocol());
+//                quartzBean.setJobParam(JSON.toJSONString(paramDTO));
+//                if(mailboxInfoDO.getOpenStatus() != null && mailboxInfoDO.getOpenStatus().equals(OpenStatusType.YES.getCode())){
+//                    logger.info(quartzBean.getJobName()+":创建定时任务,cron:"+quartzBean.getCronExpression()+"--"+ DateUtils.getNowDate());
+//                    QuartzUtils.createScheduleJob(scheduler,quartzBean);
+//                }
+//            }catch (Exception e) {
+//                logger.error(e.getMessage(),e);
+//            }
+//        }
+//    }
+//}

+ 53 - 0
service-manage/src/main/java/com/simuwang/manage/init/ScheduleConfig.java

@@ -0,0 +1,53 @@
+package com.simuwang.manage.init;
+
+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;
+
+/**
+ * 定时任务配置
+ * FileName: SchedulerConfig
+ * Author:   chenjianhua
+ * Date:     2024/9/22 14:39
+ * Description: ${DESCRIPTION}
+ */
+@Configuration
+public class ScheduleConfig {
+    @Bean
+    public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
+        SchedulerFactoryBean factory = new SchedulerFactoryBean();
+        factory.setDataSource(dataSource);
+        // quartz参数
+        Properties prop = new Properties();
+        prop.put("org.quartz.scheduler.instanceName", "scheduler");
+        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_");
+        factory.setQuartzProperties(prop);
+
+        factory.setSchedulerName("Scheduler");
+        // 延时启动
+        factory.setStartupDelay(1);
+        factory.setApplicationContextSchedulerContextKey("applicationContextKey");
+        // 可选,QuartzScheduler
+        // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
+        factory.setOverwriteExistingJobs(true);
+        // 设置自动启动,默认为true
+        factory.setAutoStartup(true);
+        return factory;
+    }
+}
+