Skip to content

Commit

Permalink
fix: use uuid in alertTemplate (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Jan 30, 2024
1 parent 52f68c8 commit c2d1f51
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 391 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/

-- ----------------------------
-- Table structure for alert_template
-- ----------------------------
CREATE TABLE `alert_template` (
`uuid` varchar(100) NOT NULL comment '主键',
`gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
`gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
`template_name` varchar(255) NULL comment '模板名称',
`description` varchar(255) DEFAULT NULL COMMENT '模板描述信息',
`scene_type` varchar(255) NULL comment '场景类型:server、miniapp、iot',
`be_default` tinyint(4) NULL comment '是否为默认模板',
`channel_type` varchar(255) NULL comment '发送渠道:dingtalk、sms',
`template_config` mediumtext NULL comment '模板配置',
`tenant` varchar(255) NULL comment '租户',
`workspace` varchar(255) NULL comment '工作空间',
`creator` varchar(255) NULL comment '创建者',
`modifier` varchar(255) NULL comment '修改者',
PRIMARY KEY(`uuid`)
) DEFAULT CHARSET = utf8mb4 COMMENT = '告警模板';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/

-- ----------------------------
-- Table structure for user_oplog
-- ----------------------------
ALTER TABLE `user_oplog`
ADD COLUMN `table_entity_uuid` varchar(100) DEFAULT NULL COMMENT 'Oplog relate table unique uuid';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/

-- ----------------------------
-- Table structure for alarm_rule
-- ----------------------------
ALTER TABLE `alarm_rule`
ADD COLUMN `alert_template_uuid` varchar(100) NULL DEFAULT NULL comment '告警模板UUID';
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import io.holoinsight.server.home.biz.plugin.model.PluginContext;
import io.holoinsight.server.home.biz.service.IntegrationPluginService;
import io.holoinsight.server.home.dal.converter.AlarmRuleConverter;
import io.holoinsight.server.home.dal.converter.AlertNotificationTemplateConverter;
import io.holoinsight.server.home.dal.converter.AlertTemplateConverter;
import io.holoinsight.server.home.dal.mapper.AlarmRuleMapper;
import io.holoinsight.server.home.dal.mapper.AlertNotificationTemplateMapper;
import io.holoinsight.server.home.dal.mapper.AlertTemplateMapper;
import io.holoinsight.server.home.dal.model.AlarmRule;
import io.holoinsight.server.home.dal.model.AlertNotificationTemplate;
import io.holoinsight.server.home.dal.model.AlertTemplate;
import io.holoinsight.server.home.dal.model.dto.IntegrationPluginDTO;
import io.holoinsight.server.home.facade.AlarmRuleDTO;
import io.holoinsight.server.home.facade.AlertNotificationTemplateDTO;
import io.holoinsight.server.home.facade.AlertTemplateDTO;
import io.holoinsight.server.home.facade.AlertNotifyRecordDTO;
import io.holoinsight.server.home.facade.AlertRuleExtra;
import io.holoinsight.server.home.facade.NotificationTemplate;
Expand Down Expand Up @@ -65,9 +65,9 @@ public abstract class GatewayService {
@Resource
private AlarmRuleConverter alarmRuleConverter;
@Resource
private AlertNotificationTemplateMapper alertNotificationTemplateMapper;
private AlertTemplateMapper alertTemplateMapper;
@Autowired
private AlertNotificationTemplateConverter alertNotificationTemplateConverter;
private AlertTemplateConverter alertTemplateConverter;

private static final String GATEWAY = "GatewayService";

Expand Down Expand Up @@ -130,11 +130,10 @@ public boolean sendAlertNotifyV3(AlertNotifyRequest notify, AlertNotifyRecordLat
if (notificationTemplate == null) {
Long alertNotificationTemplateId = alertRule.getAlertNotificationTemplateId();
if (alertNotificationTemplateId != null) {
AlertNotificationTemplate alertNotificationTemplate =
this.alertNotificationTemplateMapper.selectById(alertNotificationTemplateId);
if (alertNotificationTemplate != null) {
AlertNotificationTemplateDTO templateDTO =
this.alertNotificationTemplateConverter.doToDTO(alertNotificationTemplate);
AlertTemplate alertTemplate =
this.alertTemplateMapper.selectById(alertNotificationTemplateId);
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 @@ -5,8 +5,8 @@

import io.holoinsight.server.common.J;
import io.holoinsight.server.common.dao.transformer.MapJsonMapper;
import io.holoinsight.server.home.dal.model.AlertNotificationTemplate;
import io.holoinsight.server.home.facade.AlertNotificationTemplateDTO;
import io.holoinsight.server.home.dal.model.AlertTemplate;
import io.holoinsight.server.home.facade.AlertTemplateDTO;
import io.holoinsight.server.home.facade.NotificationTemplate;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
Expand All @@ -18,13 +18,13 @@
* @version 2024-01-22 17:03:00
*/
@Mapper(componentModel = "spring", uses = {MapJsonMapper.class})
public interface AlertNotificationTemplateConverter {
public interface AlertTemplateConverter {

AlertNotificationTemplateDTO doToDTO(AlertNotificationTemplate template);
AlertTemplateDTO doToDTO(AlertTemplate template);

AlertNotificationTemplate dtoToDO(AlertNotificationTemplateDTO templateDTO);
AlertTemplate dtoToDO(AlertTemplateDTO templateDTO);

List<AlertNotificationTemplateDTO> dosToDTOs(Iterable<AlertNotificationTemplate> templates);
List<AlertTemplateDTO> dosToDTOs(Iterable<AlertTemplate> templates);

default String map(NotificationTemplate value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package io.holoinsight.server.home.dal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.holoinsight.server.home.dal.model.AlertNotificationTemplate;
import io.holoinsight.server.home.dal.model.AlertTemplate;

/**
* @author masaimu
* @version 2024-01-22 16:56:00
*/
public interface AlertNotificationTemplateMapper extends BaseMapper<AlertNotificationTemplate> {
public interface AlertTemplateMapper extends BaseMapper<AlertTemplate> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,7 @@ public class AlarmRule {
@Column(name = "alert_notification_template_id")
private Long alertNotificationTemplateId;

@Column(name = "alert_template_uuid")
private String alertTemplateUuid;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
* @version 2024-01-22 16:48:00
*/
@Data
@Table(name = "alert_notification_template")
public class AlertNotificationTemplate {
@Table(name = "alert_template")
public class AlertTemplate {

/**
* id
*/
@TableId(type = IdType.AUTO)
public Long id;
@TableId(type = IdType.INPUT)
public String uuid;

/**
* 创建时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class UserOpLog {
@Column(name = "table_entity_id")
public Long tableEntityId;

@Column(name = "table_entity_uuid")
public String tableEntityUuid;

public String opType;

public String opBeforeContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ public class AlarmRuleDTO extends ApiSecurity {
*/
private String pql;

private Long alertNotificationTemplateId;

/**
* 告警模板ID
* 告警模板UUID
*/
private Long alertNotificationTemplateId;
private String alertTemplateUuid;

public static void tryParseLink(AlarmRuleDTO alarmRuleDTO, String domain,
Map<String /* metric */, Map<String /* type */, String /* page */>> systemMetrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
* @version 2024-01-22 17:02:00
*/
@Data
public class AlertNotificationTemplateDTO {
/**
* id
*/
public Long id;
public class AlertTemplateDTO {

public String uuid;

/**
* 创建时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ public interface UserOpLogService extends IService<UserOpLog> {

UserOpLog append(String tableName, Long tableEntityId, String opType, String user, String tenant,
String workspace, String before, String after, String relate, String name);

UserOpLog append(String tableName, String tableEntityUuid, String opType, String user,
String tenant, String workspace, String before, String after, String relate, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,24 @@ public UserOpLog append(String tableName, Long tableEntityId, String opType, Str
return opLog;
}

@Override
public UserOpLog append(String tableName, String tableEntityUuid, String opType, String user,
String tenant, String workspace, String before, String after, String relate, String name) {
UserOpLog opLog = new UserOpLog();
opLog.setTableName(tableName);
opLog.setTableEntityUuid(tableEntityUuid);
opLog.setOpType(opType);
opLog.setCreator(user);
opLog.setTenant(tenant);
opLog.setWorkspace(workspace);
opLog.setGmtCreate(new Date());
opLog.setGmtCreate(new Date());
opLog.setOpBeforeContext(before);
opLog.setOpAfterContext(after);
opLog.setName(name);
opLog.setRelate(relate);
save(opLog);
EventBusHolder.post(opLog);
return opLog;
}
}
Loading

0 comments on commit c2d1f51

Please sign in to comment.