fix: gold kpi add granularity
This commit is contained in:
@@ -143,3 +143,6 @@ ALTER TABLE
|
||||
|
||||
ALTER TABLE `omc_db`.`sys_dict_data`
|
||||
MODIFY COLUMN `dict_code` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '字典编码' FIRST;
|
||||
|
||||
ALTER TABLE `omc_db`.`gold_kpi`
|
||||
ADD COLUMN IF NOT EXISTS `granularity` tinyint NOT NULL DEFAULT 60 COMMENT '时间颗粒度: 5/10/.../60/300 (秒)' AFTER `index`;
|
||||
@@ -143,3 +143,6 @@ ALTER TABLE
|
||||
|
||||
ALTER TABLE `omc_db`.`sys_dict_data`
|
||||
MODIFY COLUMN `dict_code` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '字典编码' FIRST;
|
||||
|
||||
ALTER TABLE `omc_db`.`gold_kpi`
|
||||
ADD COLUMN IF NOT EXISTS `granularity` tinyint NOT NULL DEFAULT 60 COMMENT '时间颗粒度: 5/10/.../60/300 (秒)' AFTER `index`;
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -49,6 +50,7 @@ type GoldKpi struct {
|
||||
// Id int `json:"-" xorm:"pk 'id' autoincr"`
|
||||
Date string `json:"date" xorm:"date"`
|
||||
Index int `json:"index"`
|
||||
Granularity int8 `json:"granularity"`
|
||||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
NEName string `json:"neName" xorm:"ne_name"`
|
||||
@@ -182,6 +184,12 @@ func PostKPIReportFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
goldKpi.Index, _ = strconv.Atoi(vars["index"])
|
||||
goldKpi.StartTime = global.GetFmtTimeString(layout, kpiReport.Task.Period.StartTime, time.DateTime)
|
||||
goldKpi.EndTime = global.GetFmtTimeString(layout, kpiReport.Task.Period.EndTime, time.DateTime)
|
||||
// get time granularity from startTime and endTime
|
||||
seconds, _ := global.GetSecondDuration(goldKpi.StartTime, goldKpi.EndTime)
|
||||
goldKpi.Granularity = 60
|
||||
if seconds != 0 && seconds <= math.MaxInt8 && seconds >= math.MinInt8 {
|
||||
goldKpi.Granularity = int8(seconds)
|
||||
}
|
||||
goldKpi.NEName = kpiReport.Task.NE.NEName
|
||||
goldKpi.RmUid = kpiReport.Task.NE.RmUID
|
||||
goldKpi.NEType = kpiReport.Task.NE.NeType
|
||||
|
||||
@@ -391,6 +391,27 @@ func GetSecondsSinceDatetime(datetimeStr string) (int64, error) {
|
||||
return seconds, nil
|
||||
}
|
||||
|
||||
func GetSecondDuration(time1, time2 string) (int64, error) {
|
||||
loc1, _ := time.LoadLocation("Local")
|
||||
// 解析日期时间字符串为时间对象
|
||||
t1, err := time.ParseInLocation(time.DateTime, time1, loc1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
t2, err := time.ParseInLocation(time.DateTime, time2, loc1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 计算时间差
|
||||
duration := t2.Sub(t1)
|
||||
|
||||
// 获取时间差的秒数
|
||||
seconds := int64(duration.Seconds())
|
||||
|
||||
return seconds, nil
|
||||
}
|
||||
|
||||
// 0: invalid ip
|
||||
// 4: IPv4
|
||||
// 6: IPv6
|
||||
|
||||
Reference in New Issue
Block a user