Skip to content

Commit

Permalink
fix: alert template (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Feb 2, 2024
1 parent 93b546c commit d51d6d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlertTemplate> p = alertTemplateMapper.selectPage(page, queryWrapper);
MonitorPageResult<AlertTemplateDTO> pageResult = new MonitorPageResult<>();
Expand Down Expand Up @@ -286,8 +287,8 @@ public void doManage() {
@PostMapping("/check")
@ResponseBody
@MonitorScopeAuth(targetType = AuthTargetType.TENANT, needPower = PowerConstants.EDIT)
public JsonResult<Boolean> checkTemplateText(@RequestBody AlertTemplateDTO templateDTO) {
final JsonResult<Boolean> result = new JsonResult<>();
public JsonResult<AlertTemplateDTO> checkTemplateText(@RequestBody AlertTemplateDTO templateDTO) {
final JsonResult<AlertTemplateDTO> result = new JsonResult<>();

facadeTemplate.manage(result, new ManageCallback() {
@Override
Expand All @@ -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);
}
});

Expand Down

0 comments on commit d51d6d7

Please sign in to comment.