gva-pms/server/plugin/monitor/model/monitor_config.go

47 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// MonitorConfig 监控配置 结构体
type MonitorConfig struct {
global.GVA_MODEL
BusinessDB *string `json:"businessDB" form:"businessDB" gorm:"column:business_db;comment:;"` //业务库名
Database *string `json:"database" form:"database" gorm:"column:database;comment:;" binding:"required"` //数据库名
Table *string `json:"table" form:"table" gorm:"column:db_table;comment:;" binding:"required"` //表名
Columns []string `json:"columns" form:"columns" gorm:"column:columns;type:json;serializer:json;comment:;" binding:"required"` //字段
IsEnable *bool `json:"isEnable" form:"isEnable" gorm:"column:is_enable;comment:;" binding:"required"` //是否启用
StartTime *time.Time `json:"startTime" form:"startTime" gorm:"column:start_time;comment:;"` //开始时间
EndTime *time.Time `json:"endTime" form:"endTime" gorm:"column:end_time;comment:;"` //结束时间
}
// TableName 监控配置 MonitorConfig自定义表名 monitor_config
func (MonitorConfig) TableName() string {
return "monitor_config"
}
func (m *MonitorConfig) IsExpire() bool {
T := time.Now()
// 如果如果只设置了开始时间,则判断开始时间是否在当前时间之前
if m.StartTime != nil && m.EndTime == nil {
// fmt.Println(*m.Table, "是否生效1", m.StartTime.Before(T))
return m.StartTime.Before(T)
}
// 如果只设置了结束时间,则判断结束时间是否在当前时间之后
if m.StartTime == nil && m.EndTime != nil {
// fmt.Println(*m.Table, "是否生效2", m.EndTime.After(T))
return m.EndTime.After(T)
}
// 如果同时设置了开始时间和结束时间,则判断开始时间是否在当前时间之前,结束时间是否在当前时间之后
if m.StartTime != nil && m.EndTime != nil {
// fmt.Println(*m.Table, "是否生效3", m.StartTime.Before(T) && m.EndTime.After(T))
return m.StartTime.Before(T) && m.EndTime.After(T)
}
// fmt.Println(*m.Table, "是否生效4", true)
return true
}