告警管理,告警日志接口。更改计算95值定时任务时间
This commit is contained in:
@@ -3,17 +3,43 @@ package com.ruoyi.system.api;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.domain.RmAlarmRecordRemote;
|
||||
import com.ruoyi.system.api.factory.RemoteRocketMqFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(contextId = "remoteRocketMqService", value = ServiceNameConstants.ROCKETMQ_SERVICE, fallbackFactory = RemoteRocketMqFallbackFactory.class)
|
||||
public interface RemoteRocketMqService {
|
||||
|
||||
/**
|
||||
* 发送异步消息
|
||||
* @param topic
|
||||
* @param tag
|
||||
* @param key
|
||||
* @param value
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/api/rocketMessage/sendAsyncProducerMessage")
|
||||
public R<Map> sendAsyncProducerMessage(@RequestParam("topic") String topic, @RequestParam("tag") String tag, @RequestParam("key") String key, @RequestParam("value") String value, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 查询告警记录
|
||||
*
|
||||
* @param rmAlarmRecordRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/alarmRecord/getAlarmList")
|
||||
public R<List<RmAlarmRecordRemote>> getAlarmList(@RequestBody RmAlarmRecordRemote rmAlarmRecordRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 资源告警处理情况
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/alarmRecord/alarmHandlingStatus")
|
||||
public R<Map> alarmHandlingStatus(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 告警记录对象 rm_alarm_record
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public class RmAlarmRecordRemote extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID/设备ID */
|
||||
@Excel(name = "客户端ID/设备ID")
|
||||
private String clientId;
|
||||
|
||||
/** 资源名称 */
|
||||
@Excel(name = "资源名称")
|
||||
private String resourceName;
|
||||
|
||||
/** 源IP地址 */
|
||||
@Excel(name = "源IP地址")
|
||||
private String sourceIp;
|
||||
|
||||
/** 告警发生时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "告警发生时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date occurTime;
|
||||
|
||||
/** 告警详细内容 */
|
||||
@Excel(name = "告警详细内容")
|
||||
private String content;
|
||||
|
||||
/** 重复告警次数 */
|
||||
@Excel(name = "重复告警次数")
|
||||
private Long repeatCount;
|
||||
|
||||
/** 状态:0-未处理,1-已处理 */
|
||||
@Excel(name = "状态:0-未处理,1-已处理")
|
||||
private String status;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId)
|
||||
{
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientId()
|
||||
{
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setResourceName(String resourceName)
|
||||
{
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
public String getResourceName()
|
||||
{
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
public void setSourceIp(String sourceIp)
|
||||
{
|
||||
this.sourceIp = sourceIp;
|
||||
}
|
||||
|
||||
public String getSourceIp()
|
||||
{
|
||||
return sourceIp;
|
||||
}
|
||||
|
||||
public void setOccurTime(Date occurTime)
|
||||
{
|
||||
this.occurTime = occurTime;
|
||||
}
|
||||
|
||||
public Date getOccurTime()
|
||||
{
|
||||
return occurTime;
|
||||
}
|
||||
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setRepeatCount(Long repeatCount)
|
||||
{
|
||||
this.repeatCount = repeatCount;
|
||||
}
|
||||
|
||||
public Long getRepeatCount()
|
||||
{
|
||||
return repeatCount;
|
||||
}
|
||||
|
||||
public void setStatus(String status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("clientId", getClientId())
|
||||
.append("resourceName", getResourceName())
|
||||
.append("sourceIp", getSourceIp())
|
||||
.append("occurTime", getOccurTime())
|
||||
.append("content", getContent())
|
||||
.append("repeatCount", getRepeatCount())
|
||||
.append("status", getStatus())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@ package com.ruoyi.system.api.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.RemoteRocketMqService;
|
||||
import com.ruoyi.system.api.domain.RmAlarmRecordRemote;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -33,6 +35,16 @@ public class RemoteRocketMqFallbackFactory implements FallbackFactory<RemoteRock
|
||||
errorMap.put("error", throwable.getMessage());
|
||||
return R.fail(errorMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<RmAlarmRecordRemote>> getAlarmList(RmAlarmRecordRemote rmAlarmRecordRemote, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Map> alarmHandlingStatus(String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class TableScheduleConfig {
|
||||
}
|
||||
|
||||
// 每天12点执行 计算95带宽值/日
|
||||
@Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Shanghai")
|
||||
@Scheduled(cron = "0 4 0 * * ?", zone = "Asia/Shanghai")
|
||||
public void calculate95BandwidthDaily() {
|
||||
// 获取昨天的日期范围(北京时间)
|
||||
LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1);
|
||||
@@ -66,7 +66,7 @@ public class TableScheduleConfig {
|
||||
}
|
||||
|
||||
// 每月1号0点执行 计算95带宽值/月
|
||||
@Scheduled(cron = "0 0 0 1 * ?", zone = "Asia/Shanghai")
|
||||
@Scheduled(cron = "0 3 0 1 * ?", zone = "Asia/Shanghai")
|
||||
public void calculateMonthlyBandwidthTasks() {
|
||||
// 获取上个月的日期范围
|
||||
LocalDate lastMonth = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusMonths(1);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.api.RemoteRocketMqService;
|
||||
import com.ruoyi.system.domain.RmResourceRegistration;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
|
||||
@@ -36,6 +38,8 @@ public class ScreenController extends BaseController
|
||||
private EpsInitialTrafficDataService epsInitialTrafficDataService;
|
||||
@Autowired
|
||||
private IInitialSwitchInfoDetailsService initialSwitchInfoDetailsService;
|
||||
@Autowired
|
||||
private RemoteRocketMqService remoteRocketMqService;
|
||||
|
||||
/**
|
||||
* 统计当前在线服务器的流量相关的业务数
|
||||
@@ -111,4 +115,14 @@ public class ScreenController extends BaseController
|
||||
{
|
||||
return success(initialSwitchInfoDetailsService.sumTrafficBySwitch());
|
||||
}
|
||||
/**
|
||||
* 资源告警处理情况
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/alarmProcess")
|
||||
public AjaxResult alarmProcess() {
|
||||
Map alarmList = remoteRocketMqService.alarmHandlingStatus(SecurityConstants.INNER).getData();
|
||||
return success(alarmList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
nodeData.put("resultData", EchartsDataConverter.convertToLineChart(
|
||||
nodeBandwidthList,
|
||||
bandwidthType,
|
||||
node.getBusinessName(),
|
||||
node.getNodeName(),
|
||||
epsNodeBandwidth.getStartTime(),
|
||||
epsNodeBandwidth.getEndTime(),
|
||||
timeUnit
|
||||
|
||||
@@ -189,7 +189,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
}
|
||||
|
||||
// 发送消息通知
|
||||
sendRegistrationMessage(rmResourceRegistration);
|
||||
// sendRegistrationMessage(rmResourceRegistration);
|
||||
|
||||
// 更新注册状态
|
||||
return updateRegistrationStatus(rmResourceRegistration);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class EchartsDataConverter {
|
||||
*/
|
||||
public static Map<String, Object> convertToLineChart(
|
||||
List<EpsNodeBandwidth> dataList,
|
||||
String bandwidthType, String businessName, String startTime, String endTime, ChronoUnit timeUnit
|
||||
String bandwidthType, String nodeName, String startTime, String endTime, ChronoUnit timeUnit
|
||||
) {
|
||||
// 定义时间格式化器
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(
|
||||
@@ -32,7 +32,7 @@ public class EchartsDataConverter {
|
||||
item.getCreateTime() != null &&
|
||||
item.getBandwidthResult() != null &&
|
||||
(bandwidthType == null || bandwidthType.equals(item.getBandwidthType())) &&
|
||||
(businessName == null || businessName.equals(item.getBusinessName()))
|
||||
(nodeName == null || nodeName.equals(item.getNodeName()))
|
||||
)
|
||||
.sorted(Comparator.comparing(EpsNodeBandwidth::getCreateTime))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -72,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updaterId != null "> and updater_id = #{updaterId}</if>
|
||||
<if test="updaterName != null and updaterName != ''"> and updater_name like concat('%', #{updaterName}, '%')</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectRmResourceRegistrationById" parameterType="Long" resultMap="RmResourceRegistrationResult">
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.ruoyi.rocketmq.controller;
|
||||
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmPolicy;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmPolicyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警策略Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/policy")
|
||||
public class RmAlarmPolicyController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmAlarmPolicyService rmAlarmPolicyService;
|
||||
|
||||
/**
|
||||
* 查询告警策略列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(rmAlarmPolicy.getPageNum());
|
||||
pageDomain.setPageSize(rmAlarmPolicy.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<RmAlarmPolicy> list = rmAlarmPolicyService.selectRmAlarmPolicyList(rmAlarmPolicy);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出告警策略列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:export")
|
||||
@Log(title = "告警策略", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
List<RmAlarmPolicy> list = rmAlarmPolicyService.selectRmAlarmPolicyList(rmAlarmPolicy);
|
||||
ExcelUtil<RmAlarmPolicy> util = new ExcelUtil<RmAlarmPolicy>(RmAlarmPolicy.class);
|
||||
util.exportExcel(response, list, "告警策略数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取告警策略详细信息
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmAlarmPolicyService.getRmAlarmPolicyMsgById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警策略
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:add")
|
||||
@Log(title = "告警策略", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
return toAjax(rmAlarmPolicyService.addRmAlarmPolicy(rmAlarmPolicy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警策略
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:edit")
|
||||
@Log(title = "告警策略", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
return toAjax(rmAlarmPolicyService.updateRmAlarmPolicy(rmAlarmPolicy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发告警策略
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:query")
|
||||
@GetMapping(value = "/issueAlarmPolicy")
|
||||
public AjaxResult issueAlarmPolicy(Long id)
|
||||
{
|
||||
return success(rmAlarmPolicyService.issueAlarmPolicy(id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.ruoyi.rocketmq.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRecord;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 告警记录Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/alarmRecord")
|
||||
public class RmAlarmRecordController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmAlarmRecordService rmAlarmRecordService;
|
||||
|
||||
/**
|
||||
* 查询告警记录列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:record:list")
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody RmAlarmRecord rmAlarmRecord)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(rmAlarmRecord.getPageNum());
|
||||
pageDomain.setPageSize(rmAlarmRecord.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<RmAlarmRecord> list = rmAlarmRecordService.selectRmAlarmRecordList(rmAlarmRecord);
|
||||
return getDataTable(list);
|
||||
}
|
||||
/**
|
||||
* 查询告警记录列表
|
||||
*/
|
||||
@InnerAuth
|
||||
@PostMapping("/getAlarmList")
|
||||
public R<List<RmAlarmRecord>> getAlarmList(@RequestBody RmAlarmRecord rmAlarmRecord)
|
||||
{
|
||||
List<RmAlarmRecord> list = rmAlarmRecordService.selectRmAlarmRecordList(rmAlarmRecord);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出告警记录列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:record:export")
|
||||
@Log(title = "告警记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RmAlarmRecord rmAlarmRecord)
|
||||
{
|
||||
List<RmAlarmRecord> list = rmAlarmRecordService.selectRmAlarmRecordList(rmAlarmRecord);
|
||||
ExcelUtil<RmAlarmRecord> util = new ExcelUtil<RmAlarmRecord>(RmAlarmRecord.class);
|
||||
util.exportExcel(response, list, "告警记录数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取告警记录详细信息
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:record:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmAlarmRecordService.selectRmAlarmRecordById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源告警处理情况
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/alarmHandlingStatus")
|
||||
public R<Map> alarmHandlingStatus(){
|
||||
Map alarmRecordMap = rmAlarmRecordService.alarmHandlingStatus();
|
||||
return R.ok(alarmRecordMap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.ruoyi.rocketmq.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRule;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmRuleService;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 告警规则Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/rule")
|
||||
public class RmAlarmRuleController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmAlarmRuleService rmAlarmRuleService;
|
||||
|
||||
/**
|
||||
* 查询告警规则列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:rule:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
startPage();
|
||||
List<RmAlarmRule> list = rmAlarmRuleService.selectRmAlarmRuleList(rmAlarmRule);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出告警规则列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:rule:export")
|
||||
@Log(title = "告警规则", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
List<RmAlarmRule> list = rmAlarmRuleService.selectRmAlarmRuleList(rmAlarmRule);
|
||||
ExcelUtil<RmAlarmRule> util = new ExcelUtil<RmAlarmRule>(RmAlarmRule.class);
|
||||
util.exportExcel(response, list, "告警规则数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取告警规则详细信息
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:rule:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmAlarmRuleService.selectRmAlarmRuleById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警规则
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:rule:add")
|
||||
@Log(title = "告警规则", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
return toAjax(rmAlarmRuleService.insertRmAlarmRule(rmAlarmRule));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警规则
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:rule:edit")
|
||||
@Log(title = "告警规则", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
return toAjax(rmAlarmRuleService.updateRmAlarmRule(rmAlarmRule));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警规则
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:rule:remove")
|
||||
@Log(title = "告警规则", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(rmAlarmRuleService.deleteRmAlarmRuleByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.rocketmq.controller;
|
||||
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRuleTemplate;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmRuleTemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警规则模板Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/alarmTemplate")
|
||||
public class RmAlarmRuleTemplateController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmAlarmRuleTemplateService rmAlarmRuleTemplateService;
|
||||
|
||||
/**
|
||||
* 查询告警规则模板列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:template:list")
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(@RequestBody RmAlarmRuleTemplate rmAlarmRuleTemplate)
|
||||
{
|
||||
List<RmAlarmRuleTemplate> list = rmAlarmRuleTemplateService.selectRmAlarmRuleTemplateList(rmAlarmRuleTemplate);
|
||||
return success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.ruoyi.rocketmq.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警策略对象 rm_alarm_policy
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@Data
|
||||
public class RmAlarmPolicy extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 告警策略名称 */
|
||||
@Excel(name = "告警策略名称")
|
||||
private String alarmName;
|
||||
|
||||
/** 策略描述 */
|
||||
@Excel(name = "策略描述")
|
||||
private String alarmDescription;
|
||||
|
||||
/** 关联的资源组ID */
|
||||
@Excel(name = "关联的资源组ID")
|
||||
private Long resourceGroupId;
|
||||
/** 关联资源组名称*/
|
||||
private String resourceGroupName;
|
||||
/** 包含设备 */
|
||||
private String resourceName;
|
||||
|
||||
/** 状态:0-禁用,1-启用 */
|
||||
@Excel(name = "状态:0-禁用,1-启用")
|
||||
private String status;
|
||||
|
||||
/** 策略下发时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "策略下发时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date deployTime;
|
||||
/** 告警策略内容*/
|
||||
private List<RmAlarmRule> alarmRuleList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.ruoyi.rocketmq.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 告警记录对象 rm_alarm_record
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public class RmAlarmRecord extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID/设备ID */
|
||||
@Excel(name = "客户端ID/设备ID")
|
||||
private String clientId;
|
||||
|
||||
/** 资源名称 */
|
||||
@Excel(name = "资源名称")
|
||||
private String resourceName;
|
||||
|
||||
/** 源IP地址 */
|
||||
@Excel(name = "源IP地址")
|
||||
private String sourceIp;
|
||||
|
||||
/** 告警发生时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "告警发生时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date occurTime;
|
||||
|
||||
/** 告警详细内容 */
|
||||
@Excel(name = "告警详细内容")
|
||||
private String content;
|
||||
|
||||
/** 重复告警次数 */
|
||||
@Excel(name = "重复告警次数")
|
||||
private Long repeatCount;
|
||||
|
||||
/** 状态:0-未处理,1-已处理 */
|
||||
@Excel(name = "状态:0-未处理,1-已处理")
|
||||
private String status;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId)
|
||||
{
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientId()
|
||||
{
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setResourceName(String resourceName)
|
||||
{
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
public String getResourceName()
|
||||
{
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
public void setSourceIp(String sourceIp)
|
||||
{
|
||||
this.sourceIp = sourceIp;
|
||||
}
|
||||
|
||||
public String getSourceIp()
|
||||
{
|
||||
return sourceIp;
|
||||
}
|
||||
|
||||
public void setOccurTime(Date occurTime)
|
||||
{
|
||||
this.occurTime = occurTime;
|
||||
}
|
||||
|
||||
public Date getOccurTime()
|
||||
{
|
||||
return occurTime;
|
||||
}
|
||||
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setRepeatCount(Long repeatCount)
|
||||
{
|
||||
this.repeatCount = repeatCount;
|
||||
}
|
||||
|
||||
public Long getRepeatCount()
|
||||
{
|
||||
return repeatCount;
|
||||
}
|
||||
|
||||
public void setStatus(String status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("clientId", getClientId())
|
||||
.append("resourceName", getResourceName())
|
||||
.append("sourceIp", getSourceIp())
|
||||
.append("occurTime", getOccurTime())
|
||||
.append("content", getContent())
|
||||
.append("repeatCount", getRepeatCount())
|
||||
.append("status", getStatus())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.ruoyi.rocketmq.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 告警规则对象 rm_alarm_rule
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@Data
|
||||
public class RmAlarmRule extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 关联的告警策略ID */
|
||||
@Excel(name = "关联的告警策略ID")
|
||||
private Long alarmPolicyId;
|
||||
|
||||
/** 规则名称 */
|
||||
@Excel(name = "规则名称")
|
||||
private String ruleName;
|
||||
|
||||
/** 监控指标键 */
|
||||
@Excel(name = "监控指标键")
|
||||
private String metricKey;
|
||||
|
||||
/** 比较运算符(>, <, >=, <=, =, !=) */
|
||||
@Excel(name = "比较运算符", readConverterExp = ">=,,<=,,>==,,<==,,==,,!==")
|
||||
private String operator;
|
||||
|
||||
/** 告警阈值 */
|
||||
@Excel(name = "告警阈值")
|
||||
private BigDecimal threshold;
|
||||
|
||||
/** 资源类型(linux/switch) */
|
||||
@Excel(name = "资源类型", readConverterExp = "l=inux/switch")
|
||||
private String resourceType;
|
||||
|
||||
/** 状态:0-禁用,1-启用 */
|
||||
@Excel(name = "状态:0-禁用,1-启用")
|
||||
private String status;
|
||||
|
||||
/** 端口白名单 */
|
||||
@Excel(name = "端口白名单")
|
||||
private String portWhitelist;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.ruoyi.rocketmq.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 告警规则模板对象 rm_alarm_rule_template
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public class RmAlarmRuleTemplate extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 规则名称 */
|
||||
@Excel(name = "规则名称")
|
||||
private String ruleName;
|
||||
|
||||
/** 监控指标键 */
|
||||
@Excel(name = "监控指标键")
|
||||
private String metricKey;
|
||||
|
||||
/** 资源类型(linux/switch) */
|
||||
@Excel(name = "资源类型", readConverterExp = "l=inux/switch")
|
||||
private String resourceType;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setRuleName(String ruleName)
|
||||
{
|
||||
this.ruleName = ruleName;
|
||||
}
|
||||
|
||||
public String getRuleName()
|
||||
{
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
public void setMetricKey(String metricKey)
|
||||
{
|
||||
this.metricKey = metricKey;
|
||||
}
|
||||
|
||||
public String getMetricKey()
|
||||
{
|
||||
return metricKey;
|
||||
}
|
||||
|
||||
public void setResourceType(String resourceType)
|
||||
{
|
||||
this.resourceType = resourceType;
|
||||
}
|
||||
|
||||
public String getResourceType()
|
||||
{
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("ruleName", getRuleName())
|
||||
.append("metricKey", getMetricKey())
|
||||
.append("resourceType", getResourceType())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.rocketmq.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class AlarmVo {
|
||||
/** 规则类型 */
|
||||
private String type;
|
||||
/** 是否开启 */
|
||||
private boolean collect = false;
|
||||
/** 比较运算符 */
|
||||
private String operator;
|
||||
/** 阈值 */
|
||||
private BigDecimal threshold;
|
||||
/** 是否启用 */
|
||||
private String status;
|
||||
/** 端口白名单 */
|
||||
private String portWhitelist;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.rocketmq.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmPolicy;
|
||||
|
||||
/**
|
||||
* 告警策略Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface RmAlarmPolicyMapper
|
||||
{
|
||||
/**
|
||||
* 查询告警策略
|
||||
*
|
||||
* @param id 告警策略主键
|
||||
* @return 告警策略
|
||||
*/
|
||||
public RmAlarmPolicy selectRmAlarmPolicyById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警策略列表
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 告警策略集合
|
||||
*/
|
||||
public List<RmAlarmPolicy> selectRmAlarmPolicyList(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
/**
|
||||
* 新增告警策略
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
/**
|
||||
* 修改告警策略
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
/**
|
||||
* 删除告警策略
|
||||
*
|
||||
* @param id 告警策略主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPolicyById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除告警策略
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPolicyByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.rocketmq.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRecord;
|
||||
|
||||
/**
|
||||
* 告警记录Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface RmAlarmRecordMapper
|
||||
{
|
||||
/**
|
||||
* 查询告警记录
|
||||
*
|
||||
* @param id 告警记录主键
|
||||
* @return 告警记录
|
||||
*/
|
||||
public RmAlarmRecord selectRmAlarmRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警记录列表
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 告警记录集合
|
||||
*/
|
||||
public List<RmAlarmRecord> selectRmAlarmRecordList(RmAlarmRecord rmAlarmRecord);
|
||||
|
||||
/**
|
||||
* 新增告警记录
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmRecord(RmAlarmRecord rmAlarmRecord);
|
||||
|
||||
/**
|
||||
* 修改告警记录
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmRecord(RmAlarmRecord rmAlarmRecord);
|
||||
|
||||
/**
|
||||
* 删除告警记录
|
||||
*
|
||||
* @param id 告警记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除告警记录
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRecordByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.ruoyi.rocketmq.mapper;
|
||||
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRule;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警规则Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface RmAlarmRuleMapper
|
||||
{
|
||||
/**
|
||||
* 查询告警规则
|
||||
*
|
||||
* @param id 告警规则主键
|
||||
* @return 告警规则
|
||||
*/
|
||||
public RmAlarmRule selectRmAlarmRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警规则列表
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 告警规则集合
|
||||
*/
|
||||
public List<RmAlarmRule> selectRmAlarmRuleList(RmAlarmRule rmAlarmRule);
|
||||
|
||||
/**
|
||||
* 新增告警规则
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmRule(RmAlarmRule rmAlarmRule);
|
||||
|
||||
/**
|
||||
* 修改告警规则
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmRule(RmAlarmRule rmAlarmRule);
|
||||
|
||||
/**
|
||||
* 删除告警规则
|
||||
*
|
||||
* @param id 告警规则主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除告警规则
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根绝告警策略id删除告警规则信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public int deleteRmAlarmRuleByPolicyId(Long id);
|
||||
|
||||
/**
|
||||
* 批量插入告警规则
|
||||
* @param alarmRuleList
|
||||
*/
|
||||
void batchInsertRmAlarmRule(@Param("list") List<RmAlarmRule> alarmRuleList);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.rocketmq.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRuleTemplate;
|
||||
|
||||
/**
|
||||
* 告警规则模板Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface RmAlarmRuleTemplateMapper
|
||||
{
|
||||
/**
|
||||
* 查询告警规则模板
|
||||
*
|
||||
* @param id 告警规则模板主键
|
||||
* @return 告警规则模板
|
||||
*/
|
||||
public RmAlarmRuleTemplate selectRmAlarmRuleTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警规则模板列表
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 告警规则模板集合
|
||||
*/
|
||||
public List<RmAlarmRuleTemplate> selectRmAlarmRuleTemplateList(RmAlarmRuleTemplate rmAlarmRuleTemplate);
|
||||
|
||||
/**
|
||||
* 新增告警规则模板
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmRuleTemplate(RmAlarmRuleTemplate rmAlarmRuleTemplate);
|
||||
|
||||
/**
|
||||
* 修改告警规则模板
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmRuleTemplate(RmAlarmRuleTemplate rmAlarmRuleTemplate);
|
||||
|
||||
/**
|
||||
* 删除告警规则模板
|
||||
*
|
||||
* @param id 告警规则模板主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除告警规则模板
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleTemplateByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.ruoyi.rocketmq.service;
|
||||
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmPolicy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 告警策略Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface IRmAlarmPolicyService
|
||||
{
|
||||
/**
|
||||
* 查询告警策略
|
||||
*
|
||||
* @param id 告警策略主键
|
||||
* @return 告警策略
|
||||
*/
|
||||
public RmAlarmPolicy selectRmAlarmPolicyById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警策略列表
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 告警策略集合
|
||||
*/
|
||||
public List<RmAlarmPolicy> selectRmAlarmPolicyList(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
/**
|
||||
* 新增告警策略
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
/**
|
||||
* 修改告警策略
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
/**
|
||||
* 批量删除告警策略
|
||||
*
|
||||
* @param ids 需要删除的告警策略主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPolicyByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除告警策略信息
|
||||
*
|
||||
* @param id 告警策略主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPolicyById(Long id);
|
||||
|
||||
Map getRmAlarmPolicyMsgById(Long id);
|
||||
|
||||
int addRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy);
|
||||
|
||||
int issueAlarmPolicy(Long id);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ruoyi.rocketmq.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRecord;
|
||||
|
||||
/**
|
||||
* 告警记录Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface IRmAlarmRecordService
|
||||
{
|
||||
/**
|
||||
* 查询告警记录
|
||||
*
|
||||
* @param id 告警记录主键
|
||||
* @return 告警记录
|
||||
*/
|
||||
public RmAlarmRecord selectRmAlarmRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警记录列表
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 告警记录集合
|
||||
*/
|
||||
public List<RmAlarmRecord> selectRmAlarmRecordList(RmAlarmRecord rmAlarmRecord);
|
||||
|
||||
/**
|
||||
* 新增告警记录
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmRecord(RmAlarmRecord rmAlarmRecord);
|
||||
|
||||
/**
|
||||
* 修改告警记录
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmRecord(RmAlarmRecord rmAlarmRecord);
|
||||
|
||||
/**
|
||||
* 批量删除告警记录
|
||||
*
|
||||
* @param ids 需要删除的告警记录主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRecordByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除告警记录信息
|
||||
*
|
||||
* @param id 告警记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRecordById(Long id);
|
||||
|
||||
Map alarmHandlingStatus();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.rocketmq.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRule;
|
||||
|
||||
/**
|
||||
* 告警规则Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface IRmAlarmRuleService
|
||||
{
|
||||
/**
|
||||
* 查询告警规则
|
||||
*
|
||||
* @param id 告警规则主键
|
||||
* @return 告警规则
|
||||
*/
|
||||
public RmAlarmRule selectRmAlarmRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警规则列表
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 告警规则集合
|
||||
*/
|
||||
public List<RmAlarmRule> selectRmAlarmRuleList(RmAlarmRule rmAlarmRule);
|
||||
|
||||
/**
|
||||
* 新增告警规则
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmRule(RmAlarmRule rmAlarmRule);
|
||||
|
||||
/**
|
||||
* 修改告警规则
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmRule(RmAlarmRule rmAlarmRule);
|
||||
|
||||
/**
|
||||
* 批量删除告警规则
|
||||
*
|
||||
* @param ids 需要删除的告警规则主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除告警规则信息
|
||||
*
|
||||
* @param id 告警规则主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.rocketmq.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRuleTemplate;
|
||||
|
||||
/**
|
||||
* 告警规则模板Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
public interface IRmAlarmRuleTemplateService
|
||||
{
|
||||
/**
|
||||
* 查询告警规则模板
|
||||
*
|
||||
* @param id 告警规则模板主键
|
||||
* @return 告警规则模板
|
||||
*/
|
||||
public RmAlarmRuleTemplate selectRmAlarmRuleTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警规则模板列表
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 告警规则模板集合
|
||||
*/
|
||||
public List<RmAlarmRuleTemplate> selectRmAlarmRuleTemplateList(RmAlarmRuleTemplate rmAlarmRuleTemplate);
|
||||
|
||||
/**
|
||||
* 新增告警规则模板
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmRuleTemplate(RmAlarmRuleTemplate rmAlarmRuleTemplate);
|
||||
|
||||
/**
|
||||
* 修改告警规则模板
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmRuleTemplate(RmAlarmRuleTemplate rmAlarmRuleTemplate);
|
||||
|
||||
/**
|
||||
* 批量删除告警规则模板
|
||||
*
|
||||
* @param ids 需要删除的告警规则模板主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleTemplateByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除告警规则模板信息
|
||||
*
|
||||
* @param id 告警规则模板主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmRuleTemplateById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.rocketmq.domain.DeviceMessage;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmPolicy;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRule;
|
||||
import com.ruoyi.rocketmq.domain.vo.AlarmVo;
|
||||
import com.ruoyi.rocketmq.mapper.RmAlarmPolicyMapper;
|
||||
import com.ruoyi.rocketmq.mapper.RmAlarmRuleMapper;
|
||||
import com.ruoyi.rocketmq.model.ProducerMode;
|
||||
import com.ruoyi.rocketmq.producer.MessageProducer;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmPolicyService;
|
||||
import com.ruoyi.rocketmq.utils.DataProcessUtil;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 告警策略Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RmAlarmPolicyServiceImpl implements IRmAlarmPolicyService
|
||||
{
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
@Autowired
|
||||
private RmAlarmPolicyMapper rmAlarmPolicyMapper;
|
||||
@Autowired
|
||||
private RemoteRevenueConfigService remoteRevenueConfigService;
|
||||
@Autowired
|
||||
private RmAlarmRuleMapper rmAlarmRuleMapper;
|
||||
|
||||
/**
|
||||
* 查询告警策略
|
||||
*
|
||||
* @param id 告警策略主键
|
||||
* @return 告警策略
|
||||
*/
|
||||
@Override
|
||||
public RmAlarmPolicy selectRmAlarmPolicyById(Long id)
|
||||
{
|
||||
return rmAlarmPolicyMapper.selectRmAlarmPolicyById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警策略列表
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 告警策略
|
||||
*/
|
||||
@Override
|
||||
public List<RmAlarmPolicy> selectRmAlarmPolicyList(RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
List<RmAlarmPolicy> list = rmAlarmPolicyMapper.selectRmAlarmPolicyList(rmAlarmPolicy);
|
||||
for (RmAlarmPolicy alarmPolicy : list) {
|
||||
// 资源组名称
|
||||
alarmPolicy.setResourceGroupName(DataProcessUtil.getResourceGroupNameById(alarmPolicy.getResourceGroupId()));
|
||||
// 包含设备
|
||||
alarmPolicy.setResourceName(DataProcessUtil.getResourceMsgById(alarmPolicy.getResourceGroupId()).getIncludedDevicesName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警策略
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
rmAlarmPolicy.setCreateTime(DateUtils.getNowDate());
|
||||
return rmAlarmPolicyMapper.insertRmAlarmPolicy(rmAlarmPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警策略
|
||||
*
|
||||
* @param rmAlarmPolicy 告警策略
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy)
|
||||
{
|
||||
rmAlarmPolicy.setUpdateTime(DateUtils.getNowDate());
|
||||
rmAlarmPolicy.setStatus("0");
|
||||
rmAlarmPolicyMapper.updateRmAlarmPolicy(rmAlarmPolicy);
|
||||
// 删除已有信息
|
||||
rmAlarmRuleMapper.deleteRmAlarmRuleByPolicyId(rmAlarmPolicy.getId());
|
||||
// 新增告警规则信息
|
||||
for (RmAlarmRule alarmRule : rmAlarmPolicy.getAlarmRuleList()) {
|
||||
alarmRule.setAlarmPolicyId(rmAlarmPolicy.getId());
|
||||
}
|
||||
rmAlarmRuleMapper.batchInsertRmAlarmRule(rmAlarmPolicy.getAlarmRuleList());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除告警策略
|
||||
*
|
||||
* @param ids 需要删除的告警策略主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmPolicyByIds(Long[] ids)
|
||||
{
|
||||
return rmAlarmPolicyMapper.deleteRmAlarmPolicyByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警策略信息
|
||||
*
|
||||
* @param id 告警策略主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmPolicyById(Long id)
|
||||
{
|
||||
return rmAlarmPolicyMapper.deleteRmAlarmPolicyById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警管理详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map getRmAlarmPolicyMsgById(Long id) {
|
||||
Map map = new HashMap();
|
||||
// 告警策略基础信息
|
||||
RmAlarmPolicy alarmPolicy = rmAlarmPolicyMapper.selectRmAlarmPolicyById(id);
|
||||
alarmPolicy.setResourceGroupName(DataProcessUtil.getResourceGroupNameById(alarmPolicy.getResourceGroupId()));
|
||||
map.put("alarmPolicy", alarmPolicy);
|
||||
// 策略内容
|
||||
RmAlarmRule alarmRule = new RmAlarmRule();
|
||||
alarmRule.setAlarmPolicyId(id);
|
||||
List<RmAlarmRule> ruleList = rmAlarmRuleMapper.selectRmAlarmRuleList(alarmRule);
|
||||
List<RmAlarmRule> linuxRuleList = ruleList.stream().filter(
|
||||
rule -> "linux".equals(rule.getResourceType())
|
||||
).collect(Collectors.toList());
|
||||
List<RmAlarmRule> switchRuleList = ruleList.stream().filter(
|
||||
rule -> "switch".equals(rule.getResourceType())
|
||||
).collect(Collectors.toList());
|
||||
map.put("linuxRule", linuxRuleList);
|
||||
map.put("switchRule", switchRuleList);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警策略
|
||||
* @param rmAlarmPolicy
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int addRmAlarmPolicy(RmAlarmPolicy rmAlarmPolicy) {
|
||||
// 基础信息
|
||||
rmAlarmPolicyMapper.insertRmAlarmPolicy(rmAlarmPolicy);
|
||||
// linux/switch信息
|
||||
rmAlarmRuleMapper.batchInsertRmAlarmRule(rmAlarmPolicy.getAlarmRuleList());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发告警策略
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int issueAlarmPolicy(Long id) {
|
||||
RmAlarmPolicy rmAlarmPolicy = rmAlarmPolicyMapper.selectRmAlarmPolicyById(id);
|
||||
if (rmAlarmPolicy == null) {
|
||||
log.error("策略不存在,id: {}", id);
|
||||
return 0;
|
||||
}
|
||||
// 资源信息
|
||||
List<RmResourceRegistrationRemote> devices = DataProcessUtil.getResourceDevices(rmAlarmPolicy.getResourceGroupId());
|
||||
// 告警规则信息
|
||||
Map<String,Object> alarmPolicyMsg = getRmAlarmPolicyMsgById(id);
|
||||
// 构建消息内容
|
||||
List<AlarmVo> alarmVos = buildAlarmConfigurations(alarmPolicyMsg);
|
||||
// 发送消息
|
||||
sendConfigurationsToDevices(devices, alarmVos);
|
||||
// 更新告警策略状态为已下发
|
||||
RmAlarmPolicy alarmPolicy = new RmAlarmPolicy();
|
||||
alarmPolicy.setId(id);
|
||||
alarmPolicy.setStatus("1");
|
||||
rmAlarmPolicyMapper.updateRmAlarmPolicy(alarmPolicy);
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* 构建采集配置
|
||||
*/
|
||||
private List<AlarmVo> buildAlarmConfigurations(Map<String, Object> alarmPolicyDetails) {
|
||||
List<AlarmVo> alarmVos = new ArrayList<>();
|
||||
// 拿到告警规则信息
|
||||
List<RmAlarmRule> linuxRule = (List<RmAlarmRule>) alarmPolicyDetails.get("linuxRule");
|
||||
for (RmAlarmRule alarmRule : linuxRule) {
|
||||
AlarmVo alarmVo = new AlarmVo();
|
||||
alarmVo.setType(alarmRule.getMetricKey());
|
||||
alarmVo.setCollect(true);
|
||||
alarmVo.setOperator(alarmRule.getOperator());
|
||||
alarmVo.setThreshold(alarmRule.getThreshold());
|
||||
alarmVo.setStatus(alarmRule.getStatus());
|
||||
alarmVo.setPortWhitelist(alarmRule.getPortWhitelist());
|
||||
}
|
||||
return alarmVos;
|
||||
}
|
||||
/**
|
||||
* 发送配置到设备
|
||||
*/
|
||||
private void sendConfigurationsToDevices(List<RmResourceRegistrationRemote> devices, List<AlarmVo> alarmVos) {
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
Map map = new HashMap();
|
||||
map.put("alarmRules", alarmVos);
|
||||
String configJson = JSONObject.toJSONString(map);
|
||||
|
||||
for (RmResourceRegistrationRemote device : devices) {
|
||||
try {
|
||||
DeviceMessage message = new DeviceMessage();
|
||||
message.setClientId(device.getHardwareSn());
|
||||
message.setData(configJson);
|
||||
message.setDataType("SYSTEM_COLLECT_START");
|
||||
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
producerMode.getAgentTopic(),
|
||||
"",
|
||||
"",
|
||||
JSONObject.toJSONString(message)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("发送设备配置失败,deviceId: {}", device.getHardwareSn(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRecord;
|
||||
import com.ruoyi.rocketmq.mapper.RmAlarmRecordMapper;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 告警记录Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@Service
|
||||
public class RmAlarmRecordServiceImpl implements IRmAlarmRecordService
|
||||
{
|
||||
@Autowired
|
||||
private RmAlarmRecordMapper rmAlarmRecordMapper;
|
||||
|
||||
/**
|
||||
* 查询告警记录
|
||||
*
|
||||
* @param id 告警记录主键
|
||||
* @return 告警记录
|
||||
*/
|
||||
@Override
|
||||
public RmAlarmRecord selectRmAlarmRecordById(Long id)
|
||||
{
|
||||
return rmAlarmRecordMapper.selectRmAlarmRecordById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警记录列表
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 告警记录
|
||||
*/
|
||||
@Override
|
||||
public List<RmAlarmRecord> selectRmAlarmRecordList(RmAlarmRecord rmAlarmRecord)
|
||||
{
|
||||
return rmAlarmRecordMapper.selectRmAlarmRecordList(rmAlarmRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警记录
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmAlarmRecord(RmAlarmRecord rmAlarmRecord)
|
||||
{
|
||||
rmAlarmRecord.setCreateTime(DateUtils.getNowDate());
|
||||
return rmAlarmRecordMapper.insertRmAlarmRecord(rmAlarmRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警记录
|
||||
*
|
||||
* @param rmAlarmRecord 告警记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmAlarmRecord(RmAlarmRecord rmAlarmRecord)
|
||||
{
|
||||
rmAlarmRecord.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmAlarmRecordMapper.updateRmAlarmRecord(rmAlarmRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除告警记录
|
||||
*
|
||||
* @param ids 需要删除的告警记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmRecordByIds(Long[] ids)
|
||||
{
|
||||
return rmAlarmRecordMapper.deleteRmAlarmRecordByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警记录信息
|
||||
*
|
||||
* @param id 告警记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmRecordById(Long id)
|
||||
{
|
||||
return rmAlarmRecordMapper.deleteRmAlarmRecordById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源告警处理情况
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map alarmHandlingStatus() {
|
||||
// 1. 获取告警列表
|
||||
RmAlarmRecord rmAlarmRecord = new RmAlarmRecord();
|
||||
List<RmAlarmRecord> alarmList = rmAlarmRecordMapper.selectRmAlarmRecordList(rmAlarmRecord);
|
||||
|
||||
// 2. 计算统计数据
|
||||
BigDecimal total = BigDecimal.valueOf(alarmList.size());
|
||||
long processAlarmCount = alarmList.stream().filter(alarm -> "1".equals(alarm.getStatus())).count();
|
||||
long noProcessAlarmCount = alarmList.stream().filter(alarm -> "0".equals(alarm.getStatus())).count();
|
||||
|
||||
// 3. 计算处理率(安全处理除零情况)
|
||||
BigDecimal processAlarmRate = total.compareTo(BigDecimal.ZERO) == 0
|
||||
? BigDecimal.ZERO
|
||||
: BigDecimal.valueOf(processAlarmCount)
|
||||
.divide(total, 2, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal(100));
|
||||
|
||||
// 4. 构建返回结果
|
||||
Map<String, Object> result = new HashMap<>(4);
|
||||
result.put("total", total);
|
||||
result.put("processAlarmCount", processAlarmCount);
|
||||
result.put("noProcessAlarmCount", noProcessAlarmCount);
|
||||
result.put("processAlarmRate", processAlarmRate);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.rocketmq.mapper.RmAlarmRuleMapper;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRule;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmRuleService;
|
||||
|
||||
/**
|
||||
* 告警规则Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@Service
|
||||
public class RmAlarmRuleServiceImpl implements IRmAlarmRuleService
|
||||
{
|
||||
@Autowired
|
||||
private RmAlarmRuleMapper rmAlarmRuleMapper;
|
||||
|
||||
/**
|
||||
* 查询告警规则
|
||||
*
|
||||
* @param id 告警规则主键
|
||||
* @return 告警规则
|
||||
*/
|
||||
@Override
|
||||
public RmAlarmRule selectRmAlarmRuleById(Long id)
|
||||
{
|
||||
return rmAlarmRuleMapper.selectRmAlarmRuleById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警规则列表
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 告警规则
|
||||
*/
|
||||
@Override
|
||||
public List<RmAlarmRule> selectRmAlarmRuleList(RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
return rmAlarmRuleMapper.selectRmAlarmRuleList(rmAlarmRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警规则
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmAlarmRule(RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
rmAlarmRule.setCreateTime(DateUtils.getNowDate());
|
||||
return rmAlarmRuleMapper.insertRmAlarmRule(rmAlarmRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警规则
|
||||
*
|
||||
* @param rmAlarmRule 告警规则
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmAlarmRule(RmAlarmRule rmAlarmRule)
|
||||
{
|
||||
rmAlarmRule.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmAlarmRuleMapper.updateRmAlarmRule(rmAlarmRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除告警规则
|
||||
*
|
||||
* @param ids 需要删除的告警规则主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmRuleByIds(Long[] ids)
|
||||
{
|
||||
return rmAlarmRuleMapper.deleteRmAlarmRuleByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警规则信息
|
||||
*
|
||||
* @param id 告警规则主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmRuleById(Long id)
|
||||
{
|
||||
return rmAlarmRuleMapper.deleteRmAlarmRuleById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.rocketmq.mapper.RmAlarmRuleTemplateMapper;
|
||||
import com.ruoyi.rocketmq.domain.RmAlarmRuleTemplate;
|
||||
import com.ruoyi.rocketmq.service.IRmAlarmRuleTemplateService;
|
||||
|
||||
/**
|
||||
* 告警规则模板Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-12
|
||||
*/
|
||||
@Service
|
||||
public class RmAlarmRuleTemplateServiceImpl implements IRmAlarmRuleTemplateService
|
||||
{
|
||||
@Autowired
|
||||
private RmAlarmRuleTemplateMapper rmAlarmRuleTemplateMapper;
|
||||
|
||||
/**
|
||||
* 查询告警规则模板
|
||||
*
|
||||
* @param id 告警规则模板主键
|
||||
* @return 告警规则模板
|
||||
*/
|
||||
@Override
|
||||
public RmAlarmRuleTemplate selectRmAlarmRuleTemplateById(Long id)
|
||||
{
|
||||
return rmAlarmRuleTemplateMapper.selectRmAlarmRuleTemplateById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警规则模板列表
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 告警规则模板
|
||||
*/
|
||||
@Override
|
||||
public List<RmAlarmRuleTemplate> selectRmAlarmRuleTemplateList(RmAlarmRuleTemplate rmAlarmRuleTemplate)
|
||||
{
|
||||
return rmAlarmRuleTemplateMapper.selectRmAlarmRuleTemplateList(rmAlarmRuleTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警规则模板
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmAlarmRuleTemplate(RmAlarmRuleTemplate rmAlarmRuleTemplate)
|
||||
{
|
||||
rmAlarmRuleTemplate.setCreateTime(DateUtils.getNowDate());
|
||||
return rmAlarmRuleTemplateMapper.insertRmAlarmRuleTemplate(rmAlarmRuleTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警规则模板
|
||||
*
|
||||
* @param rmAlarmRuleTemplate 告警规则模板
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmAlarmRuleTemplate(RmAlarmRuleTemplate rmAlarmRuleTemplate)
|
||||
{
|
||||
rmAlarmRuleTemplate.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmAlarmRuleTemplateMapper.updateRmAlarmRuleTemplate(rmAlarmRuleTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除告警规则模板
|
||||
*
|
||||
* @param ids 需要删除的告警规则模板主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmRuleTemplateByIds(Long[] ids)
|
||||
{
|
||||
return rmAlarmRuleTemplateMapper.deleteRmAlarmRuleTemplateByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警规则模板信息
|
||||
*
|
||||
* @param id 告警规则模板主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmRuleTemplateById(Long id)
|
||||
{
|
||||
return rmAlarmRuleTemplateMapper.deleteRmAlarmRuleTemplateById(id);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.rocketmq.domain.*;
|
||||
import com.ruoyi.rocketmq.domain.vo.CollectVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.RmMonitorPolicyVo;
|
||||
@@ -15,15 +12,18 @@ import com.ruoyi.rocketmq.model.ProducerMode;
|
||||
import com.ruoyi.rocketmq.producer.MessageProducer;
|
||||
import com.ruoyi.rocketmq.service.IRmMonitorPolicyService;
|
||||
import com.ruoyi.rocketmq.utils.DataProcessUtil;
|
||||
import com.ruoyi.rocketmq.utils.FieldNameConverterUtil;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.RmResourceGroupRemote;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 资源监控策略Service业务层处理
|
||||
@@ -35,6 +35,8 @@ import java.util.*;
|
||||
@Slf4j
|
||||
public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
{
|
||||
// 对应rocketmq键
|
||||
public static final String COLLECT_SUFFIX = "Collect";
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
@Autowired
|
||||
@@ -186,7 +188,7 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<RmResourceRegistrationRemote> devices = getResourceDevices(policy.getResourceGroupId());
|
||||
List<RmResourceRegistrationRemote> devices = DataProcessUtil.getResourceDevices(policy.getResourceGroupId());
|
||||
if (CollectionUtils.isEmpty(devices)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -208,25 +210,6 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源设备列表
|
||||
*/
|
||||
private List<RmResourceRegistrationRemote> getResourceDevices(Long resourceGroupId) {
|
||||
R<RmResourceGroupRemote> groupResponse = remoteRevenueConfigService
|
||||
.getResourceGroupMsgById(resourceGroupId, SecurityConstants.INNER);
|
||||
|
||||
if (groupResponse == null || groupResponse.getData() == null
|
||||
|| StringUtils.isEmpty(groupResponse.getData().getIncludedDevicesId())) {
|
||||
log.error("资源组信息不完整,resourceGroupId: {}", resourceGroupId);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String[] deviceIds = groupResponse.getData().getIncludedDevicesId().split(",");
|
||||
R<List<RmResourceRegistrationRemote>> devicesResponse = remoteRevenueConfigService
|
||||
.getRegistrationByIds(deviceIds, SecurityConstants.INNER);
|
||||
|
||||
return devicesResponse != null ? devicesResponse.getData() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建采集配置
|
||||
@@ -237,13 +220,13 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
// 处理Linux配置
|
||||
if (policyDetails.containsKey("linux")) {
|
||||
Map<String, List<RmTemplateLinux>> linuxConfigs = (Map<String, List<RmTemplateLinux>>) policyDetails.get("linux");
|
||||
processConfigurations(linuxConfigs, collectVos, new String[]{"cpu", "other", "point", "net", "disk", "docker"});
|
||||
processConfigurations(linuxConfigs, collectVos, new String[]{"cpu", "other", "vfs", "net", "disk", "docker"});
|
||||
}
|
||||
|
||||
// 处理Switch配置
|
||||
if (policyDetails.containsKey("switch")) {
|
||||
Map<String, List<RmTemplateSwitch>> switchConfigs = (Map<String, List<RmTemplateSwitch>>) policyDetails.get("switch");
|
||||
processConfigurations(switchConfigs, collectVos, new String[]{"system", "mpu", "power", "netport", "lightmodule", "fan"});
|
||||
processConfigurations(switchConfigs, collectVos, new String[]{"switchOther", "switchMpu", "switchPwr", "switchNet", "switchModule", "switchFan"});
|
||||
}
|
||||
|
||||
return collectVos;
|
||||
@@ -261,11 +244,19 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
|
||||
if (config instanceof RmTemplateLinux) {
|
||||
RmTemplateLinux linuxConfig = (RmTemplateLinux) config;
|
||||
vo.setType(linuxConfig.getMetricKey());
|
||||
if("other".equals(type)){
|
||||
vo.setType(FieldNameConverterUtil.convertToJavaProperty(linuxConfig.getMetricKey()));
|
||||
}else{
|
||||
vo.setType(type + COLLECT_SUFFIX);
|
||||
}
|
||||
vo.setInterval(linuxConfig.getCollectionCycle());
|
||||
} else if (config instanceof RmTemplateSwitch) {
|
||||
RmTemplateSwitch switchConfig = (RmTemplateSwitch) config;
|
||||
vo.setType(switchConfig.getMetricKey());
|
||||
if("switchOther".equals(type)){
|
||||
vo.setType(FieldNameConverterUtil.convertToJavaProperty(switchConfig.getMetricKey()));
|
||||
}else{
|
||||
vo.setType(type + COLLECT_SUFFIX);
|
||||
}
|
||||
vo.setInterval(switchConfig.getCollectionCycle());
|
||||
}
|
||||
|
||||
@@ -280,19 +271,21 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
*/
|
||||
private void sendConfigurationsToDevices(List<RmResourceRegistrationRemote> devices, List<CollectVo> collectVos) {
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
String configJson = JSONObject.toJSONString(collectVos);
|
||||
Map map = new HashMap();
|
||||
map.put("collects", collectVos);
|
||||
String configJson = JSONObject.toJSONString(map);
|
||||
|
||||
for (RmResourceRegistrationRemote device : devices) {
|
||||
try {
|
||||
DeviceMessage message = new DeviceMessage();
|
||||
message.setClientId(device.getHardwareSn());
|
||||
message.setData(configJson);
|
||||
message.setDataType("collects");
|
||||
message.setDataType("SYSTEM_COLLECT_START");
|
||||
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
producerMode.getAgentTopic(),
|
||||
"collects",
|
||||
"title",
|
||||
"",
|
||||
"",
|
||||
JSONObject.toJSONString(message)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.rocketmq.utils;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.rocketmq.domain.RmTemplateLinux;
|
||||
import com.ruoyi.rocketmq.domain.RmTemplateSwitch;
|
||||
import com.ruoyi.rocketmq.mapper.RmMonitorTemplateMapper;
|
||||
@@ -9,10 +10,12 @@ import com.ruoyi.rocketmq.mapper.RmTemplateLinuxMapper;
|
||||
import com.ruoyi.rocketmq.mapper.RmTemplateSwitchMapper;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.RmResourceGroupRemote;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -44,6 +47,22 @@ public class DataProcessUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 资源组信息
|
||||
*/
|
||||
public static RmResourceGroupRemote getResourceMsgById(Long resourceGroupId) {
|
||||
try {
|
||||
R<RmResourceGroupRemote> resourceGroupResponse = remoteRevenueConfigService
|
||||
.getResourceGroupMsgById(resourceGroupId, SecurityConstants.INNER);
|
||||
|
||||
if (resourceGroupResponse != null && resourceGroupResponse.getData() != null) {
|
||||
return resourceGroupResponse.getData();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取资源信息失败,resourceGroupId: {}", resourceGroupId, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 处理Linux模板数据
|
||||
*/
|
||||
@@ -56,7 +75,7 @@ public class DataProcessUtil {
|
||||
Map<String, List<RmTemplateLinux>> linuxData = new HashMap<>();
|
||||
linuxData.put("cpu", filterItemsByDataType(linuxItems, "CPU"));
|
||||
linuxData.put("other", filterItemsByDataType(linuxItems, "OTHER"));
|
||||
linuxData.put("point", filterItemsByDataType(linuxItems, "POINT"));
|
||||
linuxData.put("vfs", filterItemsByDataType(linuxItems, "POINT"));
|
||||
linuxData.put("net", filterItemsByDataType(linuxItems, "NET"));
|
||||
linuxData.put("disk", filterItemsByDataType(linuxItems, "DISK"));
|
||||
linuxData.put("docker", filterItemsByDataType(linuxItems, "DOCKER"));
|
||||
@@ -75,12 +94,12 @@ public class DataProcessUtil {
|
||||
|
||||
if (!switchItems.isEmpty()) {
|
||||
Map<String, List<RmTemplateSwitch>> switchData = new HashMap<>();
|
||||
switchData.put("system", filterItemsByDataType(switchItems, "SYSTEM"));
|
||||
switchData.put("mpu", filterItemsByDataType(switchItems, "MPU"));
|
||||
switchData.put("power", filterItemsByDataType(switchItems, "POWERSOURCE"));
|
||||
switchData.put("netport", filterItemsByDataType(switchItems, "NETPORT"));
|
||||
switchData.put("lightmodule", filterItemsByDataType(switchItems, "LIGHTMODULE"));
|
||||
switchData.put("fan", filterItemsByDataType(switchItems, "FAN"));
|
||||
switchData.put("switchOther", filterItemsByDataType(switchItems, "SYSTEM"));
|
||||
switchData.put("switchMpu", filterItemsByDataType(switchItems, "MPU"));
|
||||
switchData.put("switchPwr", filterItemsByDataType(switchItems, "POWERSOURCE"));
|
||||
switchData.put("switchNet", filterItemsByDataType(switchItems, "NETPORT"));
|
||||
switchData.put("switchModule", filterItemsByDataType(switchItems, "LIGHTMODULE"));
|
||||
switchData.put("switchFan", filterItemsByDataType(switchItems, "FAN"));
|
||||
|
||||
result.put("switch", switchData);
|
||||
}
|
||||
@@ -101,4 +120,23 @@ public class DataProcessUtil {
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 获取资源设备列表
|
||||
*/
|
||||
public static List<RmResourceRegistrationRemote> getResourceDevices(Long resourceGroupId) {
|
||||
R<RmResourceGroupRemote> groupResponse = remoteRevenueConfigService
|
||||
.getResourceGroupMsgById(resourceGroupId, SecurityConstants.INNER);
|
||||
|
||||
if (groupResponse == null || groupResponse.getData() == null
|
||||
|| StringUtils.isEmpty(groupResponse.getData().getIncludedDevicesId())) {
|
||||
log.error("资源组信息不完整,resourceGroupId: {}", resourceGroupId);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String[] deviceIds = groupResponse.getData().getIncludedDevicesId().split(",");
|
||||
R<List<RmResourceRegistrationRemote>> devicesResponse = remoteRevenueConfigService
|
||||
.getRegistrationByIds(deviceIds, SecurityConstants.INNER);
|
||||
|
||||
return devicesResponse != null ? devicesResponse.getData() : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.ruoyi.rocketmq.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 数据库字段名转换工具类
|
||||
*/
|
||||
public class FieldNameConverterUtil {
|
||||
|
||||
/**
|
||||
* 将数据库字段名转换为Java属性名(带Collect后缀)
|
||||
* 示例:system.swap.size.free -> systemSwapSizeFreeCollect
|
||||
*
|
||||
* @param dbFieldName 数据库字段名
|
||||
* @return Java属性名
|
||||
*/
|
||||
public static String convertToJavaProperty(String dbFieldName) {
|
||||
return convertToJavaProperty(dbFieldName, "Collect");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据库字段名转换为Java属性名(自定义后缀)
|
||||
* 示例:system.swap.size.free + "Config" -> systemSwapSizeFreeConfig
|
||||
*
|
||||
* @param dbFieldName 数据库字段名
|
||||
* @param suffix 自定义后缀
|
||||
* @return Java属性名
|
||||
*/
|
||||
public static String convertToJavaProperty(String dbFieldName, String suffix) {
|
||||
if (StringUtils.isBlank(dbFieldName)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 分割字段名
|
||||
String[] parts = dbFieldName.split("\\.");
|
||||
|
||||
// 处理每个部分
|
||||
StringBuilder result = new StringBuilder(parts[0]);
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
result.append(StringUtils.capitalize(parts[i]));
|
||||
}
|
||||
|
||||
// 添加后缀
|
||||
if (StringUtils.isNotBlank(suffix)) {
|
||||
result.append(suffix);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Java属性名转换回数据库字段名
|
||||
* 示例:systemSwapSizeFreeCollect -> system.swap.size.free
|
||||
*
|
||||
* @param javaProperty Java属性名
|
||||
* @param suffix 需要去除的后缀
|
||||
* @return 数据库字段名
|
||||
*/
|
||||
public static String convertToDbField(String javaProperty, String suffix) {
|
||||
if (StringUtils.isBlank(javaProperty)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 去除后缀
|
||||
String withoutSuffix = StringUtils.isNotBlank(suffix)
|
||||
? StringUtils.removeEnd(javaProperty, suffix)
|
||||
: javaProperty;
|
||||
|
||||
// 使用正则表达式在大小写字母之间插入点号
|
||||
return withoutSuffix.replaceAll("(?<=[a-z])(?=[A-Z])", ".")
|
||||
.toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.rocketmq.mapper.RmAlarmPolicyMapper">
|
||||
|
||||
<resultMap type="RmAlarmPolicy" id="RmAlarmPolicyResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="alarmName" column="alarm_name" />
|
||||
<result property="alarmDescription" column="alarm_description" />
|
||||
<result property="resourceGroupId" column="resource_group_id" />
|
||||
<result property="status" column="status" />
|
||||
<result property="deployTime" column="deploy_time" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAlarmPolicyVo">
|
||||
select id, alarm_name, alarm_description, resource_group_id, status, deploy_time, create_time, update_time, create_by, update_by from rm_alarm_policy
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAlarmPolicyList" parameterType="RmAlarmPolicy" resultMap="RmAlarmPolicyResult">
|
||||
<include refid="selectRmAlarmPolicyVo"/>
|
||||
<where>
|
||||
<if test="alarmName != null and alarmName != ''"> and alarm_name like concat('%', #{alarmName}, '%')</if>
|
||||
<if test="alarmDescription != null and alarmDescription != ''"> and alarm_description = #{alarmDescription}</if>
|
||||
<if test="resourceGroupId != null "> and resource_group_id = #{resourceGroupId}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="deployTime != null "> and deploy_time = #{deployTime}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmAlarmPolicyById" parameterType="Long" resultMap="RmAlarmPolicyResult">
|
||||
<include refid="selectRmAlarmPolicyVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAlarmPolicy" parameterType="RmAlarmPolicy" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_alarm_policy
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="alarmName != null and alarmName != ''">alarm_name,</if>
|
||||
<if test="alarmDescription != null">alarm_description,</if>
|
||||
<if test="resourceGroupId != null">resource_group_id,</if>
|
||||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="deployTime != null">deploy_time,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="alarmName != null and alarmName != ''">#{alarmName},</if>
|
||||
<if test="alarmDescription != null">#{alarmDescription},</if>
|
||||
<if test="resourceGroupId != null">#{resourceGroupId},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="deployTime != null">#{deployTime},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAlarmPolicy" parameterType="RmAlarmPolicy">
|
||||
update rm_alarm_policy
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="alarmName != null and alarmName != ''">alarm_name = #{alarmName},</if>
|
||||
<if test="alarmDescription != null">alarm_description = #{alarmDescription},</if>
|
||||
<if test="resourceGroupId != null">resource_group_id = #{resourceGroupId},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="deployTime != null">deploy_time = #{deployTime},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAlarmPolicyById" parameterType="Long">
|
||||
delete from rm_alarm_policy where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAlarmPolicyByIds" parameterType="String">
|
||||
delete from rm_alarm_policy where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.rocketmq.mapper.RmAlarmRecordMapper">
|
||||
|
||||
<resultMap type="RmAlarmRecord" id="RmAlarmRecordResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="resourceName" column="resource_name" />
|
||||
<result property="sourceIp" column="source_ip" />
|
||||
<result property="occurTime" column="occur_time" />
|
||||
<result property="content" column="content" />
|
||||
<result property="repeatCount" column="repeat_count" />
|
||||
<result property="status" column="status" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAlarmRecordVo">
|
||||
select id, client_id, resource_name, source_ip, occur_time, content, repeat_count, status, create_time, update_time, create_by, update_by from rm_alarm_record
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAlarmRecordList" parameterType="RmAlarmRecord" resultMap="RmAlarmRecordResult">
|
||||
<include refid="selectRmAlarmRecordVo"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="resourceName != null and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
|
||||
<if test="sourceIp != null and sourceIp != ''"> and source_ip = #{sourceIp}</if>
|
||||
<if test="occurTime != null "> and occur_time = #{occurTime}</if>
|
||||
<if test="content != null and content != ''"> and content = #{content}</if>
|
||||
<if test="repeatCount != null "> and repeat_count = #{repeatCount}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmAlarmRecordById" parameterType="Long" resultMap="RmAlarmRecordResult">
|
||||
<include refid="selectRmAlarmRecordVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAlarmRecord" parameterType="RmAlarmRecord" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_alarm_record
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">client_id,</if>
|
||||
<if test="resourceName != null and resourceName != ''">resource_name,</if>
|
||||
<if test="sourceIp != null and sourceIp != ''">source_ip,</if>
|
||||
<if test="occurTime != null">occur_time,</if>
|
||||
<if test="content != null and content != ''">content,</if>
|
||||
<if test="repeatCount != null">repeat_count,</if>
|
||||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">#{clientId},</if>
|
||||
<if test="resourceName != null and resourceName != ''">#{resourceName},</if>
|
||||
<if test="sourceIp != null and sourceIp != ''">#{sourceIp},</if>
|
||||
<if test="occurTime != null">#{occurTime},</if>
|
||||
<if test="content != null and content != ''">#{content},</if>
|
||||
<if test="repeatCount != null">#{repeatCount},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAlarmRecord" parameterType="RmAlarmRecord">
|
||||
update rm_alarm_record
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
|
||||
<if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
|
||||
<if test="sourceIp != null and sourceIp != ''">source_ip = #{sourceIp},</if>
|
||||
<if test="occurTime != null">occur_time = #{occurTime},</if>
|
||||
<if test="content != null and content != ''">content = #{content},</if>
|
||||
<if test="repeatCount != null">repeat_count = #{repeatCount},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAlarmRecordById" parameterType="Long">
|
||||
delete from rm_alarm_record where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAlarmRecordByIds" parameterType="String">
|
||||
delete from rm_alarm_record where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.rocketmq.mapper.RmAlarmRuleMapper">
|
||||
|
||||
<resultMap type="RmAlarmRule" id="RmAlarmRuleResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="alarmPolicyId" column="alarm_policy_id" />
|
||||
<result property="ruleName" column="rule_name" />
|
||||
<result property="metricKey" column="metric_key" />
|
||||
<result property="operator" column="operator" />
|
||||
<result property="threshold" column="threshold" />
|
||||
<result property="resourceType" column="resource_type" />
|
||||
<result property="status" column="status" />
|
||||
<result property="portWhitelist" column="port_whitelist" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAlarmRuleVo">
|
||||
select id, alarm_policy_id, rule_name, metric_key, operator, threshold, resource_type, status, port_whitelist, create_time, update_time, create_by, update_by from rm_alarm_rule
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAlarmRuleList" parameterType="RmAlarmRule" resultMap="RmAlarmRuleResult">
|
||||
<include refid="selectRmAlarmRuleVo"/>
|
||||
<where>
|
||||
<if test="alarmPolicyId != null "> and alarm_policy_id = #{alarmPolicyId}</if>
|
||||
<if test="ruleName != null and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
|
||||
<if test="metricKey != null and metricKey != ''"> and metric_key = #{metricKey}</if>
|
||||
<if test="operator != null and operator != ''"> and operator = #{operator}</if>
|
||||
<if test="threshold != null "> and threshold = #{threshold}</if>
|
||||
<if test="resourceType != null and resourceType != ''"> and resource_type = #{resourceType}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="portWhitelist != null and portWhitelist != ''"> and port_whitelist = #{portWhitelist}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmAlarmRuleById" parameterType="Long" resultMap="RmAlarmRuleResult">
|
||||
<include refid="selectRmAlarmRuleVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAlarmRule" parameterType="RmAlarmRule" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_alarm_rule
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="alarmPolicyId != null">alarm_policy_id,</if>
|
||||
<if test="ruleName != null">rule_name,</if>
|
||||
<if test="metricKey != null">metric_key,</if>
|
||||
<if test="operator != null">operator,</if>
|
||||
<if test="threshold != null">threshold,</if>
|
||||
<if test="resourceType != null">resource_type,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="portWhitelist != null">port_whitelist,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="alarmPolicyId != null">#{alarmPolicyId},</if>
|
||||
<if test="ruleName != null">#{ruleName},</if>
|
||||
<if test="metricKey != null">#{metricKey},</if>
|
||||
<if test="operator != null">#{operator},</if>
|
||||
<if test="threshold != null">#{threshold},</if>
|
||||
<if test="resourceType != null">#{resourceType},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="portWhitelist != null">#{portWhitelist},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAlarmRule" parameterType="RmAlarmRule">
|
||||
update rm_alarm_rule
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="alarmPolicyId != null">alarm_policy_id = #{alarmPolicyId},</if>
|
||||
<if test="ruleName != null">rule_name = #{ruleName},</if>
|
||||
<if test="metricKey != null">metric_key = #{metricKey},</if>
|
||||
<if test="operator != null">operator = #{operator},</if>
|
||||
<if test="threshold != null">threshold = #{threshold},</if>
|
||||
<if test="resourceType != null">resource_type = #{resourceType},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="portWhitelist != null">port_whitelist = #{portWhitelist},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAlarmRuleById" parameterType="Long">
|
||||
delete from rm_alarm_rule where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAlarmRuleByIds" parameterType="String">
|
||||
delete from rm_alarm_rule where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteRmAlarmRuleByPolicyId" parameterType="Long">
|
||||
delete from rm_alarm_rule where alarm_policy_id #{id}
|
||||
</delete>
|
||||
<!-- 批量插入告警规则 -->
|
||||
<insert id="batchInsertRmAlarmRule" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO rm_alarm_rule
|
||||
(
|
||||
alarm_policy_id,
|
||||
rule_name,
|
||||
metric_key,
|
||||
operator,
|
||||
threshold,
|
||||
resource_type,
|
||||
status,
|
||||
port_whitelist,
|
||||
create_time,
|
||||
update_time,
|
||||
create_by,
|
||||
update_by
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.alarmPolicyId},
|
||||
#{item.ruleName},
|
||||
#{item.metricKey},
|
||||
#{item.operator},
|
||||
#{item.threshold},
|
||||
#{item.resourceType},
|
||||
#{item.status},
|
||||
#{item.portWhitelist},
|
||||
#{item.createTime},
|
||||
#{item.updateTime},
|
||||
#{item.createBy},
|
||||
#{item.updateBy}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.rocketmq.mapper.RmAlarmRuleTemplateMapper">
|
||||
|
||||
<resultMap type="RmAlarmRuleTemplate" id="RmAlarmRuleTemplateResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="ruleName" column="rule_name" />
|
||||
<result property="metricKey" column="metric_key" />
|
||||
<result property="resourceType" column="resource_type" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAlarmRuleTemplateVo">
|
||||
select id, rule_name, metric_key, resource_type, create_time, update_time, create_by, update_by from rm_alarm_rule_template
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAlarmRuleTemplateList" parameterType="RmAlarmRuleTemplate" resultMap="RmAlarmRuleTemplateResult">
|
||||
<include refid="selectRmAlarmRuleTemplateVo"/>
|
||||
<where>
|
||||
<if test="ruleName != null and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
|
||||
<if test="metricKey != null and metricKey != ''"> and metric_key = #{metricKey}</if>
|
||||
<if test="resourceType != null and resourceType != ''"> and resource_type = #{resourceType}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmAlarmRuleTemplateById" parameterType="Long" resultMap="RmAlarmRuleTemplateResult">
|
||||
<include refid="selectRmAlarmRuleTemplateVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAlarmRuleTemplate" parameterType="RmAlarmRuleTemplate" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_alarm_rule_template
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="ruleName != null">rule_name,</if>
|
||||
<if test="metricKey != null">metric_key,</if>
|
||||
<if test="resourceType != null">resource_type,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="ruleName != null">#{ruleName},</if>
|
||||
<if test="metricKey != null">#{metricKey},</if>
|
||||
<if test="resourceType != null">#{resourceType},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAlarmRuleTemplate" parameterType="RmAlarmRuleTemplate">
|
||||
update rm_alarm_rule_template
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="ruleName != null">rule_name = #{ruleName},</if>
|
||||
<if test="metricKey != null">metric_key = #{metricKey},</if>
|
||||
<if test="resourceType != null">resource_type = #{resourceType},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAlarmRuleTemplateById" parameterType="Long">
|
||||
delete from rm_alarm_rule_template where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAlarmRuleTemplateByIds" parameterType="String">
|
||||
delete from rm_alarm_rule_template where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user