feat: 新增告警导出接口
This commit is contained in:
@@ -764,5 +764,17 @@ INSERT INTO "sys_i18n" VALUES (702, 'dictData.cdr_sip_code.480', '被叫挂断
|
|||||||
INSERT INTO "sys_i18n" VALUES (703, 'dictData.cdr_sip_code.481', '其他', 'Other');
|
INSERT INTO "sys_i18n" VALUES (703, 'dictData.cdr_sip_code.481', '其他', 'Other');
|
||||||
INSERT INTO "sys_i18n" VALUES (704, 'dictData.cdr_sip_code.482', '发现环路', 'Loop Detected');
|
INSERT INTO "sys_i18n" VALUES (704, 'dictData.cdr_sip_code.482', '发现环路', 'Loop Detected');
|
||||||
INSERT INTO "sys_i18n" VALUES (705, 'dictData.cdr_sip_code.486', '被叫忙', 'Busy');
|
INSERT INTO "sys_i18n" VALUES (705, 'dictData.cdr_sip_code.486', '被叫忙', 'Busy');
|
||||||
INSERT INTO "sys_i18n" VALUES (705, 'dictData.cdr_sip_code.489', '其他', 'Other');
|
INSERT INTO "sys_i18n" VALUES (706, 'dictData.cdr_sip_code.489', '其他', 'Other');
|
||||||
INSERT INTO "sys_i18n" VALUES (706, 'dictData.cdr_sip_code.580', '其他', 'Other');
|
INSERT INTO "sys_i18n" VALUES (707, 'dictData.cdr_sip_code.580', '其他', 'Other');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (708, 'alarm.export.alarmType', '告警类型', 'Alarm Type');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (709, 'alarm.export.origSeverity', '告警级别', 'Severity');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (710, 'alarm.export.alarmTitle', '告警标题', 'Alarm Title');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (711, 'alarm.export.eventTime', '告警产生时间', 'Event Time');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (712, 'alarm.export.alarmId', '告警唯一标识', 'Alarm ID');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (713, 'alarm.export.clearUser', '告警清除用户', 'Clear User');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (714, 'alarm.export.clearType', '告警清除类型', 'Clear Type');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (715, 'alarm.export.clearTime', '告警清除时间', 'Clear Time');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (716, 'log.operate.title.alarm', '告警', 'Alarm');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (717, 'ne.common.neType', '网元类型', 'NE Type');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (718, 'ne.common.neName', '网元名称', 'NE Name');
|
||||||
|
INSERT INTO "sys_i18n" VALUES (719, 'ne.common.neId', '网元标识', 'NE ID');
|
||||||
|
|||||||
@@ -720,7 +720,19 @@ INSERT INTO `sys_i18n` VALUES (702, 'dictData.cdr_sip_code.480', '被叫挂断
|
|||||||
INSERT INTO `sys_i18n` VALUES (703, 'dictData.cdr_sip_code.481', '其他', 'Other');
|
INSERT INTO `sys_i18n` VALUES (703, 'dictData.cdr_sip_code.481', '其他', 'Other');
|
||||||
INSERT INTO `sys_i18n` VALUES (704, 'dictData.cdr_sip_code.482', '发现环路', 'Loop Detected');
|
INSERT INTO `sys_i18n` VALUES (704, 'dictData.cdr_sip_code.482', '发现环路', 'Loop Detected');
|
||||||
INSERT INTO `sys_i18n` VALUES (705, 'dictData.cdr_sip_code.486', '被叫忙', 'Busy');
|
INSERT INTO `sys_i18n` VALUES (705, 'dictData.cdr_sip_code.486', '被叫忙', 'Busy');
|
||||||
INSERT INTO `sys_i18n` VALUES (705, 'dictData.cdr_sip_code.489', '其他', 'Other');
|
INSERT INTO `sys_i18n` VALUES (706, 'dictData.cdr_sip_code.489', '其他', 'Other');
|
||||||
INSERT INTO `sys_i18n` VALUES (706, 'dictData.cdr_sip_code.580', '其他', 'Other');
|
INSERT INTO `sys_i18n` VALUES (707, 'dictData.cdr_sip_code.580', '其他', 'Other');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (708, 'alarm.export.alarmType', '告警类型', 'Alarm Type');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (709, 'alarm.export.origSeverity', '告警级别', 'Severity');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (710, 'alarm.export.alarmTitle', '告警标题', 'Alarm Title');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (711, 'alarm.export.eventTime', '告警产生时间', 'Event Time');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (712, 'alarm.export.alarmId', '告警唯一标识', 'Alarm ID');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (713, 'alarm.export.clearUser', '告警清除用户', 'Clear User');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (714, 'alarm.export.clearType', '告警清除类型', 'Clear Type');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (715, 'alarm.export.clearTime', '告警清除时间', 'Clear Time');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (716, 'log.operate.title.alarm', '告警', 'Alarm');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (717, 'ne.common.neType', '网元类型', 'NE Type');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (718, 'ne.common.neName', '网元名称', 'NE Name');
|
||||||
|
INSERT INTO `sys_i18n` VALUES (719, 'ne.common.neId', '网元标识', 'NE ID');
|
||||||
|
|
||||||
-- Dump completed on 2025-02-14 15:26:56
|
-- Dump completed on 2025-02-14 15:26:56
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"be.ems/src/framework/i18n"
|
"be.ems/src/framework/i18n"
|
||||||
"be.ems/src/framework/reqctx"
|
"be.ems/src/framework/reqctx"
|
||||||
@@ -136,3 +137,60 @@ func (s AlarmController) Ack(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
c.JSON(200, resp.OkData(rows))
|
c.JSON(200, resp.OkData(rows))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 告警列表导出
|
||||||
|
//
|
||||||
|
// GET /export
|
||||||
|
//
|
||||||
|
// @Tags network_data/alarm
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||||
|
// @Param neId query string false "NE ID The actual record is the network element RmUid"
|
||||||
|
// @Param neName query string false "NE Name"
|
||||||
|
// @Param pvFlag query string false "PV Flag" Enums(PNF,VNF)
|
||||||
|
// @Param alarmCode query string false "alarm status code"
|
||||||
|
// @Param alarmType query string false "Alarm type Communication alarms=1, Equipment alarms=2, Processing faults=3, Environmental alarms=4, Quality of service alarms=5" Enums(1,2,3,4,5)
|
||||||
|
// @Param alarmStatus query string false "Alarm status 0:clear, 1:active" Enums(0,1)
|
||||||
|
// @Param origSeverity query string false "Alarm Type 1: Critical, 2: Major, 3: Minor, 4: Warning" Enums(1,2,3,4)
|
||||||
|
// @Param sortField query string false "Sort fields, fill in result fields" default(event_time)
|
||||||
|
// @Param sortOrder query string false "Sort by ascending or descending order, asc desc" default(asc)
|
||||||
|
// @Param pageNum query number true "pageNum" default(1)
|
||||||
|
// @Param pageSize query number true "pageSize" default(10)
|
||||||
|
// @Success 200 {object} object "Response Results"
|
||||||
|
// @Security TokenAuth
|
||||||
|
// @Summary Alarm List Export
|
||||||
|
// @Description Alarm List Export
|
||||||
|
// @Router /neData/alarm/export [get]
|
||||||
|
func (s AlarmController) Export(c *gin.Context) {
|
||||||
|
language := reqctx.AcceptLanguage(c)
|
||||||
|
// 查询结果,根据查询条件结果,单页最大值限制
|
||||||
|
var query model.AlarmQuery
|
||||||
|
if err := c.ShouldBindQuery(&query); err != nil {
|
||||||
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||||
|
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 限制导出数据集
|
||||||
|
if query.PageSize > 10000 {
|
||||||
|
query.PageSize = 10000
|
||||||
|
}
|
||||||
|
// 查询数据
|
||||||
|
rows, total := s.alarmService.FindByPage(query)
|
||||||
|
if total == 0 {
|
||||||
|
// 导出数据记录为空
|
||||||
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出文件名称
|
||||||
|
fileName := fmt.Sprintf("alarm_export_%d_%s_%d.xlsx", len(rows), query.AlarmStatus, time.Now().UnixMilli())
|
||||||
|
// 导出数据表格
|
||||||
|
saveFilePath, err := s.alarmService.ExportXlsx(rows, fileName, language, query.AlarmStatus)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.FileAttachment(saveFilePath, fileName)
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,12 +46,19 @@ func Setup(router *gin.Engine) {
|
|||||||
)
|
)
|
||||||
alarmGroup.PUT("/clear",
|
alarmGroup.PUT("/clear",
|
||||||
middleware.PreAuthorize(nil),
|
middleware.PreAuthorize(nil),
|
||||||
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.alarm", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||||
controller.NewAlarm.Clear,
|
controller.NewAlarm.Clear,
|
||||||
)
|
)
|
||||||
alarmGroup.PUT("/ack",
|
alarmGroup.PUT("/ack",
|
||||||
middleware.PreAuthorize(nil),
|
middleware.PreAuthorize(nil),
|
||||||
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.alarm", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||||
controller.NewAlarm.Ack,
|
controller.NewAlarm.Ack,
|
||||||
)
|
)
|
||||||
|
alarmGroup.GET("/export",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.alarm", collectlogs.BUSINESS_TYPE_EXPORT)),
|
||||||
|
controller.NewAlarm.Export,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 告警日志数据信息
|
// 告警日志数据信息
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"be.ems/src/framework/constants"
|
"be.ems/src/framework/constants"
|
||||||
|
"be.ems/src/framework/i18n"
|
||||||
|
"be.ems/src/framework/utils/date"
|
||||||
|
"be.ems/src/framework/utils/file"
|
||||||
"be.ems/src/modules/network_data/model"
|
"be.ems/src/modules/network_data/model"
|
||||||
"be.ems/src/modules/network_data/repository"
|
"be.ems/src/modules/network_data/repository"
|
||||||
|
sysService "be.ems/src/modules/system/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 实例化数据层 Alarm 结构体
|
// 实例化数据层 Alarm 结构体
|
||||||
@@ -114,3 +119,83 @@ func (r Alarm) AlarmAckByIds(ids []int64, ackUser string, ackState bool) (int64,
|
|||||||
// 清除失败!
|
// 清除失败!
|
||||||
return 0, fmt.Errorf("ack fail")
|
return 0, fmt.Errorf("ack fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExportXlsx 导出数据到 xlsx 文件
|
||||||
|
func (r Alarm) ExportXlsx(rows []model.Alarm, fileName, language, alarmStatus string) (string, error) {
|
||||||
|
// 第一行表头标题
|
||||||
|
headerCells := map[string]string{
|
||||||
|
"A1": i18n.TKey(language, "alarm.export.alarmType"),
|
||||||
|
"B1": i18n.TKey(language, "alarm.export.origSeverity"),
|
||||||
|
"C1": i18n.TKey(language, "alarm.export.alarmTitle"),
|
||||||
|
"D1": i18n.TKey(language, "alarm.export.eventTime"),
|
||||||
|
"E1": i18n.TKey(language, "alarm.export.alarmId"),
|
||||||
|
"F1": i18n.TKey(language, "alarm.export.alarmCode"),
|
||||||
|
"G1": i18n.TKey(language, "ne.common.neType"),
|
||||||
|
"H1": i18n.TKey(language, "ne.common.neName"),
|
||||||
|
"I1": i18n.TKey(language, "ne.common.neId"),
|
||||||
|
}
|
||||||
|
if alarmStatus == "0" {
|
||||||
|
headerCells["J1"] = i18n.TKey(language, "alarm.export.clearUser")
|
||||||
|
headerCells["K1"] = i18n.TKey(language, "alarm.export.clearTime")
|
||||||
|
headerCells["L1"] = i18n.TKey(language, "alarm.export.clearType")
|
||||||
|
}
|
||||||
|
// 读取字典数据 告警原始严重程度
|
||||||
|
dictActiveAlarmType := sysService.NewSysDictData.FindByType("active_alarm_type")
|
||||||
|
// 读取字典数据 告警类型
|
||||||
|
dictActiveClearType := sysService.NewSysDictData.FindByType("active_clear_type")
|
||||||
|
// 读取字典数据 告警确认类型
|
||||||
|
dictActiveAlarmSeverity := sysService.NewSysDictData.FindByType("active_alarm_severity")
|
||||||
|
// 从第二行开始的数据
|
||||||
|
dataCells := make([]map[string]any, 0)
|
||||||
|
for i, row := range rows {
|
||||||
|
idx := strconv.Itoa(i + 2)
|
||||||
|
|
||||||
|
// 原始严重程度
|
||||||
|
origSeverity := "-"
|
||||||
|
for _, v := range dictActiveAlarmSeverity {
|
||||||
|
if row.OrigSeverity == v.DataValue {
|
||||||
|
origSeverity = i18n.TKey(language, v.DataLabel)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 活动告警类型
|
||||||
|
alarmType := "-"
|
||||||
|
for _, v := range dictActiveAlarmType {
|
||||||
|
if row.AlarmType == v.DataValue {
|
||||||
|
alarmType = i18n.TKey(language, v.DataLabel)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 告警清除类型
|
||||||
|
clearType := "-"
|
||||||
|
for _, v := range dictActiveClearType {
|
||||||
|
if fmt.Sprint(row.ClearType) == v.DataValue {
|
||||||
|
clearType = i18n.TKey(language, v.DataLabel)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eventTimeStr := date.ParseDateToStr(row.EventTime, date.YYYY_MM_DDTHH_MM_SSZ)
|
||||||
|
|
||||||
|
cells := map[string]any{
|
||||||
|
"A" + idx: alarmType,
|
||||||
|
"B" + idx: origSeverity,
|
||||||
|
"C" + idx: row.AlarmTitle,
|
||||||
|
"D" + idx: eventTimeStr,
|
||||||
|
"E" + idx: row.AlarmId,
|
||||||
|
"F" + idx: row.AlarmCode,
|
||||||
|
"G" + idx: row.NeType,
|
||||||
|
"H" + idx: row.NeName,
|
||||||
|
"I" + idx: row.NeId,
|
||||||
|
}
|
||||||
|
if alarmStatus == "0" {
|
||||||
|
clearTimeStr := date.ParseDateToStr(row.ClearTime, date.YYYY_MM_DDTHH_MM_SSZ)
|
||||||
|
cells["J"+idx] = row.ClearUser
|
||||||
|
cells["K"+idx] = clearType
|
||||||
|
cells["L"+idx] = clearTimeStr
|
||||||
|
}
|
||||||
|
dataCells = append(dataCells, cells)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出数据表格
|
||||||
|
return file.WriteSheet(headerCells, dataCells, fileName, "")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user