del: 移除网元授权新增修改删除接口
This commit is contained in:
@@ -2,11 +2,9 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
@@ -69,104 +67,6 @@ func (s *NeLicenseController) Info(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(neLicense))
|
||||
}
|
||||
|
||||
// 网元授权激活信息新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeLicenseController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeLicense
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.neLicenseService.CheckUniqueTypeAndID(body.NeType, body.NeId, "")
|
||||
if !uniqueInfo {
|
||||
// 网元授权激活操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neLicense.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 读取授权码
|
||||
code, _ := s.neLicenseService.ReadLicenseInfo(body)
|
||||
body.ActivationRequestCode = code
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.neLicenseService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元授权激活信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeLicenseController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeLicense
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.neLicenseService.CheckUniqueTypeAndID(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueInfo {
|
||||
// 网元授权激活操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neLicense.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neLicense := s.neLicenseService.SelectById(body.ID)
|
||||
if neLicense.ID != body.ID {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neLicenseService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元授权激活信息删除
|
||||
//
|
||||
// DELETE /:licenseIds
|
||||
func (s *NeLicenseController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
licenseIds := c.Param("licenseIds")
|
||||
if licenseIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(licenseIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neLicenseService.DeleteByIds(uniqueIDs)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 网元neType和neID查询
|
||||
//
|
||||
// GET /byTypeAndID
|
||||
|
||||
@@ -21,7 +21,4 @@ type INeLicense interface {
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) int64
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neLicense model.NeLicense) string
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -177,41 +176,6 @@ func (r *NeLicenseImpl) SelectByIds(cmdIds []string) []model.NeLicense {
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
func (r *NeLicenseImpl) CheckUniqueTypeAndID(neLicense model.NeLicense) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neLicense.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neLicense.NeType)
|
||||
}
|
||||
if neLicense.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neLicense.NeId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select id as 'str' from ne_license " + whereSql + " limit 1"
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err %v", err)
|
||||
return ""
|
||||
}
|
||||
if len(results) > 0 {
|
||||
return fmt.Sprint(results[0]["str"])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeLicenseImpl) Insert(neLicense model.NeLicense) string {
|
||||
// 参数拼接
|
||||
|
||||
@@ -22,9 +22,6 @@ type INeLicense interface {
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) (int64, error)
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neType, neId, id string) bool
|
||||
|
||||
// SelectByNeTypeAndNeID 通过ne_type和ne_id查询信息
|
||||
SelectByNeTypeAndNeID(neType, neId string) model.NeLicense
|
||||
|
||||
|
||||
@@ -84,18 +84,6 @@ func (r *NeLicenseImpl) SelectByTypeAndID(neType, neId string) model.NeLicense {
|
||||
return model.NeLicense{}
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
func (r *NeLicenseImpl) CheckUniqueTypeAndID(neType, neId, id string) bool {
|
||||
uniqueId := r.neLicenseRepository.CheckUniqueTypeAndID(model.NeLicense{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
|
||||
// SelectByNeTypeAndNeID 通过ne_type和ne_id查询信息
|
||||
func (r *NeLicenseImpl) SelectByNeTypeAndNeID(neType, neId string) model.NeLicense {
|
||||
neLicenses := r.neLicenseRepository.SelectList(model.NeLicense{
|
||||
|
||||
Reference in New Issue
Block a user