feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -6,8 +6,9 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
@@ -34,47 +35,49 @@ type NeLicenseController struct {
|
||||
// @Tags network_element/license
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string false "NE ID"
|
||||
// @Param expiryDate query string false "ExpiryDate"
|
||||
// @Param pageNum query number true "pageNum" default(1)
|
||||
// @Param pageSize query number true "pageSize" default(10)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
// @Summary Net Element License Activation List
|
||||
// @Description Net Element License Activation List
|
||||
// @Router /ne/license/list [get]
|
||||
func (s *NeLicenseController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neLicenseService.SelectPage(querys)
|
||||
query := reqctx.QueryMap(c)
|
||||
rows, total := s.neLicenseService.FindByPage(query)
|
||||
|
||||
// 过滤屏蔽授权文件
|
||||
rows := data["rows"].([]model.NeLicense)
|
||||
arr := &rows
|
||||
for i := range *arr {
|
||||
(*arr)[i].ActivationRequestCode = "-"
|
||||
(*arr)[i].LicensePath = "-"
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
|
||||
}
|
||||
|
||||
// 网元授权激活信息
|
||||
//
|
||||
// GET /:licenseId
|
||||
// GET /:id
|
||||
func (s *NeLicenseController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
licenseId := c.Param("licenseId")
|
||||
if licenseId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := parse.Number(c.Param("id"))
|
||||
if id <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
neLicense := s.neLicenseService.SelectById(licenseId)
|
||||
if neLicense.ID != licenseId {
|
||||
neLicense := s.neLicenseService.FindById(id)
|
||||
if neLicense.ID != id {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neLicense))
|
||||
c.JSON(200, resp.OkData(neLicense))
|
||||
}
|
||||
|
||||
// 网元neType和neID查询
|
||||
@@ -84,7 +87,7 @@ func (s *NeLicenseController) Info(c *gin.Context) {
|
||||
// @Tags network_element/license
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
@@ -92,24 +95,25 @@ func (s *NeLicenseController) Info(c *gin.Context) {
|
||||
// @Description Network element neType and neID queries
|
||||
// @Router /ne/license/byTypeAndID [get]
|
||||
func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeId string `form:"neId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
neLicense := s.neLicenseService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neLicense.NeId != querys.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neLicense))
|
||||
c.JSON(200, resp.OkData(neLicense))
|
||||
}
|
||||
|
||||
// 网元授权激活授权申请码
|
||||
@@ -119,7 +123,7 @@ func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
|
||||
// @Tags network_element/license
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
@@ -127,21 +131,21 @@ func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
|
||||
// @Description Network Element License Activation License Application Code
|
||||
// @Router /ne/license/code [get]
|
||||
func (s *NeLicenseController) Code(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeId string `form:"neId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在授权记录
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
neLicense := s.neLicenseService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neLicense.NeId != querys.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -155,10 +159,10 @@ func (s *NeLicenseController) Code(c *gin.Context) {
|
||||
neLicense.ExpiryDate = ""
|
||||
neLicense.Status = "0"
|
||||
}
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
s.neLicenseService.Update(neLicense)
|
||||
|
||||
c.JSON(200, result.OkData(code))
|
||||
c.JSON(200, resp.OkData(code))
|
||||
}
|
||||
|
||||
// 网元授权激活授权文件替换
|
||||
@@ -175,19 +179,19 @@ func (s *NeLicenseController) Code(c *gin.Context) {
|
||||
// @Description Network element authorization activation status
|
||||
// @Router /ne/license/change [post]
|
||||
func (s *NeLicenseController) Change(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.NeLicense
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil || body.LicensePath == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在授权记录
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
neLicense := s.neLicenseService.FindByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neLicense.NeId != body.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -197,19 +201,19 @@ func (s *NeLicenseController) Change(c *gin.Context) {
|
||||
}
|
||||
neLicense.LicensePath = body.LicensePath
|
||||
neLicense.Status = "0"
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
upRows := s.neLicenseService.Update(neLicense)
|
||||
if upRows > 0 {
|
||||
// 进行上传替换
|
||||
err = s.neLicenseService.UploadLicense(body)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 网元授权激活状态
|
||||
@@ -219,7 +223,7 @@ func (s *NeLicenseController) Change(c *gin.Context) {
|
||||
// @Tags network_element/license
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
@@ -227,28 +231,28 @@ func (s *NeLicenseController) Change(c *gin.Context) {
|
||||
// @Description Network element authorization activation status
|
||||
// @Router /ne/license/state [get]
|
||||
func (s *NeLicenseController) State(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeId string `form:"neId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在授权记录
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
neLicense := s.neLicenseService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neLicense.NeId != querys.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP获取网元状态
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
|
||||
neInfo := s.neInfoService.FindByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
|
||||
if neInfo.NeId != neLicense.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
if neState, err := neFetchlink.NeState(neInfo); err == nil && neState["sn"] != nil {
|
||||
@@ -263,15 +267,15 @@ func (s *NeLicenseController) State(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 更新授权信息
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
s.neLicenseService.Update(neLicense)
|
||||
|
||||
if neLicense.Status == "1" {
|
||||
c.JSON(200, result.OkData(map[string]string{
|
||||
c.JSON(200, resp.OkData(map[string]string{
|
||||
"sn": neLicense.SerialNum,
|
||||
"expire": neLicense.ExpiryDate,
|
||||
}))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
|
||||
c.JSON(200, resp.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user