diff --git a/dinky-admin/src/main/java/org/dinky/configure/schedule/Alert/JobAlerts.java b/dinky-admin/src/main/java/org/dinky/configure/schedule/Alert/JobAlerts.java index 5ffc6ba5f7..686ce16063 100644 --- a/dinky-admin/src/main/java/org/dinky/configure/schedule/Alert/JobAlerts.java +++ b/dinky-admin/src/main/java/org/dinky/configure/schedule/Alert/JobAlerts.java @@ -130,7 +130,7 @@ public class JobAlerts extends BaseSchedule { */ @PostConstruct public void init() { - refeshRulesData(); + refreshRulesData(); addSchedule(AlertRuleOptions.JOB_ALERT_SCHEDULE, this::check, new PeriodicTrigger(1000 * 30)); } @@ -170,7 +170,7 @@ protected void check() { /** * Refreshes the alert rules and related data. */ - public void refeshRulesData() { + public void refreshRulesData() { ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_REFRESH_RULES_DATA, new ExceptionRule()); ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_CHECKPOINT_RULES, new CheckpointsRule()); diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java b/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java index 28d41297cd..1a0953a8ef 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java @@ -39,6 +39,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import io.swagger.annotations.ApiImplicitParam; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -62,16 +63,31 @@ public ProTableResult list(@RequestBody JsonNode para) { } @PutMapping + @ApiImplicitParam( + name = "alertRule", + value = "alertRule", + required = true, + dataType = "AlertRule", + paramType = "body", + dataTypeClass = AlertRule.class) public Result saveOrUpdateAlertRule(@RequestBody AlertRule alertRule) { boolean saved = alertRuleService.saveOrUpdate(alertRule); if (saved) { - jobAlerts.refeshRulesData(); + jobAlerts.refreshRulesData(); return Result.succeed(Status.MODIFY_SUCCESS); } return Result.failed(Status.MODIFY_FAILED); } @DeleteMapping + @ApiImplicitParam( + name = "id", + value = "id", + required = true, + dataType = "Integer", + paramType = "query", + dataTypeClass = Integer.class, + example = "1") public Result deleteAlertRuleById(@RequestParam Integer id) { if (alertRuleService.removeById(id)) { return Result.succeed(Status.DELETE_SUCCESS); diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateConteroller.java b/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateConteroller.java index 2210d2b3ca..7cb0362b1f 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateConteroller.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateConteroller.java @@ -33,8 +33,10 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.ApiImplicitParam; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -50,14 +52,31 @@ public Result> list() { } @DeleteMapping - @Log(title = "Delete AlertTemplate ", businessType = BusinessType.INSERT_OR_UPDATE) - public Result delete(int id) { - return Result.succeed(alertTemplateService.removeById(id)); + @Log(title = "Delete AlertTemplate ", businessType = BusinessType.DELETE) + @ApiImplicitParam( + name = "id", + value = "AlertTemplate ID", + required = true, + dataType = "Integer", + paramType = "query", + example = "1") + public Result deleteAlertTemplateById(@RequestParam Integer id) { + if (alertTemplateService.removeById(id)) { + return Result.succeed(Status.DELETE_SUCCESS); + } + return Result.failed(Status.DELETE_FAILED); } @PutMapping @Log(title = "Insert OR Update AlertTemplate ", businessType = BusinessType.INSERT_OR_UPDATE) - public Result put(@RequestBody AlertTemplate alertTemplate) { + @ApiImplicitParam( + name = "alertTemplate", + value = "AlertTemplate", + required = true, + dataType = "AlertTemplate", + paramType = "body", + dataTypeClass = AlertTemplate.class) + public Result saveOrUpdateAlertTemplate(@RequestBody AlertTemplate alertTemplate) { if (alertTemplateService.saveOrUpdate(alertTemplate)) { return Result.succeed(Status.SAVE_SUCCESS); } else { diff --git a/dinky-admin/src/main/java/org/dinky/data/model/AlertRule.java b/dinky-admin/src/main/java/org/dinky/data/model/AlertRule.java index 4adc54afe4..e42819453e 100644 --- a/dinky-admin/src/main/java/org/dinky/data/model/AlertRule.java +++ b/dinky-admin/src/main/java/org/dinky/data/model/AlertRule.java @@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -31,11 +33,31 @@ @EqualsAndHashCode(callSuper = true) @Data @TableName("dinky_alert_rules") +@ApiModel(value = "AlertRule", description = "AlertRule") public class AlertRule extends SuperEntity { + @ApiModelProperty(value = "rule", required = true, dataType = "String", example = "rule") String rule; + + @ApiModelProperty(value = "templateId", required = true, dataType = "int", example = "1") int templateId; + + @ApiModelProperty( + value = "ruleType", + required = true, + dataType = "String", + example = "ruleType", + allowableValues = "CUSTOM,SYSTEM") String ruleType; + + @ApiModelProperty( + value = "triggerConditions", + required = true, + dataType = "String", + example = "or", + allowableValues = "or,and") String triggerConditions; + + @ApiModelProperty(value = "description", required = true, dataType = "String", example = "description") String description; } diff --git a/dinky-admin/src/main/java/org/dinky/data/model/AlertTemplate.java b/dinky-admin/src/main/java/org/dinky/data/model/AlertTemplate.java index 80ac1eca52..78ac61f0e3 100644 --- a/dinky-admin/src/main/java/org/dinky/data/model/AlertTemplate.java +++ b/dinky-admin/src/main/java/org/dinky/data/model/AlertTemplate.java @@ -23,12 +23,16 @@ import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) @TableName("dinky_alert_template") +@ApiModel(value = "AlertTemplate", description = "AlertTemplate") public class AlertTemplate extends SuperEntity { + @ApiModelProperty(value = "name", required = true, dataType = "String", example = "# 11 \n > 11") String templateContent; } diff --git a/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkAlert.java b/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkAlert.java index 70b6de721b..ea4291e7f9 100644 --- a/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkAlert.java +++ b/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkAlert.java @@ -24,17 +24,17 @@ import java.io.IOException; -import freemarker.template.TemplateException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import freemarker.template.TemplateException; + /** * DingTalkAlert * * @since 2022/2/23 19:28 */ public class DingTalkAlert extends AbstractAlert { - private static final Logger log = LoggerFactory.getLogger(DingTalkAlert.class); @Override diff --git a/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkSender.java b/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkSender.java index 0ae085620c..7e5aa42088 100644 --- a/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkSender.java +++ b/dinky-alert/dinky-alert-dingtalk/src/main/java/org/dinky/alert/dingtalk/DingTalkSender.java @@ -43,7 +43,6 @@ * */ public class DingTalkSender { - private static final Logger logger = LoggerFactory.getLogger(DingTalkSender.class); private final String url; private final String keyword; diff --git a/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailAlert.java b/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailAlert.java index 1192d302f5..fe0f69ed0a 100644 --- a/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailAlert.java +++ b/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailAlert.java @@ -29,11 +29,11 @@ import org.commonmark.node.Node; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; - -import freemarker.template.TemplateException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import freemarker.template.TemplateException; + /** EmailAlert */ public class EmailAlert extends AbstractAlert { private static final Logger log = LoggerFactory.getLogger(EmailAlert.class); diff --git a/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailConstants.java b/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailConstants.java index 4ce72d7adb..4437dc3533 100644 --- a/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailConstants.java +++ b/dinky-alert/dinky-alert-email/src/main/java/org/dinky/alert/email/EmailConstants.java @@ -53,7 +53,6 @@ public class EmailConstants extends AlertBaseConstant { public static final String XLS_FILE_PATH = "xls.file.path"; public static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol"; public static final String XLS_FILE_DEFAULT_PATH = "/tmp/xls"; - public static final String ALERT_TEMPLATE_TITLE = "title"; public static final String ALERT_TEMPLATE_CONTENT = "content"; } diff --git a/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuAlert.java b/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuAlert.java index 420694159c..388be27cbc 100644 --- a/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuAlert.java +++ b/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuAlert.java @@ -31,7 +31,6 @@ /** FeiShuAlert */ public class FeiShuAlert extends AbstractAlert { - private static final Logger logger = LoggerFactory.getLogger(FeiShuAlert.class); @Override diff --git a/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuConstants.java b/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuConstants.java index 2f2db5fb5b..f597131313 100644 --- a/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuConstants.java +++ b/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuConstants.java @@ -24,10 +24,8 @@ /** FeiShuConstants */ public class FeiShuConstants extends AlertBaseConstant { public static final String TYPE = "FeiShu"; - public static final String SIGN_TMESTAMP = "timestamp"; public static final String SIGN = "sign"; - public static final String ALERT_TEMPLATE_TITLE = "title"; public static final String ALERT_TEMPLATE_CONTENT = "content"; public static final String ALERT_TEMPLATE_KEYWORD = "keyword"; diff --git a/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuSender.java b/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuSender.java index b04f54883c..7c29e04dce 100644 --- a/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuSender.java +++ b/dinky-alert/dinky-alert-feishu/src/main/java/org/dinky/alert/feishu/FeiShuSender.java @@ -43,7 +43,6 @@ * fei shu sender */ public final class FeiShuSender { - private static final Logger logger = LoggerFactory.getLogger(FeiShuSender.class); private final String url; private final String secret; diff --git a/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatAlert.java b/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatAlert.java index 441b7901e4..645d6cb984 100644 --- a/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatAlert.java +++ b/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatAlert.java @@ -24,11 +24,12 @@ import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.text.StrFormatter; import freemarker.template.TemplateException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * WeChatAlert @@ -36,7 +37,6 @@ * @since 2022/2/23 21:09 */ public class WeChatAlert extends AbstractAlert { - private static final Logger logger = LoggerFactory.getLogger(WeChatAlert.class); @Override diff --git a/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatConstants.java b/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatConstants.java index e671ab4703..fbaa37267e 100644 --- a/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatConstants.java +++ b/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatConstants.java @@ -30,7 +30,6 @@ public class WeChatConstants extends AlertBaseConstant { public static final String WECHAT_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpId}&corpsecret={secret}"; - public static final String CORP_ID = "corpId"; public static final String TEAM_SEND_MSG = "teamSendMsg"; public static final String AGENT_ID = "agentId"; diff --git a/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatSender.java b/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatSender.java index 831ba9e1bf..e10f520525 100644 --- a/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatSender.java +++ b/dinky-alert/dinky-alert-wechat/src/main/java/org/dinky/alert/wechat/WeChatSender.java @@ -51,7 +51,6 @@ * @since 2022/2/23 21:11 */ public class WeChatSender { - private static final Logger logger = LoggerFactory.getLogger(WeChatSender.class); private static final String CORP_ID_REGEX = "{corpId}"; private static final String SECRET_REGEX = "{secret}";