feat: 网元SGWC-CDR数据功能接口
This commit is contained in:
94
src/modules/network_data/repository/cdr_event_sgwc.go
Normal file
94
src/modules/network_data/repository/cdr_event_sgwc.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/modules/network_data/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 CDREventSGWC 结构体
|
||||
var NewCDREventSGWC = &CDREventSGWC{}
|
||||
|
||||
// CDREventSGWC CDR会话事件 数据层处理
|
||||
type CDREventSGWC struct{}
|
||||
|
||||
// SelectByPage 分页查询集合
|
||||
func (r CDREventSGWC) SelectByPage(querys model.CDREventSGWCQuery) ([]model.CDREventSGWC, int64) {
|
||||
tx := datasource.DB("").Model(&model.CDREventSGWC{})
|
||||
// 查询条件拼接
|
||||
if querys.NeType != "" {
|
||||
tx = tx.Where("ne_type = ?", querys.NeType)
|
||||
}
|
||||
if querys.RmUID != "" {
|
||||
tx = tx.Where("rm_uid = ?", querys.RmUID)
|
||||
}
|
||||
if querys.StartTime != "" {
|
||||
startTime := querys.StartTime
|
||||
if len(startTime) == 13 {
|
||||
startTime = startTime[:10]
|
||||
}
|
||||
tx = tx.Where("timestamp >= ?", startTime)
|
||||
}
|
||||
if querys.EndTime != "" {
|
||||
endTime := querys.EndTime
|
||||
if len(endTime) == 13 {
|
||||
endTime = endTime[:10]
|
||||
}
|
||||
tx = tx.Where("timestamp <= ?", endTime)
|
||||
}
|
||||
if querys.RecordType != "" {
|
||||
tx = tx.Where("JSON_EXTRACT(cdr_json, '$.recordType') = ?", querys.RecordType)
|
||||
}
|
||||
if querys.SubscriberID != "" {
|
||||
tx = tx.Where("JSON_EXTRACT(cdr_json, '$.subscriberIdentifier.subscriptionIDData') = ?", querys.SubscriberID)
|
||||
}
|
||||
|
||||
// 查询结果
|
||||
var total int64 = 0
|
||||
rows := []model.CDREventSGWC{}
|
||||
|
||||
// 查询数量为0直接返回
|
||||
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// 查询数据分页
|
||||
pageNum, pageSize := datasource.PageNumSize(querys.PageNum, querys.PageSize)
|
||||
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
|
||||
err := tx.Find(&rows).Error
|
||||
if err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows, total
|
||||
}
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *CDREventSGWC) SelectByIds(ids []string) []model.CDREventSGWC {
|
||||
rows := []model.CDREventSGWC{}
|
||||
if len(ids) <= 0 {
|
||||
return rows
|
||||
}
|
||||
tx := datasource.DB("").Model(&model.CDREventSGWC{})
|
||||
// 构建查询条件
|
||||
tx = tx.Where("id in ?", ids)
|
||||
// 查询数据
|
||||
if err := tx.Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *CDREventSGWC) DeleteByIds(ids []string) int64 {
|
||||
if len(ids) <= 0 {
|
||||
return 0
|
||||
}
|
||||
tx := datasource.DB("").Where("id in ?", ids)
|
||||
if err := tx.Delete(&model.CDREventSGWC{}).Error; err != nil {
|
||||
logger.Errorf("delete err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
Reference in New Issue
Block a user