Explorar el Código

告警相关功能

sixian hace 2 años
padre
commit
96616a97bb

+ 1 - 1
Makefile

@@ -8,7 +8,7 @@ clear:
 	@$(RM) ${BINARY}
 
 build:
-	@go build -tags=jsoniter -o ${BINARY} ./
+	@go build  -o ${BINARY} ./
 
 push-test:clear build
 	@$(push_test)

+ 19 - 0
app/warn/controller/platformAlarmController.go

@@ -59,3 +59,22 @@ func (c platformAlarmCrl) Refresh(ctx *gin.Context) {
 	}()
 	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
+
+func (c platformAlarmCrl) HannleAlart(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+	id, _ := strconv.Atoi(ctx.Query("id"))
+	armHandle, _ := strconv.Atoi(ctx.Query("armHandle"))
+	remark := ctx.Query("remark")
+
+	err := service.PlatformAlarmService.HannleAlart(claims.TenantId, id, armHandle, remark)
+	if err != nil {
+		ctx.JSON(http.StatusBadRequest, err)
+		return
+	}
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
+}
+
+func (c platformAlarmCrl) Detail(ctx *gin.Context) {
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
+}

+ 24 - 18
app/warn/dao/platformAlarmDao.go

@@ -1,6 +1,8 @@
 package dao
 
 import (
+	"errors"
+	"gorm.io/gorm"
 	"iot_manager_service/app/warn/model"
 	"iot_manager_service/util/common"
 )
@@ -25,19 +27,19 @@ type PlatformAlarm struct {
 	ArmLevel          int         `gorm:"column:arm_level;type:int(11);comment: 告警类型 1紧急2严重3普通" json:"armLevel"`            // 告警类型 1紧急2严重3普通
 	ArmContent        string      `gorm:"column:arm_content;type:varchar(255);comment:告警内容" json:"armContent"`              // 告警内容
 	ArmUrl            string      `gorm:"column:arm_url;type:varchar(1000);comment:运维告警图片地址" json:"armUrl"`                 // 运维告警图片地址
-	ArmHandleTime     common.Time `gorm:"column:arm_handle_time;type:datetime" json:"armHandleTime"`                        // 告警处理时间
-	Status            int         `gorm:"column:status;type:int(11);comment:告警状态 1处理完成2待处理3无需处理" json:"status"`             // 告警状态 1处理完成2待处理3无需处理
+	ArmHanleRemark    string      `gorm:"column:arm_handle_remark;type:text;comment:处理内容" json:"armHanleRemark"`
+	ArmHandleTime     common.Time `gorm:"column:arm_handle_time;type:datetime" json:"armHandleTime"`            // 告警处理时间
+	Status            int         `gorm:"column:status;type:int(11);comment:告警状态 1处理完成2待处理3无需处理" json:"status"` // 告警状态 1处理完成2待处理3无需处理
 	NoticeRecordId    int         `gorm:"comment:发送通知ID" json:"noticeRecordId"`
-	NoticeRecord      NoticeRecord
-	TenantId          string  `gorm:"column:tenant_id;type:varchar(12);comment:租户ID" json:"tenantId"`                       // 租户ID
-	ProcessInstanceId string  `gorm:"column:process_instance_id;type:varchar(255);comment:流程实例主键" json:"processInstanceId"` // 流程实例主键
-	BusinessId        string  `gorm:"column:business_id;type:varchar(64);comment:流程实例主键ID" json:"businessId"`               // 流程实例主键ID
-	Threshold         float64 `gorm:"column:threshold;type:float(11,2);comment:阈值-业务告警" json:"threshold"`                   // 阈值-业务告警
-	Value             float64 `gorm:"column:value;type:float(11,2);comment:告警时的值-业务告警" json:"value"`                        // 告警时的值-业务告警
-	Sid               int     `gorm:"column:sid;type:int(11);comment:物模型sid" json:"sid"`                                    // 物模型sid
-	Cid               uint    `gorm:"column:cid;type:int(10) unsigned;comment:告警策略编号" json:"cid"`                           // 告警策略编号
-	Cname             string  `gorm:"column:cname;type:varchar(100);comment:告警策略名称" json:"cname"`                           // 告警策略名称
-	ExtendId          int     `gorm:"column:extend_id;type:int(11);comment:扩展id"json:"extendId"`                            // 扩展id
+	TenantId          string      `gorm:"column:tenant_id;type:varchar(12);comment:租户ID" json:"tenantId"`                       // 租户ID
+	ProcessInstanceId string      `gorm:"column:process_instance_id;type:varchar(255);comment:流程实例主键" json:"processInstanceId"` // 流程实例主键
+	BusinessId        string      `gorm:"column:business_id;type:varchar(64);comment:流程实例主键ID" json:"businessId"`               // 流程实例主键ID
+	Threshold         float64     `gorm:"column:threshold;type:float(11,2);comment:阈值-业务告警" json:"threshold"`                   // 阈值-业务告警
+	Value             float64     `gorm:"column:value;type:float(11,2);comment:告警时的值-业务告警" json:"value"`                        // 告警时的值-业务告警
+	Sid               int         `gorm:"column:sid;type:int(11);comment:物模型sid" json:"sid"`                                    // 物模型sid
+	Cid               uint        `gorm:"column:cid;type:int(10) unsigned;comment:告警策略编号" json:"cid"`                           // 告警策略编号
+	Cname             string      `gorm:"column:cname;type:varchar(100);comment:告警策略名称" json:"cname"`                           // 告警策略名称
+	ExtendId          int         `gorm:"column:extend_id;type:int(11);comment:扩展id"json:"extendId"`                            // 扩展id
 }
 
 func (PlatformAlarm) TableName() string {
@@ -50,11 +52,7 @@ func (a PlatformAlarm) Gets(filter model.RequestPlatFormAlartFilter) ([]Platform
 	db = db.Scopes(common.Paginate(filter.Current, filter.Size))
 	if filter.ArmHandle > 0 {
 		handle := filter.ArmHandle
-		status := 2
-		if handle == 1 {
-
-		}
-		db = db.Where(&PlatformAlarm{Status: status})
+		db = db.Where(&PlatformAlarm{ArmHandle: handle})
 	}
 	if filter.ArmDeviceType > 0 {
 		db = db.Where(&PlatformAlarm{ArmDeviceType: filter.ArmDeviceType})
@@ -62,7 +60,10 @@ func (a PlatformAlarm) Gets(filter model.RequestPlatFormAlartFilter) ([]Platform
 	if filter.ArmDeviceName != "" {
 		db = db.Where(&PlatformAlarm{ArmDeviceName: filter.ArmDeviceName})
 	}
-	err := db.Preload("NoticeRecord").Order("id desc").Find(&list).Error
+	err := db.Order("id desc").Find(&list).Error
+	if errors.Is(err, gorm.ErrRecordNotFound) {
+		err = nil
+	}
 	var count int64
 	db.Count(&count)
 	//fmt.Printf("count = %v", count)
@@ -78,3 +79,8 @@ func (a PlatformAlarm) GetMaxIdAndUpDateTime() (int64, string) {
 func (a PlatformAlarm) BatchCreate(his []PlatformAlarm) error {
 	return Db.Debug().CreateInBatches(his, 1000).Error
 }
+
+func (a PlatformAlarm) Update() error {
+	err := Db.Debug().Model(&a).Updates(a).Error
+	return err
+}

+ 13 - 0
app/warn/service/platformAlarmService.go

@@ -6,6 +6,7 @@ import (
 	"iot_manager_service/app/warn/model"
 	"iot_manager_service/util/common"
 	"strconv"
+	"time"
 )
 
 var PlatformAlarmService = new(platformAlarmService)
@@ -36,6 +37,8 @@ func (s platformAlarmService) GetList(tenantId int, filter model.RequestPlatForm
 			ArmLevel:          alart.ArmLevel,
 			ArmLevelName:      levelArr[alart.ArmLevel],
 			LampPoleLocation:  alart.LampPoleLocation,
+			ArmHandleTime:     alart.ArmHandleTime.String(),
+			OpsStatus:         alart.ArmHandle,
 		})
 	}
 	return list, i, err
@@ -98,3 +101,13 @@ func (s platformAlarmService) Refresh(tenantId int) error {
 	return err
 
 }
+
+func (s platformAlarmService) HannleAlart(tenant_id int, id int, armHandle int, remark string) error {
+	dao := dao.PlatformAlarm{
+		ID:             id,
+		ArmHandle:      armHandle,
+		ArmHanleRemark: remark,
+		ArmHandleTime:  common.Time(time.Now()),
+	}
+	return dao.Update()
+}

+ 2 - 0
router/router.go

@@ -575,7 +575,9 @@ func InitRouter(engine *gin.Engine) {
 		alarmGroup := warnGroup.Group("alarm")
 		{
 			alarmGroup.GET("/list", warn.PlatformAlarm.List)
+			alarmGroup.GET("/detail", warn.PlatformAlarm.Detail)
 			alarmGroup.GET("/refresh", warn.PlatformAlarm.Refresh)
+			alarmGroup.POST("/changeHandleType", warn.PlatformAlarm.HannleAlart)
 		}
 	}
 }