fix: issue of export udm sub user not filter

This commit is contained in:
2024-10-17 14:58:41 +08:00
parent e0fd3004e9
commit c49df70eb8
2 changed files with 66 additions and 34 deletions

View File

@@ -369,32 +369,46 @@ func (s *UDMAuthController) Removes(c *gin.Context) {
// POST /export
func (s *UDMAuthController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
NeId string `json:"neId" binding:"required"`
Type string `json:"type" binding:"required"`
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
neId := querys["neId"].(string)
fileType := querys["type"].(string)
if neId == "" || fileType == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if !(body.Type == "csv" || body.Type == "txt") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errExportType")))
if !(fileType == "csv" || fileType == "txt") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
return
}
querys["pageNum"] = 1
querys["pageSize"] = 10000
querys["neId"] = ""
data := s.udmAuthService.SelectPage(querys)
if parse.Number(data["total"]) == 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.UDMAuthUser)
// rows := s.udmAuthService.SelectList(model.UDMAuthUser{NeId: neId})
if len(rows) <= 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
neId := ""
list := s.udmAuthService.SelectList(model.UDMAuthUser{NeId: neId})
// 文件名
fileName := fmt.Sprintf("udm_auth_user_export_%s_%d.%s", neId, time.Now().UnixMilli(), body.Type)
fileName := fmt.Sprintf("udm_auth_user_export_%s_%d.%s", neId, time.Now().UnixMilli(), fileType)
filePath := fmt.Sprintf("%s/%s", file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
if body.Type == "csv" {
if fileType == "csv" {
// 转换数据
data := [][]string{}
data = append(data, []string{"imsi", "ki", "algo", "amf", "opc"})
for _, v := range list {
for _, v := range rows {
opc := v.Opc
if opc == "-" {
opc = ""
@@ -409,10 +423,10 @@ func (s *UDMAuthController) Export(c *gin.Context) {
}
}
if body.Type == "txt" {
if fileType == "txt" {
// 转换数据
data := [][]string{}
for _, v := range list {
for _, v := range rows {
opc := v.Opc
if opc == "-" {
opc = ""
@@ -420,7 +434,7 @@ func (s *UDMAuthController) Export(c *gin.Context) {
data = append(data, []string{v.IMSI, v.Ki, v.AlgoIndex, v.Amf, opc})
}
// 输出到文件
err = file.WriterFileTXT(data, ",", filePath)
err := file.WriterFileTXT(data, ",", filePath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return

View File

@@ -427,52 +427,70 @@ func (s *UDMSubController) Removes(c *gin.Context) {
// POST /export
func (s *UDMSubController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
NeId string `json:"neId" binding:"required"`
Type string `json:"type" binding:"required"`
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
neId := querys["neId"].(string)
fileType := querys["type"].(string)
if neId == "" || fileType == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if !(body.Type == "csv" || body.Type == "txt") {
if !(fileType == "csv" || fileType == "txt") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
return
}
neId := ""
list := s.udmSubService.SelectList(model.UDMSubUser{NeId: neId})
querys["pageNum"] = 1
querys["pageSize"] = 10000
// for multi-tenancy
querys["userName"] = ctx.LoginUserToUserName(c)
querys["neId"] = ""
data := s.udmSubService.SelectPage(querys)
if parse.Number(data["total"]) == 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.UDMSubUser)
// rows := s.udmSubService.SelectList(model.UDMSubUser{NeId: neId})
if len(rows) <= 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
// 文件名
fileName := fmt.Sprintf("udm_sub_user_export_%s_%d.%s", neId, time.Now().UnixMilli(), body.Type)
fileName := fmt.Sprintf("udm_sub_user_export_%s_%d.%s", neId, time.Now().UnixMilli(), fileType)
filePath := fmt.Sprintf("%s/%s", file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
if body.Type == "csv" {
if fileType == "csv" {
// 转换数据
data := [][]string{}
data = append(data, []string{"imsi", "msisdn", "ambr", "nssai", "arfb", "sar", "rat", "cn", "smf_sel", "sm_dat", "eps_dat", "tenant_name"})
for _, v := range list {
for _, v := range rows {
epsDat := fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s", v.EpsFlag, v.EpsOdb, v.HplmnOdb, v.Ard, v.Epstpl, v.ContextId, v.ApnContext, v.StaticIp)
data = append(data, []string{v.IMSI, v.MSISDN, v.Ambr, v.Nssai, v.Arfb, v.Sar, v.Rat, v.Cn, v.SmfSel, v.SmData, epsDat, v.TenantName})
}
// 输出到文件
err = file.WriterFileCSV(data, filePath)
err := file.WriterFileCSV(data, filePath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
}
if body.Type == "txt" {
if fileType == "txt" {
// 转换数据
data := [][]string{}
for _, v := range list {
for _, v := range rows {
epsDat := fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s", v.EpsFlag, v.EpsOdb, v.HplmnOdb, v.Ard, v.Epstpl, v.ContextId, v.ApnContext, v.StaticIp)
data = append(data, []string{v.IMSI, v.MSISDN, v.Ambr, v.Nssai, v.Arfb, v.Sar, v.Rat, v.Cn, v.SmfSel, v.SmData, epsDat, v.TenantName})
}
// 输出到文件
err = file.WriterFileTXT(data, ",", filePath)
err := file.WriterFileTXT(data, ",", filePath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return