diff --git a/austin-cron/src/main/java/com/java3y/austin/constants/XxlJobConstant.java b/austin-cron/src/main/java/com/java3y/austin/constants/XxlJobConstant.java index 8c98cfcdc..6566ceba4 100644 --- a/austin-cron/src/main/java/com/java3y/austin/constants/XxlJobConstant.java +++ b/austin-cron/src/main/java/com/java3y/austin/constants/XxlJobConstant.java @@ -11,7 +11,7 @@ public class XxlJobConstant { /** * 接口路径 */ - public static final String LOGIN_URL = "/xxl-job-admin/login"; + public static final String LOGIN_URL = "/login"; public static final String INSERT_URL = "/jobinfo/add"; public static final String UPDATE_URL = "/jobinfo/update"; public static final String DELETE_URL = "/jobinfo/remove"; diff --git a/austin-cron/src/main/java/com/java3y/austin/service/impl/CronTaskServiceImpl.java b/austin-cron/src/main/java/com/java3y/austin/service/impl/CronTaskServiceImpl.java index c1fd6461f..a43062292 100644 --- a/austin-cron/src/main/java/com/java3y/austin/service/impl/CronTaskServiceImpl.java +++ b/austin-cron/src/main/java/com/java3y/austin/service/impl/CronTaskServiceImpl.java @@ -1,5 +1,6 @@ package com.java3y.austin.service.impl; +import cn.hutool.core.util.IdUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; @@ -39,7 +40,7 @@ public BasicResultVO saveCronTask(XxlJobInfo xxlJobInfo) { Map params = JSON.parseObject(JSON.toJSONString(xxlJobInfo), Map.class); String path; - if (xxlJobInfo.getId() != null) { + if (xxlJobInfo.getId() == null) { path = xxlAddresses + XxlJobConstant.INSERT_URL; } else { path = xxlAddresses + XxlJobConstant.UPDATE_URL; @@ -69,7 +70,7 @@ public BasicResultVO saveCronTask(XxlJobInfo xxlJobInfo) { log.error("TaskService#saveTask fail:{}", JSON.toJSONString(response.body())); return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(response.body())); } - return BasicResultVO.success(JSON.toJSONString(response.body())); + return BasicResultVO.success(JSON.parseObject(response.body())); } @Override @@ -122,6 +123,7 @@ private String getCookie() { Map hashMap = new HashMap<>(); hashMap.put("userName", xxlUserName); hashMap.put("password", xxlPassword); + hashMap.put("randomCode", IdUtil.fastSimpleUUID()); log.info("TaskService#getCookie params:{}", hashMap); HttpResponse response = HttpRequest.post(path).form(hashMap).execute(); diff --git a/austin-cron/src/main/java/com/java3y/austin/utils/XxlJobUtils.java b/austin-cron/src/main/java/com/java3y/austin/utils/XxlJobUtils.java index 7fe937bb1..1e93ead52 100644 --- a/austin-cron/src/main/java/com/java3y/austin/utils/XxlJobUtils.java +++ b/austin-cron/src/main/java/com/java3y/austin/utils/XxlJobUtils.java @@ -19,7 +19,6 @@ public class XxlJobUtils { * 构建xxlJobInfo信息 * * @param messageTemplate - * @param triggerStatus 是否启动定时任务 * @return */ public static XxlJobInfo buildXxlJobInfo(MessageTemplate messageTemplate) { @@ -37,7 +36,7 @@ public static XxlJobInfo buildXxlJobInfo(MessageTemplate messageTemplate) { .scheduleConf(scheduleConf) .scheduleType(scheduleType) .misfireStrategy(MisfireStrategyEnum.DO_NOTHING.name()) - .executorBlockStrategy(ExecutorRouteStrategyEnum.CONSISTENT_HASH.name()) + .executorRouteStrategy(ExecutorRouteStrategyEnum.CONSISTENT_HASH.name()) .executorHandler(XxlJobConstant.HANDLER_NAME) .executorParam(JSON.toJSONString(messageTemplate)) .executorBlockStrategy(ExecutorBlockStrategyEnum.SERIAL_EXECUTION.name()) diff --git a/austin-web/src/main/java/com/java3y/austin/service/impl/MessageTemplateServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/service/impl/MessageTemplateServiceImpl.java index a929db814..e8602dc23 100644 --- a/austin-web/src/main/java/com/java3y/austin/service/impl/MessageTemplateServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/service/impl/MessageTemplateServiceImpl.java @@ -3,6 +3,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; import com.java3y.austin.constant.AustinConstant; import com.java3y.austin.dao.MessageTemplateDao; import com.java3y.austin.domain.MessageTemplate; @@ -89,12 +90,16 @@ public BasicResultVO startCronTask(Long id) { XxlJobInfo xxlJobInfo = XxlJobUtils.buildXxlJobInfo(messageTemplate); BasicResultVO basicResultVO = cronTaskService.saveCronTask(xxlJobInfo); - // basicResultVO.getData() - //cronTaskService.startCronTask() + JSONObject data = (JSONObject) basicResultVO.getData(); + if (data.get("content") != null) { + cronTaskService.startCronTask(Integer.valueOf(String.valueOf(data.get("content")))); + MessageTemplate clone = ObjectUtil.clone(messageTemplate).setMsgStatus(MessageStatus.RUN.getCode()).setUpdated(Math.toIntExact(DateUtil.currentSeconds())); + messageTemplateDao.save(clone); + return BasicResultVO.success(); + } else { + return BasicResultVO.fail(); + } - MessageTemplate clone = ObjectUtil.clone(messageTemplate).setMsgStatus(MessageStatus.RUN.getCode()).setUpdated(Math.toIntExact(DateUtil.currentSeconds())); - messageTemplateDao.save(clone); - return BasicResultVO.success(); } @Override diff --git a/austin-web/src/main/java/com/java3y/austin/vo/TaskParam.java b/austin-web/src/main/java/com/java3y/austin/vo/TaskParam.java deleted file mode 100644 index 88e0ff602..000000000 --- a/austin-web/src/main/java/com/java3y/austin/vo/TaskParam.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.java3y.austin.vo; - - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Map; - -/** - * xxlJob任务的参数 - * @author 3y - */ -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class TaskParam { - - /** - * 模板Id - */ - private String messageTemplateId; - - /** - * cron表达式 - */ - private String cron; - - /** - * 创建者 - */ - private String creator; - - - /** - * 额外参数信息 - */ - private Map extra; - -} diff --git a/sql/austin.sql b/sql/austin.sql index d44fc91bf..ef8c057c9 100644 --- a/sql/austin.sql +++ b/sql/austin.sql @@ -1,14 +1,17 @@ create database austin; +use austin; + + CREATE TABLE `message_template` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '标题', `audit_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '当前消息审核状态: 10.待审核 20.审核成功 30.被拒绝', - `flow_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '工单ID', + `flow_id` varchar(50) COLLATE utf8mb4_unicode_ci COMMENT '工单ID', `msg_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '当前消息状态:10.新建 20.停用 30.启用 40.等待发送 50.发送中 60.发送成功 70.发送失败', - `cron_task_id` int(11) COMMENT '定时任务Id (xxl-job-admin返回)', + `cron_task_id` bigint(20) COMMENT '定时任务Id (xxl-job-admin返回)', `id_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息的发送ID类型:10. userId 20.did 30.手机号 40.openId 50.email', `send_channel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息发送渠道:10.IM 20.Push 30.短信 40.Email 50.公众号 60.小程序', `template_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.运营类 20.技术类接口调用', @@ -59,19 +62,21 @@ CREATE TABLE `sms_record` /*测试短信*/ -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, id_type, send_channel, template_type, msg_type, expect_push_time, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated, deduplication_time, is_night_shield) VALUES (1, 'test短信', 10, 'yyyy', 10, 30, 30, 10, 10, '0', '{"content":"{$contentValue}"}', 10, 'yyyyc', 'yyyyu', 'yyyyyyz', 'yyyt', 'yyyy22', 0, 1636978066, 1636978066, 1, 0); +INSERT INTO austin.message_template (id, name, audit_status, msg_status, id_type, send_channel, template_type, msg_type, expect_push_time, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated, deduplication_time, is_night_shield) + +VALUES (1, 'test短信', 10, 10, 30, 30, 10, 10, '0', '{"content":"{$contentValue}"}', 10, 'yyyyc', 'yyyyu', 'yyyyyyz', 'yyyt', 'yyyy22', 0, 1636978066, 1636978066, 1, 0); /*测试短信+url链接追踪*/ -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, id_type, send_channel, template_type, +INSERT INTO austin.message_template (id, name, audit_status, msg_status, id_type, send_channel, template_type, msg_type, expect_push_time, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated, deduplication_time, is_night_shield) -VALUES (2, 'test短信', 10, 'yyyy', 10, 30, 30, 10, 20, '0', +VALUES (2, 'test短信', 10, 10, 30, 30, 10, 20, '0', '{"content":"{$contentValue}","url":"https://gitee.com/zhongfucheng/austin"}', 10, 'yyyyc', 'yyyyu', 'yyyyyyz', 'yyyt', 'yyyy22', 0, 1637411536, 1637411536, 1, 0); /*测试邮件发送*/ -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, id_type, send_channel, template_type, +INSERT INTO austin.message_template (id, name, audit_status, msg_status, id_type, send_channel, template_type, msg_type, expect_push_time, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated, deduplication_time, is_night_shield) -VALUES (3, 'test邮件', 10, 'yyyy', 10, 50, 40, 20, 10, '0', '{"content":"{$contentValue}","title":"{$title}"}', 10, +VALUES (3, 'test邮件', 10, 10, 50, 40, 20, 10, '0', '{"content":"{$contentValue}","title":"{$title}"}', 10, 'yyyyc', 'yyyyu', 'yyyyyyz', 'yyyt', 'yyyy22', 0, 1641546914, 1641546914, 1, 0); \ No newline at end of file