feat: 添加KPI忙时0609统计接口及相关服务逻辑

This commit is contained in:
TsMask
2025-09-01 18:14:20 +08:00
parent 723d9431f7
commit 77feee664c
5 changed files with 111 additions and 5 deletions

View File

@@ -301,3 +301,39 @@ func (r *PerfKPI) SelectUPFTotalFlow(neType, rmUID, startDate, endDate string) m
}
return results[0]
}
// SelectIMSBusyHour 查询IMS忙时流量 SCSCF.06呼叫尝试次数 SCSCF.09呼叫成功次数
func (r *PerfKPI) SelectIMSBusyHour(rmUID string, startDate, endDate int64) []map[string]any {
// 查询条件拼接
var conditions []string
var params []any
if rmUID != "" {
conditions = append(conditions, "kims.rm_uid = ?")
params = append(params, rmUID)
}
if startDate > 0 {
conditions = append(conditions, "kims.created_at >= ?")
params = append(params, startDate)
}
if endDate > 0 {
conditions = append(conditions, "kims.created_at <= ?")
params = append(params, endDate)
}
// 构建查询条件语句
whereSql := ""
if len(conditions) > 0 {
whereSql += " where " + strings.Join(conditions, " and ")
}
// 查询数据 3600秒=1小时
querySql := `SELECT
CONCAT(FLOOR(kims.created_at / (3600 * 1000)) * (3600 * 1000)) AS timeGroup,
sum( CASE WHEN JSON_EXTRACT(kims.kpi_values, '$[5].kpi_id') = 'SCSCF.06' THEN JSON_EXTRACT(kims.kpi_values, '$[5].value') ELSE 0 END ) AS 'callAttempts',
sum( CASE WHEN JSON_EXTRACT(kims.kpi_values, '$[8].kpi_id') = ' ' THEN JSON_EXTRACT(kims.kpi_values, '$[8].value') ELSE 0 END ) AS 'callCompletions'
FROM kpi_report_ims kims`
results, err := datasource.RawDB("", querySql+whereSql+" GROUP by timeGroup ", params)
if err != nil {
logger.Errorf("query err => %v", err)
}
return results
}