From 2d3aa9b737b9e17dc9f591b0c0230fe093a980c2 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 26 Dec 2024 18:44:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E9=A1=B5=E9=9D=A2-=E6=95=B0=E6=8D=AE=E6=B5=81?= =?UTF-8?q?=E9=87=8F=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/install/sys_dict_data1_i18n_zh.sql | 2 +- database/install/sys_dict_data2_i18n_en.sql | 2 +- database/install/sys_menu.sql | 2 +- database/upgrade/upg_sys_dict_data1_i18n_zh.sql | 2 +- database/upgrade/upg_sys_dict_data2_i18n_en.sql | 2 +- database/upgrade/upg_sys_menu.sql | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/database/install/sys_dict_data1_i18n_zh.sql b/database/install/sys_dict_data1_i18n_zh.sql index eb0c9175..1a97bcb7 100644 --- a/database/install/sys_dict_data1_i18n_zh.sql +++ b/database/install/sys_dict_data1_i18n_zh.sql @@ -134,7 +134,7 @@ INSERT INTO `sys_dict_data` VALUES (1126, 1126, 'menu.dashboard.smscCDR.content' INSERT INTO `sys_dict_data` VALUES (1127, 1127, 'menu.perf.thresholdRemark', '性能门限菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (1128, 1128, 'menu.perf.kpiRemark', '黄金指标菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (1129, 1129, 'menu.perf.customTargetRemark', '自定义指标菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); --- INSERT INTO `sys_dict_data` VALUES (1130, 1130, 'menu.perf.setRemark', '性能通用设置菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); +INSERT INTO `sys_dict_data` VALUES (1130, 1130, 'menu.dashboard.smfCDRByIMSI', '数据流量报表', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (1131, 1131, 'menu.mmlRemark', 'MML管理目录', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (1132, 1132, 'menu.mml.neRemark', '网元操作菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (1133, 1133, 'menu.mml.udmRemark', '网元UDM用户数据菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); diff --git a/database/install/sys_dict_data2_i18n_en.sql b/database/install/sys_dict_data2_i18n_en.sql index 96947728..4a030bfa 100644 --- a/database/install/sys_dict_data2_i18n_en.sql +++ b/database/install/sys_dict_data2_i18n_en.sql @@ -134,7 +134,7 @@ INSERT INTO `sys_dict_data` VALUES (3126, 3126, 'menu.dashboard.smscCDR.content' INSERT INTO `sys_dict_data` VALUES (3127, 3127, 'menu.perf.thresholdRemark', 'Performance Threshold Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (3128, 3128, 'menu.perf.kpiRemark', 'Key Performance Indicator Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (3129, 3129, 'menu.perf.customTargetRemark', 'Custom Indicator Management Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); --- INSERT INTO `sys_dict_data` VALUES (3130, 3130, 'menu.perf.setRemark', 'Performance General Settings Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); +INSERT INTO `sys_dict_data` VALUES (3130, 3130, 'menu.dashboard.smfCDRByIMSI', 'Data Usage Report', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (3131, 3131, 'menu.mmlRemark', 'MML Management Catalog', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (3132, 3132, 'menu.mml.neRemark', 'Network Element Operations Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_dict_data` VALUES (3133, 3133, 'menu.mml.udmRemark', 'Network Element UDM User Data Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); diff --git a/database/install/sys_menu.sql b/database/install/sys_menu.sql index 49299c7e..4d665b5a 100644 --- a/database/install/sys_menu.sql +++ b/database/install/sys_menu.sql @@ -167,7 +167,7 @@ INSERT INTO `sys_menu` VALUES (2114, 'menu.system.systemSet', 1, 60, 'setting', INSERT INTO `sys_menu` VALUES (2115, 'menu.system.systemResource', 1, 6, 'monitor', 'monitor/monitor/index', '1', '1', 'M', '1', '1', 'monitor:monitor:info', 'icon-soutubiao', 'supervisor', 1700000000000, NULL, 0, 'menu.system.systemResourceRemark'); INSERT INTO `sys_menu` VALUES (2116, 'menu.dashboard.smscCDR.content', 2157, 1, '', '', '1', '1', 'B', '1', '1', 'cdr:smsc:content', '#', 'supervisor', 1734936660956, '', 0, ''); INSERT INTO `sys_menu` VALUES (2117, 'menu.common.delete', 2140, 1, '', '', '1', '1', 'B', '1', '1', 'cdr:ne:remove', '#', 'supervisor', 1734936660956, '', 0, ''); --- INSERT INTO `sys_menu` VALUES (2118, 'menu.config.configNETreeTable', 4, 2, 'configNETreeTable', 'configManage/configParamTreeTable/index', '1', '1', 'M', '1', '0', 'configManage:configParam:index', 'icon-wofaqi', 'supervisor', 1700000000000, NULL, 0, 'menu.config.configNETreeTableRemark'); +INSERT INTO `sys_menu` VALUES (2118, 'menu.dashboard.smfCDRByIMSI', 2140, 7, 'smfCDRByIMSI', 'dashboard/smfCDRByIMSI/index', '1', '0', 'M', '1', '1', 'dashboard:cdr:index', 'icon-gerenzhanghu', 'supervisor', 1735010792379, '', 0, ''); INSERT INTO `sys_menu` VALUES (2119, 'menu.ueUser.n3iwf', 5, 8, 'n3iwf', 'neUser/n3iwf/index', '1', '0', 'M', '0', '1', 'neUser:n3iwf:index', 'icon-paixu', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_menu` VALUES (2120, 'menu.ueUser.pcf', 5, 9, 'pcf', 'neUser/pcf/index', '1', '0', 'M', '1', '1', 'neUser:pcf:index', 'icon-paixu', 'supervisor', 1700000000000, NULL, 0, NULL); INSERT INTO `sys_menu` VALUES (2121, 'menu.system.user.editRole', 100, 8, NULL, NULL, '1', '1', 'B', '1', '1', 'system:user:editRole', '#', 'supervisor', 1700000000000, NULL, 0, NULL); diff --git a/database/upgrade/upg_sys_dict_data1_i18n_zh.sql b/database/upgrade/upg_sys_dict_data1_i18n_zh.sql index 1f4437c9..4c673929 100644 --- a/database/upgrade/upg_sys_dict_data1_i18n_zh.sql +++ b/database/upgrade/upg_sys_dict_data1_i18n_zh.sql @@ -141,7 +141,7 @@ REPLACE INTO `sys_dict_data` VALUES (1126, 1126, 'menu.dashboard.smscCDR.content REPLACE INTO `sys_dict_data` VALUES (1127, 1127, 'menu.perf.thresholdRemark', '性能门限菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (1128, 1128, 'menu.perf.kpiRemark', '黄金指标菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (1129, 1129, 'menu.perf.customTargetRemark', '自定义指标菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); --- REPLACE INTO `sys_dict_data` VALUES (1130, 1130, 'menu.perf.setRemark', '性能通用设置菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); +REPLACE INTO `sys_dict_data` VALUES (1130, 1130, 'menu.dashboard.smfCDRByIMSI', '数据流量报表', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (1131, 1131, 'menu.mmlRemark', 'MML管理目录', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (1132, 1132, 'menu.mml.neRemark', '网元操作菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (1133, 1133, 'menu.mml.udmRemark', '网元UDM用户数据菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); diff --git a/database/upgrade/upg_sys_dict_data2_i18n_en.sql b/database/upgrade/upg_sys_dict_data2_i18n_en.sql index a50ced6b..b2ba4ec8 100644 --- a/database/upgrade/upg_sys_dict_data2_i18n_en.sql +++ b/database/upgrade/upg_sys_dict_data2_i18n_en.sql @@ -139,7 +139,7 @@ REPLACE INTO `sys_dict_data` VALUES (3126, 3126, 'menu.dashboard.smscCDR.content REPLACE INTO `sys_dict_data` VALUES (3127, 3127, 'menu.perf.thresholdRemark', 'Performance Threshold Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (3128, 3128, 'menu.perf.kpiRemark', 'Key Performance Indicator Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (3129, 3129, 'menu.perf.customTargetRemark', 'Custom Indicator Management Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); --- REPLACE INTO `sys_dict_data` VALUES (3130, 3130, 'menu.perf.setRemark', 'Performance General Settings Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); +REPLACE INTO `sys_dict_data` VALUES (3130, 3130, 'menu.dashboard.smfCDRByIMSI', 'Data Usage Report', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (3131, 3131, 'menu.mmlRemark', 'MML Management Catalog', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (3132, 3132, 'menu.mml.neRemark', 'Network Element Operations Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_dict_data` VALUES (3133, 3133, 'menu.mml.udmRemark', 'Network Element UDM User Data Menu', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL); diff --git a/database/upgrade/upg_sys_menu.sql b/database/upgrade/upg_sys_menu.sql index d82a9fd2..074dd34a 100644 --- a/database/upgrade/upg_sys_menu.sql +++ b/database/upgrade/upg_sys_menu.sql @@ -150,7 +150,7 @@ REPLACE INTO `sys_menu` VALUES (2114, 'menu.system.systemSet', 1, 60, 'setting', REPLACE INTO `sys_menu` VALUES (2115, 'menu.system.systemResource', 1, 6, 'monitor', 'monitor/monitor/index', '1', '1', 'M', '1', '1', 'monitor:monitor:info', 'icon-soutubiao', 'supervisor', 1700000000000, NULL, 0, 'menu.system.systemResourceRemark'); REPLACE INTO `sys_menu` VALUES (2116, 'menu.dashboard.smscCDR.content', 2157, 1, '', '', '1', '1', 'B', '1', '1', 'cdr:smsc:content', '#', 'supervisor', 1734936660956, '', 0, ''); REPLACE INTO `sys_menu` VALUES (2117, 'menu.common.delete', 2140, 1, '', '', '1', '1', 'B', '1', '1', 'cdr:ne:remove', '#', 'supervisor', 1734936660956, '', 0, ''); --- REPLACE INTO `sys_menu` VALUES (2118, 'menu.config.configNETreeTable', 4, 2, 'configNETreeTable', 'configManage/configParamTreeTable/index', '1', '1', 'M', '1', '0', 'configManage:configParam:index', 'icon-wofaqi', 'supervisor', 1700000000000, NULL, 0, 'menu.config.configNETreeTableRemark'); +REPLACE INTO `sys_menu` VALUES (2118, 'menu.dashboard.smfCDRByIMSI', 2140, 7, 'smfCDRByIMSI', 'dashboard/smfCDRByIMSI/index', '1', '0', 'M', '1', '1', 'dashboard:cdr:index', 'icon-gerenzhanghu', 'supervisor', 1735010792379, '', 0, ''); REPLACE INTO `sys_menu` VALUES (2119, 'menu.ueUser.n3iwf', 5, 8, 'n3iwf', 'neUser/n3iwf/index', '1', '0', 'M', '0', '1', 'neUser:n3iwf:index', 'icon-paixu', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_menu` VALUES (2120, 'menu.ueUser.pcf', 5, 9, 'pcf', 'neUser/pcf/index', '1', '0', 'M', '1', '1', 'neUser:pcf:index', 'icon-paixu', 'supervisor', 1700000000000, NULL, 0, NULL); REPLACE INTO `sys_menu` VALUES (2121, 'menu.system.user.editRole', 100, 8, NULL, NULL, '1', '1', 'B', '1', '1', 'system:user:editRole', '#', 'supervisor', 1700000000000, NULL, 0, NULL); From 8911468c7a9452522303a7d4e9b51409bc247116 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 26 Dec 2024 18:45:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20SMF-CDR/SGWC-CDR=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E6=B5=81=E9=87=8F=E8=BF=9B=E8=A1=8C=E7=B4=AF?= =?UTF-8?q?=E5=8A=A0=E4=B8=8D=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/network_data/controller/sgwc.go | 171 +-------------- src/modules/network_data/controller/smf.go | 196 +----------------- .../network_data/service/cdr_event_sgwc.go | 177 ++++++++++++++++ .../network_data/service/cdr_event_smf.go | 192 +++++++++++++++++ 4 files changed, 372 insertions(+), 364 deletions(-) diff --git a/src/modules/network_data/controller/sgwc.go b/src/modules/network_data/controller/sgwc.go index 5089ebbf..f528c412 100644 --- a/src/modules/network_data/controller/sgwc.go +++ b/src/modules/network_data/controller/sgwc.go @@ -1,16 +1,12 @@ package controller import ( - "encoding/json" "fmt" - "strconv" "strings" "time" "be.ems/src/framework/i18n" - "be.ems/src/framework/logger" "be.ems/src/framework/utils/ctx" - "be.ems/src/framework/utils/file" "be.ems/src/framework/utils/parse" "be.ems/src/framework/vo/result" "be.ems/src/modules/network_data/model" @@ -116,173 +112,8 @@ func (s *SGWCController) CDRExport(c *gin.Context) { // 导出文件名称 fileName := fmt.Sprintf("sgwc_cdr_event_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli()) - // 第一行表头标题 - headerCells := map[string]string{ - "A1": "ID", - "B1": "NE Name", - "C1": "Resource Unique ID", - "D1": "Charging ID", - "E1": "IMSI", - "F1": "MSISDN", - "G1": "GPRS Uplink", - "H1": "GPRS Downlink", - "I1": "Duration", - "J1": "Invocation Time", - "K1": "PGW Address Used", - "L1": "SGW Address", - "M1": "RAT Type", - "N1": "PDPPDN Type", - "O1": "PDPPDN Address", - "P1": "Node Address", - "Q1": "Node Type", - "R1": "Record Access Point Name NI", - "S1": "Record Cause For Rec Closing", - "T1": "Record Sequence Number", - "U1": "Local Record Sequence Number", - } - // 从第二行开始的数据 - dataCells := make([]map[string]any, 0) - for i, row := range rows { - idx := strconv.Itoa(i + 2) - // 解析 JSON 字符串为 map - var cdrJSON map[string]interface{} - err := json.Unmarshal([]byte(row.CDRJSONStr), &cdrJSON) - if err != nil { - logger.Warnf("CDRExport Error parsing JSON: %s", err.Error()) - continue - } - // 计费ID - chargingID := "" - if v, ok := cdrJSON["chargingID"]; ok && v != nil { - chargingID = fmt.Sprint(parse.Number(v)) - } - // IMSI - servedIMSI := "" - if v, ok := cdrJSON["servedIMSI"]; ok && v != nil { - servedIMSI = fmt.Sprint(v) - } - // MSISDN - servedMSISDN := "" - if v, ok := cdrJSON["servedMSISDN"]; ok && v != nil { - servedMSISDN = fmt.Sprint(v) - } - // pGWAddressUsed - pGWAddressUsed := "" - if v, ok := cdrJSON["pGWAddressUsed"]; ok && v != nil { - pGWAddressUsed = fmt.Sprint(v) - } - // sGWAddress - sGWAddress := "" - if v, ok := cdrJSON["sGWAddress"]; ok && v != nil { - sGWAddress = fmt.Sprint(v) - } - // rATType - rATType := "" - if v, ok := cdrJSON["rATType"]; ok && v != nil { - rATType = fmt.Sprint(v) - } - // pdpPDNType - pdpPDNType := "" - if v, ok := cdrJSON["pdpPDNType"]; ok && v != nil { - pdpPDNType = fmt.Sprint(v) - } - // servedPDPPDNAddress - servedPDPPDNAddress := "" - if v, ok := cdrJSON["servedPDPPDNAddress"]; ok && v != nil { - servedPDPPDNAddress = fmt.Sprint(v) - } - // servedPDPPDNAddress - servingNodeAddress := []string{} - if v, ok := cdrJSON["servingNodeAddress"]; ok && v != nil { - for _, v := range v.([]any) { - servingNodeAddress = append(servingNodeAddress, fmt.Sprint(v)) - } - } - // servingNodeType - servingNodeType := []string{} - if v, ok := cdrJSON["servingNodeType"]; ok && v != nil { - for _, v := range v.([]any) { - if v, ok := v.(map[string]any)["servingNodeType"]; ok && v != nil { - servingNodeType = append(servingNodeType, fmt.Sprint(v)) - } - } - } - // accessPointNameNI - accessPointNameNI := "" - if v, ok := cdrJSON["accessPointNameNI"]; ok && v != nil { - accessPointNameNI = fmt.Sprint(v) - } - // causeForRecClosing - causeForRecClosing := "" - if v, ok := cdrJSON["causeForRecClosing"]; ok && v != nil { - causeForRecClosing = fmt.Sprint(v) - } - // recordSequenceNumber - recordSequenceNumber := "" - if v, ok := cdrJSON["recordSequenceNumber"]; ok && v != nil { - recordSequenceNumber = fmt.Sprint(v) - } - // localRecordSequenceNumber - localRecordSequenceNumber := "" - if v, ok := cdrJSON["localRecordSequenceNumber"]; ok && v != nil { - localRecordSequenceNumber = fmt.Sprint(v) - } - // 数据量上行链路 - dataVolumeGPRSUplink := []string{} - // 数据量下行链路 - dataVolumeGPRSDownlink := []string{} - if v, ok := cdrJSON["listOfTrafficVolumes"]; ok && v != nil { - usageList := v.([]any) - if len(usageList) > 0 { - for _, used := range usageList { - usedUnit := used.(map[string]any) - if dup, dupOk := usedUnit["dataVolumeGPRSUplink"]; dupOk { - dataVolumeGPRSUplink = append(dataVolumeGPRSUplink, fmt.Sprint(parse.Number(dup))) - } - if ddown, ddownOk := usedUnit["dataVolumeGPRSDownlink"]; ddownOk { - dataVolumeGPRSDownlink = append(dataVolumeGPRSDownlink, fmt.Sprint(parse.Number(ddown))) - } - } - } - } - // 时长 - duration := "-" - if v, ok := cdrJSON["duration"]; ok && v != nil { - duration = fmt.Sprint(parse.Number(v)) - } - // 调用时间 - invocationTimestamp := "" - if v, ok := cdrJSON["recordOpeningTime"]; ok && v != nil { - invocationTimestamp = v.(string) - } - - dataCells = append(dataCells, map[string]any{ - "A" + idx: row.ID, - "B" + idx: row.NeName, - "C" + idx: row.RmUID, - "D" + idx: chargingID, - "E" + idx: servedIMSI, - "F" + idx: servedMSISDN, - "G" + idx: strings.Join(dataVolumeGPRSUplink, ","), - "H" + idx: strings.Join(dataVolumeGPRSDownlink, ","), - "I" + idx: duration, - "J" + idx: invocationTimestamp, - "K" + idx: pGWAddressUsed, - "L" + idx: sGWAddress, - "M" + idx: rATType, - "N" + idx: pdpPDNType, - "O" + idx: servedPDPPDNAddress, - "P" + idx: strings.Join(servingNodeAddress, ","), - "Q" + idx: strings.Join(servingNodeType, ","), - "R" + idx: accessPointNameNI, - "S" + idx: causeForRecClosing, - "T" + idx: recordSequenceNumber, - "U" + idx: localRecordSequenceNumber, - }) - } - // 导出数据表格 - saveFilePath, err := file.WriteSheet(headerCells, dataCells, fileName, "") + saveFilePath, err := s.cdrEventService.ExportXlsx(rows, fileName) if err != nil { c.JSON(200, result.ErrMsg(err.Error())) return diff --git a/src/modules/network_data/controller/smf.go b/src/modules/network_data/controller/smf.go index 8519a051..fb293525 100644 --- a/src/modules/network_data/controller/smf.go +++ b/src/modules/network_data/controller/smf.go @@ -1,16 +1,12 @@ package controller import ( - "encoding/json" "fmt" - "strconv" "strings" "time" "be.ems/src/framework/i18n" - "be.ems/src/framework/logger" "be.ems/src/framework/utils/ctx" - "be.ems/src/framework/utils/file" "be.ems/src/framework/utils/parse" "be.ems/src/framework/vo/result" "be.ems/src/modules/network_data/model" @@ -118,196 +114,8 @@ func (s *SMFController) CDRExport(c *gin.Context) { // 导出文件名称 fileName := fmt.Sprintf("smf_cdr_event_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli()) - // 第一行表头标题 - headerCells := map[string]string{ - "A1": "ID", - "B1": "Charging ID", - "C1": "NE Name", - "D1": "Resource Unique ID", - "E1": "Subscriber ID Data", - "F1": "Subscriber ID Type", - "G1": "Data Volume Uplink", - "H1": "Data Volume Downlink", - "I1": "Data Total Volume", - "J1": "Duration", - "K1": "Invocation Time", - "L1": "User Identifier", - "M1": "SSC Mode", - "N1": "DNN ID", - "O1": "PDU Type", - "P1": "RAT Type", - "Q1": "PDU IPv4 Address", - "R1": "Network Function IPv4", - "S1": "PDU IPv6 Address Swith Prefix", - "T1": "Record Network Function ID", - "U1": "Record Type", - "V1": "Record Opening Time", - } - // 从第二行开始的数据 - dataCells := make([]map[string]any, 0) - - for i, row := range rows { - idx := strconv.Itoa(i + 2) - // 解析 JSON 字符串为 map - var cdrJSON map[string]interface{} - err := json.Unmarshal([]byte(row.CDRJSONStr), &cdrJSON) - if err != nil { - logger.Warnf("CDRExport Error parsing JSON: %s", err.Error()) - continue - } - // 计费ID - chargingID := "" - if v, ok := cdrJSON["chargingID"]; ok && v != nil { - chargingID = fmt.Sprint(parse.Number(v)) - } - // 订阅 ID 类型 - subscriptionIDType := "-" - // 订阅 ID 数据 - subscriptionIDData := "-" - if v, ok := cdrJSON["subscriberIdentifier"]; ok && v != nil { - if sub, subOk := v.(map[string]any); subOk && sub != nil { - subscriptionIDType = sub["subscriptionIDType"].(string) - subscriptionIDData = sub["subscriptionIDData"].(string) - } - } - - // 网络功能 IPv4 地址 - networkFunctionIPv4Address := "" - if v, ok := cdrJSON["nFunctionConsumerInformation"]; ok && v != nil { - if conInfo, conInfoOk := v.(map[string]any); conInfoOk && conInfo != nil { - networkFunctionIPv4Address = conInfo["networkFunctionIPv4Address"].(string) - } - } - - // 数据量上行链路 - dataVolumeUplink := []string{} - // 数据量下行链路 - dataVolumeDownlink := []string{} - // 数据总量 - dataTotalVolume := []string{} - - if v, ok := cdrJSON["listOfMultipleUnitUsage"]; ok && v != nil { - usageList := v.([]any) - if len(usageList) > 0 { - for _, used := range usageList { - usedUnit := used.(map[string]any) - usedUnitList := usedUnit["usedUnitContainer"].([]any) - if len(usedUnitList) > 0 { - for _, data := range usedUnitList { - udata := data.(map[string]any) - if dup, dupOk := udata["dataVolumeUplink"]; dupOk { - dataVolumeUplink = append(dataVolumeUplink, fmt.Sprint(parse.Number(dup))) - } - if ddown, ddownOk := udata["dataVolumeDownlink"]; ddownOk { - dataVolumeDownlink = append(dataVolumeDownlink, fmt.Sprint(parse.Number(ddown))) - } - if dt, dtOk := udata["dataTotalVolume"]; dtOk { - dataTotalVolume = append(dataTotalVolume, fmt.Sprint(parse.Number(dt))) - } - } - } - } - } - } - // 时长 - duration := "-" - if v, ok := cdrJSON["duration"]; ok && v != nil { - duration = fmt.Sprint(parse.Number(v)) - } - // 调用时间 - invocationTimestamp := "" - if v, ok := cdrJSON["invocationTimestamp"]; ok && v != nil { - invocationTimestamp = v.(string) - } - // 记录打开时间 - User_Identifier := "" - SSC_Mode := "" - RAT_Type := "" - DNN_ID := "" - PDU_Type := "" - PDU_IPv4 := "" - PDU_IPv6 := "" - if v, ok := cdrJSON["pDUSessionChargingInformation"]; ok && v != nil { - pduInfo := v.(map[string]any) - - if v, ok := pduInfo["userIdentifier"]; ok && v != nil { - User_Identifier = v.(string) - } - if v, ok := pduInfo["sSCMode"]; ok && v != nil { - SSC_Mode = v.(string) - } - if v, ok := pduInfo["rATType"]; ok && v != nil { - RAT_Type = v.(string) - } - if v, ok := pduInfo["dNNID"]; ok && v != nil { - DNN_ID = v.(string) - } - if v, ok := pduInfo["pDUType"]; ok && v != nil { - PDU_Type = v.(string) - } - if v, ok := pduInfo["pDUAddress"]; ok && v != nil { - pDUAddress := v.(map[string]any) - if addr, ok := pDUAddress["pDUIPv4Address"]; ok && addr != nil { - PDU_IPv4 = addr.(string) - } - if addr, ok := pDUAddress["pDUIPv6AddresswithPrefix"]; ok && addr != nil { - PDU_IPv6 = addr.(string) - } - } - - // pduSessionChargingInformation = fmt.Sprintf(`User Identifier: %s - // SSC Mode: %s RAT Type: %s DNN ID: %s - // PDU Type: %s - // PDU IPv4 Address: %s - // PDU IPv6 Addres Swith Prefix: %s`, User_Identifier, SSC_Mode, RAT_Type, DNN_ID, PDU_Type, PDU_IPv4, PDU_IPv6) - } - - // 记录网络参数ID - recordNFID := "" - if v, ok := cdrJSON["recordingNetworkFunctionID"]; ok && v != nil { - recordNFID = v.(string) - } - - //记录开始时间 - recordOpeningTime := "" - if v, ok := cdrJSON["recordOpeningTime"]; ok && v != nil { - recordOpeningTime = v.(string) - } - - //记录类型 - recordType := "" - if v, ok := cdrJSON["recordType"]; ok && v != nil { - recordType = v.(string) - } - - dataCells = append(dataCells, map[string]any{ - "A" + idx: row.ID, - "B" + idx: chargingID, - "C" + idx: row.NeName, - "D" + idx: row.RmUID, - "E" + idx: subscriptionIDData, - "F" + idx: subscriptionIDType, - "G" + idx: strings.Join(dataVolumeUplink, ","), - "H" + idx: strings.Join(dataVolumeDownlink, ","), - "I" + idx: strings.Join(dataTotalVolume, ","), - "J" + idx: duration, - "K" + idx: invocationTimestamp, - "L" + idx: User_Identifier, - "M" + idx: SSC_Mode, - "N" + idx: DNN_ID, - "O" + idx: PDU_Type, - "P" + idx: RAT_Type, - "Q" + idx: PDU_IPv4, - "R" + idx: networkFunctionIPv4Address, - "S" + idx: PDU_IPv6, - "T" + idx: recordNFID, - "U" + idx: recordType, - "V" + idx: recordOpeningTime, - }) - } - // 导出数据表格 - saveFilePath, err := file.WriteSheet(headerCells, dataCells, fileName, "") + saveFilePath, err := s.cdrEventService.ExportXlsx(rows, fileName) if err != nil { c.JSON(200, result.ErrMsg(err.Error())) return @@ -393,7 +201,7 @@ func (s *SMFController) SubUserList(c *gin.Context) { imsiStr = strings.TrimPrefix(imsiStr, "imsi-") item["imsi"] = imsiStr // 查UDM拓展信息 - info := s.udmUserInfoService.SelectByIMSIAndNeID(imsiStr, "") + info := s.udmUserInfoService.SelectByIMSIAndNeID(imsiStr, "%") item["remark"] = info.Remark } if v, ok := item["msisdn"]; ok && v != nil { diff --git a/src/modules/network_data/service/cdr_event_sgwc.go b/src/modules/network_data/service/cdr_event_sgwc.go index 2e29f4d1..316024ea 100644 --- a/src/modules/network_data/service/cdr_event_sgwc.go +++ b/src/modules/network_data/service/cdr_event_sgwc.go @@ -1,8 +1,14 @@ package service import ( + "encoding/json" "fmt" + "strconv" + "strings" + "be.ems/src/framework/logger" + "be.ems/src/framework/utils/file" + "be.ems/src/framework/utils/parse" "be.ems/src/modules/network_data/model" "be.ems/src/modules/network_data/repository" ) @@ -37,3 +43,174 @@ func (r *CDREventSGWC) DeleteByIds(cdrIds []string) (int64, error) { // 删除信息失败! return 0, fmt.Errorf("delete fail") } + +// ExportXlsx 导出数据到 xlsx 文件 +func (r CDREventSGWC) ExportXlsx(rows []model.CDREventSGWC, fileName string) (string, error) { + // 第一行表头标题 + headerCells := map[string]string{ + "A1": "ID", + "B1": "NE Name", + "C1": "Resource Unique ID", + "D1": "Charging ID", + "E1": "IMSI", + "F1": "MSISDN", + "G1": "GPRS Uplink", + "H1": "GPRS Downlink", + "I1": "Duration", + "J1": "Invocation Time", + "K1": "PGW Address Used", + "L1": "SGW Address", + "M1": "RAT Type", + "N1": "PDPPDN Type", + "O1": "PDPPDN Address", + "P1": "Node Address", + "Q1": "Node Type", + "R1": "Record Access Point Name NI", + "S1": "Record Cause For Rec Closing", + "T1": "Record Sequence Number", + "U1": "Local Record Sequence Number", + } + // 从第二行开始的数据 + dataCells := make([]map[string]any, 0) + for i, row := range rows { + idx := strconv.Itoa(i + 2) + // 解析 JSON 字符串为 map + var cdrJSON map[string]interface{} + err := json.Unmarshal([]byte(row.CDRJSONStr), &cdrJSON) + if err != nil { + logger.Warnf("CDRExport Error parsing JSON: %s", err.Error()) + continue + } + // 计费ID + chargingID := "" + if v, ok := cdrJSON["chargingID"]; ok && v != nil { + chargingID = fmt.Sprint(parse.Number(v)) + } + // IMSI + servedIMSI := "" + if v, ok := cdrJSON["servedIMSI"]; ok && v != nil { + servedIMSI = fmt.Sprint(v) + } + // MSISDN + servedMSISDN := "" + if v, ok := cdrJSON["servedMSISDN"]; ok && v != nil { + servedMSISDN = fmt.Sprint(v) + } + // pGWAddressUsed + pGWAddressUsed := "" + if v, ok := cdrJSON["pGWAddressUsed"]; ok && v != nil { + pGWAddressUsed = fmt.Sprint(v) + } + // sGWAddress + sGWAddress := "" + if v, ok := cdrJSON["sGWAddress"]; ok && v != nil { + sGWAddress = fmt.Sprint(v) + } + // rATType + rATType := "" + if v, ok := cdrJSON["rATType"]; ok && v != nil { + rATType = fmt.Sprint(v) + } + // pdpPDNType + pdpPDNType := "" + if v, ok := cdrJSON["pdpPDNType"]; ok && v != nil { + pdpPDNType = fmt.Sprint(v) + } + // servedPDPPDNAddress + servedPDPPDNAddress := "" + if v, ok := cdrJSON["servedPDPPDNAddress"]; ok && v != nil { + servedPDPPDNAddress = fmt.Sprint(v) + } + // servedPDPPDNAddress + servingNodeAddress := []string{} + if v, ok := cdrJSON["servingNodeAddress"]; ok && v != nil { + for _, v := range v.([]any) { + servingNodeAddress = append(servingNodeAddress, fmt.Sprint(v)) + } + } + // servingNodeType + servingNodeType := []string{} + if v, ok := cdrJSON["servingNodeType"]; ok && v != nil { + for _, v := range v.([]any) { + if v, ok := v.(map[string]any)["servingNodeType"]; ok && v != nil { + servingNodeType = append(servingNodeType, fmt.Sprint(v)) + } + } + } + // accessPointNameNI + accessPointNameNI := "" + if v, ok := cdrJSON["accessPointNameNI"]; ok && v != nil { + accessPointNameNI = fmt.Sprint(v) + } + // causeForRecClosing + causeForRecClosing := "" + if v, ok := cdrJSON["causeForRecClosing"]; ok && v != nil { + causeForRecClosing = fmt.Sprint(v) + } + // recordSequenceNumber + recordSequenceNumber := "" + if v, ok := cdrJSON["recordSequenceNumber"]; ok && v != nil { + recordSequenceNumber = fmt.Sprint(v) + } + // localRecordSequenceNumber + localRecordSequenceNumber := "" + if v, ok := cdrJSON["localRecordSequenceNumber"]; ok && v != nil { + localRecordSequenceNumber = fmt.Sprint(v) + } + // 数据量上行链路 + var dataVolumeGPRSUplink int64 = 0 + // 数据量下行链路 + var dataVolumeGPRSDownlink int64 = 0 + if v, ok := cdrJSON["listOfTrafficVolumes"]; ok && v != nil { + usageList := v.([]any) + if len(usageList) > 0 { + for _, used := range usageList { + usedUnit := used.(map[string]any) + if dup, dupOk := usedUnit["dataVolumeGPRSUplink"]; dupOk { + dataVolumeGPRSUplink = parse.Number(dup) + } + if ddown, ddownOk := usedUnit["dataVolumeGPRSDownlink"]; ddownOk { + dataVolumeGPRSDownlink = parse.Number(ddown) + } + } + } + } + // 时长 + duration := "-" + if v, ok := cdrJSON["duration"]; ok && v != nil { + duration = fmt.Sprint(parse.Number(v)) + } + // 调用时间 + invocationTimestamp := "" + if v, ok := cdrJSON["recordOpeningTime"]; ok && v != nil { + invocationTimestamp = v.(string) + } + + dataCells = append(dataCells, map[string]any{ + "A" + idx: row.ID, + "B" + idx: row.NeName, + "C" + idx: row.RmUID, + "D" + idx: chargingID, + "E" + idx: servedIMSI, + "F" + idx: servedMSISDN, + "G" + idx: dataVolumeGPRSUplink, + "H" + idx: dataVolumeGPRSDownlink, + "I" + idx: duration, + "J" + idx: invocationTimestamp, + "K" + idx: pGWAddressUsed, + "L" + idx: sGWAddress, + "M" + idx: rATType, + "N" + idx: pdpPDNType, + "O" + idx: servedPDPPDNAddress, + "P" + idx: strings.Join(servingNodeAddress, ","), + "Q" + idx: strings.Join(servingNodeType, ","), + "R" + idx: accessPointNameNI, + "S" + idx: causeForRecClosing, + "T" + idx: recordSequenceNumber, + "U" + idx: localRecordSequenceNumber, + }) + } + + // 导出数据表格 + return file.WriteSheet(headerCells, dataCells, fileName, "") +} diff --git a/src/modules/network_data/service/cdr_event_smf.go b/src/modules/network_data/service/cdr_event_smf.go index 02fb8f4b..cbc20769 100644 --- a/src/modules/network_data/service/cdr_event_smf.go +++ b/src/modules/network_data/service/cdr_event_smf.go @@ -1,8 +1,13 @@ package service import ( + "encoding/json" "fmt" + "strconv" + "be.ems/src/framework/logger" + "be.ems/src/framework/utils/file" + "be.ems/src/framework/utils/parse" "be.ems/src/modules/network_data/model" "be.ems/src/modules/network_data/repository" ) @@ -37,3 +42,190 @@ func (r *CDREventSMF) DeleteByIds(cdrIds []string) (int64, error) { // 删除信息失败! return 0, fmt.Errorf("delete fail") } + +// ExportXlsx 导出数据到 xlsx 文件 +func (r CDREventSMF) ExportXlsx(rows []model.CDREventSMF, fileName string) (string, error) { + // 第一行表头标题 + headerCells := map[string]string{ + "A1": "ID", + "B1": "Charging ID", + "C1": "NE Name", + "D1": "Resource Unique ID", + "E1": "Subscriber ID Data", + "F1": "Subscriber ID Type", + "G1": "Data Volume Uplink", + "H1": "Data Volume Downlink", + "I1": "Data Total Volume", + "J1": "Duration", + "K1": "Invocation Time", + "L1": "User Identifier", + "M1": "SSC Mode", + "N1": "DNN ID", + "O1": "PDU Type", + "P1": "RAT Type", + "Q1": "PDU IPv4 Address", + "R1": "Network Function IPv4", + "S1": "PDU IPv6 Address Swith Prefix", + "T1": "Record Network Function ID", + "U1": "Record Type", + "V1": "Record Opening Time", + } + // 从第二行开始的数据 + dataCells := make([]map[string]any, 0) + + for i, row := range rows { + idx := strconv.Itoa(i + 2) + // 解析 JSON 字符串为 map + var cdrJSON map[string]interface{} + err := json.Unmarshal([]byte(row.CDRJSONStr), &cdrJSON) + if err != nil { + logger.Warnf("CDRExport Error parsing JSON: %s", err.Error()) + continue + } + // 计费ID + chargingID := "" + if v, ok := cdrJSON["chargingID"]; ok && v != nil { + chargingID = fmt.Sprint(parse.Number(v)) + } + // 订阅 ID 类型 + subscriptionIDType := "-" + // 订阅 ID 数据 + subscriptionIDData := "-" + if v, ok := cdrJSON["subscriberIdentifier"]; ok && v != nil { + if sub, subOk := v.(map[string]any); subOk && sub != nil { + subscriptionIDType = sub["subscriptionIDType"].(string) + subscriptionIDData = sub["subscriptionIDData"].(string) + } + } + + // 网络功能 IPv4 地址 + networkFunctionIPv4Address := "" + if v, ok := cdrJSON["nFunctionConsumerInformation"]; ok && v != nil { + if conInfo, conInfoOk := v.(map[string]any); conInfoOk && conInfo != nil { + networkFunctionIPv4Address = conInfo["networkFunctionIPv4Address"].(string) + } + } + + // 数据量上行链路 + var dataVolumeUplink int64 = 0 + // 数据量下行链路 + var dataVolumeDownlink int64 = 0 + // 数据总量 + var dataTotalVolume int64 = 0 + if v, ok := cdrJSON["listOfMultipleUnitUsage"]; ok && v != nil { + usageList := v.([]any) + if len(usageList) > 0 { + for _, used := range usageList { + usedUnit := used.(map[string]any) + usedUnitList := usedUnit["usedUnitContainer"].([]any) + if len(usedUnitList) > 0 { + for _, data := range usedUnitList { + udata := data.(map[string]any) + if dup, dupOk := udata["dataVolumeUplink"]; dupOk { + dataVolumeUplink += parse.Number(dup) + } + if ddown, ddownOk := udata["dataVolumeDownlink"]; ddownOk { + dataVolumeDownlink += parse.Number(ddown) + } + if dt, dtOk := udata["dataTotalVolume"]; dtOk { + dataTotalVolume += parse.Number(dt) + } + } + } + } + } + } + // 时长 + duration := "-" + if v, ok := cdrJSON["duration"]; ok && v != nil { + duration = fmt.Sprint(parse.Number(v)) + } + // 调用时间 + invocationTimestamp := "" + if v, ok := cdrJSON["invocationTimestamp"]; ok && v != nil { + invocationTimestamp = v.(string) + } + // 记录打开时间 + User_Identifier := "" + SSC_Mode := "" + RAT_Type := "" + DNN_ID := "" + PDU_Type := "" + PDU_IPv4 := "" + PDU_IPv6 := "" + if v, ok := cdrJSON["pDUSessionChargingInformation"]; ok && v != nil { + pduInfo := v.(map[string]any) + + if v, ok := pduInfo["userIdentifier"]; ok && v != nil { + User_Identifier = v.(string) + } + if v, ok := pduInfo["sSCMode"]; ok && v != nil { + SSC_Mode = v.(string) + } + if v, ok := pduInfo["rATType"]; ok && v != nil { + RAT_Type = v.(string) + } + if v, ok := pduInfo["dNNID"]; ok && v != nil { + DNN_ID = v.(string) + } + if v, ok := pduInfo["pDUType"]; ok && v != nil { + PDU_Type = v.(string) + } + if v, ok := pduInfo["pDUAddress"]; ok && v != nil { + pDUAddress := v.(map[string]any) + if addr, ok := pDUAddress["pDUIPv4Address"]; ok && addr != nil { + PDU_IPv4 = addr.(string) + } + if addr, ok := pDUAddress["pDUIPv6AddresswithPrefix"]; ok && addr != nil { + PDU_IPv6 = addr.(string) + } + } + } + + // 记录网络参数ID + recordNFID := "" + if v, ok := cdrJSON["recordingNetworkFunctionID"]; ok && v != nil { + recordNFID = v.(string) + } + + //记录开始时间 + recordOpeningTime := "" + if v, ok := cdrJSON["recordOpeningTime"]; ok && v != nil { + recordOpeningTime = v.(string) + } + + //记录类型 + recordType := "" + if v, ok := cdrJSON["recordType"]; ok && v != nil { + recordType = v.(string) + } + + dataCells = append(dataCells, map[string]any{ + "A" + idx: row.ID, + "B" + idx: chargingID, + "C" + idx: row.NeName, + "D" + idx: row.RmUID, + "E" + idx: subscriptionIDData, + "F" + idx: subscriptionIDType, + "G" + idx: dataVolumeUplink, + "H" + idx: dataVolumeDownlink, + "I" + idx: dataTotalVolume, + "J" + idx: duration, + "K" + idx: invocationTimestamp, + "L" + idx: User_Identifier, + "M" + idx: SSC_Mode, + "N" + idx: DNN_ID, + "O" + idx: PDU_Type, + "P" + idx: RAT_Type, + "Q" + idx: PDU_IPv4, + "R" + idx: networkFunctionIPv4Address, + "S" + idx: PDU_IPv6, + "T" + idx: recordNFID, + "U" + idx: recordType, + "V" + idx: recordOpeningTime, + }) + } + + // 导出数据表格 + return file.WriteSheet(headerCells, dataCells, fileName, "") +}