feat: UDM鉴权文件导入K4文件支持
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/network_data/model"
|
||||
neDataService "be.ems/src/modules/network_data/service"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
@@ -411,7 +412,11 @@ func (s *UDMAuthController) Export(c *gin.Context) {
|
||||
data := [][]string{}
|
||||
data = append(data, []string{"imsi", "ki", "algo", "amf", "opc"})
|
||||
for _, v := range list {
|
||||
data = append(data, []string{v.IMSI, v.Ki, v.AlgoIndex, v.Amf, v.Opc})
|
||||
opc := v.Opc
|
||||
if opc == "-" {
|
||||
opc = ""
|
||||
}
|
||||
data = append(data, []string{v.IMSI, v.Ki, v.AlgoIndex, v.Amf, opc})
|
||||
}
|
||||
// 输出到文件
|
||||
err := file.WriterFileCSV(data, filePath)
|
||||
@@ -425,7 +430,11 @@ func (s *UDMAuthController) Export(c *gin.Context) {
|
||||
// 转换数据
|
||||
data := [][]string{}
|
||||
for _, v := range list {
|
||||
data = append(data, []string{v.IMSI, v.Ki, v.AlgoIndex, v.Amf, v.Opc})
|
||||
opc := v.Opc
|
||||
if opc == "-" {
|
||||
opc = ""
|
||||
}
|
||||
data = append(data, []string{v.IMSI, v.Ki, v.AlgoIndex, v.Amf, opc})
|
||||
}
|
||||
// 输出到文件
|
||||
err = file.WriterFileTXT(data, ",", filePath)
|
||||
@@ -446,6 +455,8 @@ func (s *UDMAuthController) Import(c *gin.Context) {
|
||||
var body struct {
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
UploadPath string `json:"uploadPath" binding:"required"`
|
||||
TypeVal string `json:"typeVal" binding:"required,oneof=default k4"`
|
||||
TypeData any `json:"typeData"`
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
@@ -497,16 +508,30 @@ func (s *UDMAuthController) Import(c *gin.Context) {
|
||||
}
|
||||
defer telnetClient.Close()
|
||||
|
||||
// 发送MML
|
||||
cmd := fmt.Sprintf("import authdat:path=%s", neFilePath)
|
||||
data, err := telnet.ConvertToStr(telnetClient, cmd)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
// 结果信息
|
||||
var resultMsg string
|
||||
var resultErr error
|
||||
|
||||
// 默认的情况 发送MML
|
||||
if body.TypeVal == "default" {
|
||||
cmd := fmt.Sprintf("import authdat:path=%s", neFilePath)
|
||||
resultMsg, resultErr = telnet.ConvertToStr(telnetClient, cmd)
|
||||
}
|
||||
|
||||
// K4类型发特定请求
|
||||
if body.TypeVal == "k4" {
|
||||
resultMsg, resultErr = neFetchlink.UDMImportAuth(neInfo.IP, map[string]any{
|
||||
"path": neFilePath, "k4": body.TypeData,
|
||||
})
|
||||
}
|
||||
|
||||
if resultErr != nil {
|
||||
c.JSON(200, result.ErrMsg(resultErr.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.Contains(resultMsg, "ok") {
|
||||
if strings.HasSuffix(body.UploadPath, ".csv") {
|
||||
data := file.ReadFileCSV(localFilePath)
|
||||
neId := ""
|
||||
@@ -518,5 +543,5 @@ func (s *UDMAuthController) Import(c *gin.Context) {
|
||||
go s.udmAuthService.InsertData(neId, "txt", data)
|
||||
}
|
||||
}
|
||||
c.JSON(200, result.OkMsg(data))
|
||||
c.JSON(200, result.OkMsg(resultMsg))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user