291 lines
9.3 KiB
Go
291 lines
9.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"be.ems/src/framework/i18n"
|
|
"be.ems/src/framework/reqctx"
|
|
"be.ems/src/framework/resp"
|
|
"be.ems/src/framework/utils/parse"
|
|
"be.ems/src/modules/network_element/model"
|
|
neService "be.ems/src/modules/network_element/service"
|
|
neFetchlink "be.ems/src/modules/network_link/fetch_link"
|
|
)
|
|
|
|
// 实例化控制层 NeLicenseController 结构体
|
|
var NewNeLicense = &NeLicenseController{
|
|
neLicenseService: neService.NewNeLicense,
|
|
neInfoService: neService.NewNeInfo,
|
|
}
|
|
|
|
// 网元授权激活请求
|
|
//
|
|
// PATH /license
|
|
type NeLicenseController struct {
|
|
neLicenseService *neService.NeLicense // 网元授权激活服务
|
|
neInfoService *neService.NeInfo // 网元信息服务
|
|
}
|
|
|
|
// 网元授权激活列表
|
|
//
|
|
// GET /list
|
|
//
|
|
// @Tags network_element/license
|
|
// @Accept json
|
|
// @Produce json
|
|
// @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) {
|
|
query := reqctx.QueryMap(c)
|
|
rows, total := s.neLicenseService.FindByPage(query)
|
|
|
|
// 过滤屏蔽授权文件
|
|
arr := &rows
|
|
for i := range *arr {
|
|
(*arr)[i].ActivationRequestCode = "-"
|
|
(*arr)[i].LicensePath = "-"
|
|
}
|
|
|
|
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
|
|
}
|
|
|
|
// 网元授权激活信息
|
|
//
|
|
// GET /:id
|
|
func (s *NeLicenseController) Info(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
id := parse.Number(c.Param("id"))
|
|
if id <= 0 {
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: id is empty"))
|
|
return
|
|
}
|
|
|
|
neLicense := s.neLicenseService.FindById(id)
|
|
if neLicense.ID != id {
|
|
// 没有可访问网元授权激活数据!
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
|
return
|
|
}
|
|
|
|
c.JSON(200, resp.OkData(neLicense))
|
|
}
|
|
|
|
// 网元信息查询
|
|
//
|
|
// GET /nf
|
|
//
|
|
// @Tags network_element/license
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param coreUid query string true "CoreUID" default(8I73Y01Z)
|
|
// @Param neUid query string true "NeUID" default(5AKF59BZ)
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary Network element neType and neID queries
|
|
// @Description Network element neType and neID queries
|
|
// @Router /ne/license/nf [get]
|
|
func (s *NeLicenseController) Nf(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
var querys struct {
|
|
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
|
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
|
}
|
|
if err := c.ShouldBindQuery(&querys); err != nil {
|
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
|
return
|
|
}
|
|
|
|
neLicense := s.neLicenseService.FindByCoreUidAndNeUid(querys.CoreUID, querys.NeUID)
|
|
if neLicense.CoreUID != querys.CoreUID || neLicense.NeUID != querys.NeUID {
|
|
// 没有可访问网元授权激活数据!
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
|
return
|
|
}
|
|
|
|
c.JSON(200, resp.OkData(neLicense))
|
|
}
|
|
|
|
// 网元授权激活授权申请码
|
|
//
|
|
// GET /code
|
|
//
|
|
// @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,SMSC)
|
|
// @Param neId query string true "NE ID" default(001)
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary Network Element License Activation License Application Code
|
|
// @Description Network Element License Activation License Application Code
|
|
// @Router /ne/license/code [get]
|
|
func (s *NeLicenseController) Code(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
var querys struct {
|
|
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
|
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
|
}
|
|
if err := c.ShouldBindQuery(&querys); err != nil {
|
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
|
return
|
|
}
|
|
|
|
// 检查是否存在授权记录
|
|
neLicense := s.neLicenseService.FindByCoreUidAndNeUid(querys.CoreUID, querys.NeUID)
|
|
if neLicense.CoreUID != querys.CoreUID || neLicense.NeUID != querys.NeUID {
|
|
// 没有可访问网元授权激活数据!
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
|
return
|
|
}
|
|
|
|
// 更新授权码
|
|
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
|
neLicense.ActivationRequestCode = code
|
|
if licensePath != "" {
|
|
neLicense.LicensePath = licensePath
|
|
} else {
|
|
neLicense.Capability = 0
|
|
neLicense.SerialNum = ""
|
|
neLicense.ExpiryDate = ""
|
|
neLicense.Status = "0"
|
|
}
|
|
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
|
|
s.neLicenseService.Update(neLicense)
|
|
|
|
c.JSON(200, resp.OkData(code))
|
|
}
|
|
|
|
// 网元授权激活授权文件替换
|
|
//
|
|
// POST /change
|
|
//
|
|
// @Tags network_element/license
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param data body object true "Request Param"
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary Network element authorization activation status
|
|
// @Description Network element authorization activation status
|
|
// @Router /ne/license/change [post]
|
|
func (s *NeLicenseController) Change(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
var body model.NeLicense
|
|
err := c.ShouldBindBodyWithJSON(&body)
|
|
if err != nil || body.LicensePath == "" {
|
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
|
return
|
|
}
|
|
|
|
// 检查是否存在授权记录
|
|
neLicense := s.neLicenseService.FindByCoreUidAndNeUid(body.CoreUID, body.NeUID)
|
|
if neLicense.CoreUID != body.CoreUID || neLicense.NeUID != body.NeUID {
|
|
// 没有可访问网元授权激活数据!
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
|
return
|
|
}
|
|
|
|
// 更新授权记录
|
|
if body.Remark != "" {
|
|
neLicense.Remark = body.Remark
|
|
}
|
|
neLicense.LicensePath = body.LicensePath
|
|
neLicense.Status = "0"
|
|
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
|
|
upRows := s.neLicenseService.Update(neLicense)
|
|
if upRows > 0 {
|
|
// 进行上传替换
|
|
err = s.neLicenseService.UploadLicense(body)
|
|
if err != nil {
|
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
|
return
|
|
}
|
|
c.JSON(200, resp.Ok(nil))
|
|
return
|
|
}
|
|
c.JSON(200, resp.Err(nil))
|
|
}
|
|
|
|
// 网元授权激活状态
|
|
//
|
|
// GET /state
|
|
//
|
|
// @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,SMSC)
|
|
// @Param neId query string true "NE ID" default(001)
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary Network element authorization activation status
|
|
// @Description Network element authorization activation status
|
|
// @Router /ne/license/state [get]
|
|
func (s *NeLicenseController) State(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
var querys struct {
|
|
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
|
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
|
}
|
|
if err := c.ShouldBindQuery(&querys); err != nil {
|
|
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
|
return
|
|
}
|
|
|
|
// 检查是否存在授权记录
|
|
neLicense := s.neLicenseService.FindByCoreUidAndNeUid(querys.CoreUID, querys.NeUID)
|
|
if neLicense.CoreUID != querys.CoreUID || neLicense.NeUID != querys.NeUID {
|
|
// 没有可访问网元授权激活数据!
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
|
return
|
|
}
|
|
|
|
// 查询网元获取IP获取网元状态
|
|
neInfo := s.neInfoService.FindByCoreUidAndNeUid(neLicense.CoreUID, neLicense.NeUID)
|
|
if neInfo.CoreUID != neLicense.CoreUID || neInfo.NeUID != neLicense.NeUID {
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
|
return
|
|
}
|
|
if neState, err := neFetchlink.NeState(neInfo); err == nil && neState["sn"] != nil {
|
|
neLicense.Status = "1"
|
|
neLicense.Capability = parse.Number(neState["capability"])
|
|
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
|
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
|
} else {
|
|
neLicense.Status = "0"
|
|
}
|
|
// 更新授权码
|
|
if neLicense.ActivationRequestCode == "" || strings.HasPrefix(neLicense.ActivationRequestCode, "SN") || neLicense.Status == "0" {
|
|
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
|
neLicense.ActivationRequestCode = code
|
|
neLicense.LicensePath = licensePath
|
|
}
|
|
|
|
// 更新授权信息
|
|
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
|
|
s.neLicenseService.Update(neLicense)
|
|
|
|
if neLicense.Status == "1" {
|
|
c.JSON(200, resp.OkData(map[string]any{
|
|
"capability": neLicense.Capability,
|
|
"sn": neLicense.SerialNum,
|
|
"expire": neLicense.ExpiryDate,
|
|
}))
|
|
return
|
|
}
|
|
c.JSON(200, resp.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
|
|
}
|