1
0
Files
omc_api/features/pm/kpi_c_report/model.go
2024-10-18 17:26:59 +08:00

72 lines
2.8 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 kpi_c_report
import (
"database/sql/driver"
"encoding/json"
"fmt"
"time"
)
type KpiCVal struct {
KPIID string `json:"kpi_id" gorm:"column:kpi_id"`
Value float64 `json:"value" gorm:"column:value"`
Err string `json:"err" gorm:"column:err"`
}
type KpiCValues []KpiCVal
type KpiCReport struct {
ID int `gorm:"column:id;primary_key;auto_increment" json:"id"`
NeType *string `gorm:"column:ne_type;default:NULL" json:"neType,omitempty"`
NeName *string `gorm:"column:ne_name;default:" json:"neName,omitempty"`
RmUID *string `gorm:"column:rm_uid;default:NULL" json:"rmUid,omitempty"`
Date string `gorm:"column:date" json:"date"` // time.Time `gorm:"column:date" json:"date"`
StartTime *string `gorm:"column:start_time;default:NULL" json:"startTime,omitempty"`
EndTime *string `gorm:"column:end_time;default:NULL" json:"endTime,omitempty"`
Index int16 `gorm:"column:index" json:"index"`
Granularity *int8 `gorm:"column:granularity;default:60" json:"granularity,omitempty"` //Time granualarity: 5/10/.../60/300 (second)
KpiValues KpiCValues `gorm:"column:kpi_values;type:json" json:"kpiValues,omitempty"`
CreatedAt *time.Time `gorm:"column:created_at;default:current_timestamp()" json:"createdAt,omitempty"`
}
type KpiCReportQuery struct {
NeType string `json:"neType" form:"neType" binding:"required"`
NeID string `json:"neId" form:"neId" binding:"required"`
RmUID string `json:"rmUID" form:"rmUID"`
StartTime string `json:"startTime" form:"startTime"`
EndTime string `json:"endTime" form:"endTime"`
UserName string `json:"userName" form:"userName"`
SortField string `json:"sortField" form:"sortField" binding:"omitempty,oneof=created_at"` // 排序字段,填写结果字段
SortOrder string `json:"sortOrder" form:"sortOrder" binding:"omitempty,oneof=asc desc"` // 排序升降序asc desc
PageNum int `json:"pageNum" form:"pageNum"`
PageSize int `json:"pageSize" form:"pageSize"`
}
type KpiCReport2FE struct {
NeType string `json:"neType" gorm:"column:ne_type"`
NeId string `json:"neId"`
NeName string `json:"neName" gorm:"column:ne_name"`
RmUID string `json:"rmUid" gorm:"column:rm_uid"`
TimeGroup string `json:"timeGroup"`
StartIndex int16 `json:"startIndex" gorm:"column:index"`
Granularity int8 `json:"granularity" gorm:"column:granularity"`
}
func TableName() string {
return "kpi_c_report"
}
// 将 KpiCValues 转换为 JSON 字节
func (k KpiCValues) Value() (driver.Value, error) {
return json.Marshal(k)
}
// 从字节中扫描 KpiCValues
func (k *KpiCValues) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return fmt.Errorf("failed to scan value: %v", value)
}
return json.Unmarshal(b, k)
}