feat: 添加KPI忙时0609统计接口及相关服务逻辑
This commit is contained in:
@@ -280,3 +280,72 @@ func (r KpiReport) UPFTodayFlowLoad(day int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IMSBusyHour IMS忙时流量统计
|
||||
// SCSCF.06呼叫尝试次数 SCSCF.09呼叫成功次数
|
||||
func (r KpiReport) IMSBusyHour(rmUID string, timestamp int64) []map[string]any {
|
||||
t := time.UnixMilli(timestamp)
|
||||
beginTime := t
|
||||
endTime := t
|
||||
// 检查时分秒是否都为零
|
||||
if t.Hour() == 0 && t.Minute() == 0 && t.Second() == 0 {
|
||||
// 获取当天起始时间(00:00:00)
|
||||
beginTime = t.Truncate(time.Hour)
|
||||
// 计算当天结束时间(23:59:59)
|
||||
endTime = beginTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
} else {
|
||||
// 起始时间:当前小时的 00 分 00 秒
|
||||
beginTime = t.Truncate(time.Hour)
|
||||
// 结束时间:当前小时的 59 分 59 秒 999 毫秒
|
||||
endTime = beginTime.Add(time.Hour - time.Millisecond)
|
||||
}
|
||||
// 转换为毫秒级时间戳
|
||||
rows := r.kpiReportRepository.SelectIMS(rmUID, beginTime.UnixMilli(), endTime.UnixMilli())
|
||||
|
||||
// 创建一个map来存储按时间段合并后的数据
|
||||
timeGroup := make(map[int64]map[string]int64)
|
||||
// 遍历每个数据项
|
||||
for _, row := range rows {
|
||||
// 将毫秒时间戳转换为小时级时间戳(保留到小时的起始毫秒)
|
||||
timeHour := row.CreatedAt / 3600000 * 3600000 // 1小时 = 3600000毫秒
|
||||
|
||||
// 解析 JSON 字符串为 map
|
||||
var kpiValues []map[string]any
|
||||
err := json.Unmarshal([]byte(row.KpiValues), &kpiValues)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var callAttempts, callCompletions int64
|
||||
for _, v := range kpiValues {
|
||||
if k, ok := v["kpiId"]; ok {
|
||||
if k == "SCSCF.06" {
|
||||
callAttempts = parse.Number(v["value"])
|
||||
}
|
||||
if k == "SCSCF.09" {
|
||||
callCompletions = parse.Number(v["value"])
|
||||
}
|
||||
}
|
||||
}
|
||||
// 合并到对应的小时段
|
||||
if _, exists := timeGroup[timeHour]; !exists {
|
||||
timeGroup[timeHour] = map[string]int64{
|
||||
"callAttempts": 0,
|
||||
"callCompletions": 0,
|
||||
}
|
||||
}
|
||||
timeGroup[timeHour]["callAttempts"] += callAttempts
|
||||
timeGroup[timeHour]["callCompletions"] += callCompletions
|
||||
}
|
||||
|
||||
// 时间组合输出
|
||||
data := make([]map[string]any, 0, len(timeGroup))
|
||||
for hour, sums := range timeGroup {
|
||||
data = append(data, map[string]any{
|
||||
"timeGroup": fmt.Sprintf("%d", hour),
|
||||
"callAttempts": sums["callAttempts"],
|
||||
"callCompletions": sums["callCompletions"],
|
||||
})
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user