From 4fd534240bed42ef9247bd83d7a603112326770a Mon Sep 17 00:00:00 2001 From: "saimu.msm" Date: Fri, 2 Feb 2024 14:24:39 +0800 Subject: [PATCH] fix alert template --- .../home/alert/plugin/GatewayService.java | 6 +++--- .../controller/AlertTemplateFacadeImpl.java | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java index d9e631005..0abe5747b 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java @@ -128,10 +128,10 @@ public boolean sendAlertNotifyV3(AlertNotifyRequest notify, AlertNotifyRecordLat notify.setAlertRuleExtra(extra); NotificationTemplate notificationTemplate = extra == null ? null : extra.getDingTalkTemplate(); if (notificationTemplate == null) { - Long alertNotificationTemplateId = alertRule.getAlertNotificationTemplateId(); - if (alertNotificationTemplateId != null) { + String alertRuleAlertTemplateUuid = alertRule.getAlertTemplateUuid(); + if (StringUtils.isNotEmpty(alertRuleAlertTemplateUuid)) { AlertTemplate alertTemplate = - this.alertTemplateMapper.selectById(alertNotificationTemplateId); + this.alertTemplateMapper.selectById(alertRuleAlertTemplateUuid); if (alertTemplate != null) { AlertTemplateDTO templateDTO = this.alertTemplateConverter.doToDTO(alertTemplate); notificationTemplate = templateDTO.templateConfig; diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/AlertTemplateFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/AlertTemplateFacadeImpl.java index d85daba9e..4ea6841c5 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/AlertTemplateFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/AlertTemplateFacadeImpl.java @@ -243,6 +243,7 @@ public void doManage() { if (StringUtils.isNotBlank(pageRequest.getTarget().templateName)) { queryWrapper.like("template_name", pageRequest.getTarget().templateName); } + queryWrapper.orderByDesc("gmt_modified"); Page p = alertTemplateMapper.selectPage(page, queryWrapper); MonitorPageResult pageResult = new MonitorPageResult<>(); @@ -286,8 +287,8 @@ public void doManage() { @PostMapping("/check") @ResponseBody @MonitorScopeAuth(targetType = AuthTargetType.TENANT, needPower = PowerConstants.EDIT) - public JsonResult checkTemplateText(@RequestBody AlertTemplateDTO templateDTO) { - final JsonResult result = new JsonResult<>(); + public JsonResult checkTemplateText(@RequestBody AlertTemplateDTO templateDTO) { + final JsonResult result = new JsonResult<>(); facadeTemplate.manage(result, new ManageCallback() { @Override @@ -297,12 +298,19 @@ public void checkParameter() { @Override public void doManage() { - if (templateDTO.templateConfig == null - || StringUtils.isEmpty(templateDTO.templateConfig.text)) { - JsonResult.createSuccessResult(result, false); + NotificationTemplate template = templateDTO.getTemplateConfig(); + if (template == null) { + result.setMessage("templateConfig is null"); return; } - JsonResult.createSuccessResult(result, templateDTO.templateConfig.parseText()); + + if (StringUtils.isNotEmpty(template.text)) { + result.setSuccess(template.parseText()); + } else if (!CollectionUtils.isEmpty(template.fieldMap)) { + template.text = template.getTemplateJson(); + result.setSuccess(true); + } + result.setData(templateDTO); } });