ref: v3变更,,网元关联核心网
This commit is contained in:
@@ -5,9 +5,9 @@ DROP TABLE IF EXISTS `core_info`;
|
||||
CREATE TABLE `core_info` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '核心网ID',
|
||||
`core_uid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '核心网唯一标识',
|
||||
`name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '核心网名称',
|
||||
`core_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '核心网名称',
|
||||
`sn` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '核心网序列号',
|
||||
`omc_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'OMC安装生成的唯一编码',
|
||||
`core_omc` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '核心网所在OMC唯一编码',
|
||||
`time_zone` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '时区',
|
||||
`longitude` float DEFAULT '0' COMMENT '经度 -180 to 180',
|
||||
`latitude` float DEFAULT '0' COMMENT '纬度 -90 to 90',
|
||||
|
||||
@@ -9,7 +9,7 @@ CREATE TABLE `ne_info` (
|
||||
`update_by` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者',
|
||||
`update_time` bigint DEFAULT '0' COMMENT '更新时间',
|
||||
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '备注',
|
||||
`core_id` bigint DEFAULT '0' COMMENT '核心网ID 1为全局默认',
|
||||
`core_id` bigint DEFAULT '0' COMMENT '核心网ID 0为默认',
|
||||
`ne_uid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元唯一标识',
|
||||
`ne_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '网元类型',
|
||||
`ne_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元名称',
|
||||
|
||||
@@ -24,6 +24,8 @@ const (
|
||||
CACHE_I18N = "i18n"
|
||||
// CACHE_NE_INFO 网元信息管理 ne_info:ne_type:ne_id:ne_uid
|
||||
CACHE_NE_INFO = "ne_info"
|
||||
// CACHE_NE_CORE 核心网信息管理 ne_core:sn:core_id:core_uid
|
||||
CACHE_NE_CORE = "ne_core"
|
||||
// CACHE_NE_DATA 网元数据管理 ne_data:{x}:{x}:{x}
|
||||
CACHE_NE_DATA = "ne_data"
|
||||
)
|
||||
|
||||
@@ -107,9 +107,10 @@ func processSQLFile(db *gorm.DB, filePath string) {
|
||||
// 忽略重复记录错误
|
||||
// Error 1062 (23000): Duplicate entry 'value' for key 'key_name'
|
||||
log.Println(err.Error())
|
||||
} else if strings.Contains(errorStr, "unknown column") {
|
||||
} else if strings.Contains(errorStr, "unknown column") || strings.Contains(errorStr, "no such column") {
|
||||
// 忽略未知字段错误
|
||||
// Error 1054 (42S22): Unknown column 'field_name' in 'table'
|
||||
// sql logic error: no such column: "field_name" (1)
|
||||
} else if strings.Contains(errorStr, "can't drop") {
|
||||
// 忽略删除字段或索引错误
|
||||
// Error 1091 (42000): Can't DROP COLUMN `field_name`; check that it exists
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/ne/model"
|
||||
"be.ems/src/modules/ne/service"
|
||||
coreService "be.ems/src/modules/ne_core/service"
|
||||
neFetchlink "be.ems/src/modules/ne_data_nf/fetch_link"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
// 实例化控制层 NeInfoController 结构体
|
||||
var NewNeInfo = &NeInfoController{
|
||||
neInfoService: service.NewNeInfo,
|
||||
coreInfoService: coreService.NewCoreInfo,
|
||||
}
|
||||
|
||||
// 网元信息请求
|
||||
@@ -25,6 +27,7 @@ var NewNeInfo = &NeInfoController{
|
||||
// PATH /info
|
||||
type NeInfoController struct {
|
||||
neInfoService *service.NeInfo // 网元信息服务
|
||||
coreInfoService *coreService.CoreInfo
|
||||
}
|
||||
|
||||
// neStateCacheMap 网元状态缓存最后一次成功的信息
|
||||
@@ -122,6 +125,14 @@ func (s NeInfoController) Nf(c *gin.Context) {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 关联核心网信息
|
||||
coreInfo := s.coreInfoService.FindByCoreId(neInfo.CoreId)
|
||||
if coreInfo.ID == neInfo.CoreId {
|
||||
neInfo.CoreName = coreInfo.CoreName
|
||||
neInfo.CoreUid = coreInfo.CoreUid
|
||||
}
|
||||
|
||||
c.JSON(200, resp.OkData(neInfo))
|
||||
}
|
||||
|
||||
@@ -143,7 +154,7 @@ func (s NeInfoController) Nf(c *gin.Context) {
|
||||
func (s NeInfoController) ListAll(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
CoreId int64 `form:"coreId"` // 核心网唯一标识
|
||||
CoreUid string `form:"coreUid"` // 核心网唯一标识
|
||||
NeUid string `form:"neUid"` // 网元唯一标识
|
||||
NeType string `form:"neType"`
|
||||
BandStatus bool `form:"bandStatus"`
|
||||
@@ -157,8 +168,14 @@ func (s NeInfoController) ListAll(c *gin.Context) {
|
||||
|
||||
// 查询实体参数
|
||||
ne := model.NeInfo{}
|
||||
if querys.CoreId != 0 {
|
||||
ne.CoreId = querys.CoreId
|
||||
if querys.CoreUid != "" {
|
||||
// 检查是否存在
|
||||
coreInfo := s.coreInfoService.FindByCoreUid(querys.CoreUid)
|
||||
if coreInfo.ID == 0 || coreInfo.CoreUid != querys.CoreUid {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noCoreInfo")))
|
||||
return
|
||||
}
|
||||
ne.CoreId = coreInfo.ID
|
||||
}
|
||||
if querys.NeUid != "" {
|
||||
ne.NeUid = querys.NeUid
|
||||
@@ -172,9 +189,17 @@ func (s NeInfoController) ListAll(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤屏蔽授权文件
|
||||
// 过滤处理
|
||||
arr := &neList
|
||||
for i := range *arr {
|
||||
// 关联核心网信息
|
||||
coreId := (*arr)[i].CoreId
|
||||
coreInfo := s.coreInfoService.FindByCoreId(coreId)
|
||||
if coreInfo.ID == coreId {
|
||||
(*arr)[i].CoreName = coreInfo.CoreName
|
||||
(*arr)[i].CoreUid = coreInfo.CoreUid
|
||||
}
|
||||
// 过滤屏蔽授权文件
|
||||
(*arr)[i].ActivationRequestCode = "-"
|
||||
(*arr)[i].LicensePath = "-"
|
||||
}
|
||||
@@ -403,11 +428,27 @@ func (s NeInfoController) List(c *gin.Context) {
|
||||
if v, ok := query["bandStatus"]; ok {
|
||||
bandStatus = parse.Boolean(v)
|
||||
}
|
||||
if v, ok := query["coreUid"]; ok {
|
||||
// 检查是否存在
|
||||
coreInfo := s.coreInfoService.FindByCoreUid(v)
|
||||
if coreInfo.ID != 0 && coreInfo.CoreUid == v {
|
||||
query["coreId"] = fmt.Sprint(coreInfo.ID)
|
||||
}
|
||||
}
|
||||
|
||||
rows, total := s.neInfoService.FindByPage(query, bandStatus)
|
||||
|
||||
// 过滤屏蔽授权文件
|
||||
// 过滤处理
|
||||
arr := &rows
|
||||
for i := range *arr {
|
||||
// 关联核心网信息
|
||||
coreId := (*arr)[i].CoreId
|
||||
coreInfo := s.coreInfoService.FindByCoreId(coreId)
|
||||
if coreInfo.ID == coreId {
|
||||
(*arr)[i].CoreName = coreInfo.CoreName
|
||||
(*arr)[i].CoreUid = coreInfo.CoreUid
|
||||
}
|
||||
// 过滤屏蔽授权文件
|
||||
(*arr)[i].ActivationRequestCode = "-"
|
||||
(*arr)[i].LicensePath = "-"
|
||||
}
|
||||
@@ -568,3 +609,56 @@ func (s NeInfoController) Remove(c *gin.Context) {
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 网元信息关联核心网
|
||||
//
|
||||
// PUT /
|
||||
//
|
||||
// @Tags network_element/info
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param data body object true "Request Param"
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
// @Summary Network element information modification
|
||||
// @Description Network element information modification
|
||||
// @Router /ne/info/core [put]
|
||||
func (s NeInfoController) Core(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeUID string `json:"neUid" binding:"required"` // 网元唯一标识
|
||||
CoreUID string `json:"coreUid" binding:"required"` // 核心网唯一标识
|
||||
}
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.FindByNeUid(body.NeUID)
|
||||
if neInfo.ID == 0 || neInfo.NeUid != body.NeUID {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询核心网ID
|
||||
var coreId int64 = 0
|
||||
if len(body.CoreUID) == 8 {
|
||||
// 检查是否存在
|
||||
coreInfo := s.coreInfoService.FindByCoreUid(body.CoreUID)
|
||||
if coreInfo.ID == 0 || coreInfo.CoreUid != body.CoreUID {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noCoreInfo")))
|
||||
return
|
||||
}
|
||||
coreId = coreInfo.ID
|
||||
}
|
||||
|
||||
rows := s.neInfoService.UpdateCoreId(neInfo.ID, coreId)
|
||||
if rows > 0 {
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ type NeInfo struct {
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
Remark string `json:"remark" gorm:"column:remark"` // 备注
|
||||
CoreId int64 `json:"coreId" gorm:"column:core_id"` // 核心网ID 1为全局默认
|
||||
CoreId int64 `json:"coreId" gorm:"column:core_id"` // 核心网ID 0为默认
|
||||
NeUid string `json:"neUid" gorm:"column:ne_uid"` // 网元唯一标识
|
||||
NeType string `json:"neType" gorm:"column:ne_type" binding:"required"` // 网元类型
|
||||
NeName string `json:"neName" gorm:"column:ne_name"` // 网元名称
|
||||
@@ -30,6 +30,8 @@ type NeInfo struct {
|
||||
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
CoreUid string `json:"coreUid,omitempty" gorm:"->"` // 核心网唯一标识
|
||||
CoreName string `json:"coreName,omitempty" gorm:"->"` // 核心网名称
|
||||
ServerState map[string]any `json:"serverState,omitempty" gorm:"-"` // 服务状态
|
||||
Hosts []NeHost `json:"hosts,omitempty" gorm:"-"` // 主机对象组
|
||||
}
|
||||
|
||||
@@ -115,6 +115,12 @@ func Setup(router *gin.Engine) {
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeInfo.Remove,
|
||||
)
|
||||
neInfoGroup.PUT("/core",
|
||||
middleware.CryptoApi(true, true),
|
||||
middleware.AuthorizeUser(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeInfo.Core,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元主机
|
||||
|
||||
@@ -93,6 +93,10 @@ func (r NeInfo) SelectByPage(query map[string]string) ([]model.NeInfo, int64) {
|
||||
// 查询数据分页
|
||||
pageNum, pageSize := db.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
|
||||
|
||||
// 关联查询
|
||||
// tx = tx.Joins("left join core_info on ne_info.core_id = core_info.id")
|
||||
// tx = tx.Select("ne_info.*, core_info.core_uid, core_info.core_name")
|
||||
err := tx.Find(&rows).Error
|
||||
if err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
@@ -235,3 +239,23 @@ func (r NeInfo) UpdateState(neInfo model.NeInfo) int64 {
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// UpdateCoreId 修改核心网ID
|
||||
func (r NeInfo) UpdateCoreId(id int64, coreId int64) int64 {
|
||||
if id <= 0 {
|
||||
return 0
|
||||
}
|
||||
tx := db.DB("").Model(&model.NeInfo{})
|
||||
// 构建查询条件
|
||||
tx = tx.Where("id = ?", id)
|
||||
tx.Updates(map[string]any{
|
||||
"core_id": coreId,
|
||||
"update_time": time.Now().UnixMilli(),
|
||||
})
|
||||
// 执行更新
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("update err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
@@ -342,6 +342,11 @@ func (r NeInfo) Insert(neInfo model.NeInfo) int64 {
|
||||
return insertId
|
||||
}
|
||||
|
||||
// UpdateCoreId 修改核心网ID
|
||||
func (r NeInfo) UpdateCoreId(id int64, coreId int64) int64 {
|
||||
return r.neInfoRepository.UpdateCoreId(id, coreId)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
// 获取网元状态是否正常
|
||||
|
||||
@@ -43,7 +43,7 @@ type CoreInfoController struct {
|
||||
func (s CoreInfoController) ListAll(c *gin.Context) {
|
||||
var querys struct {
|
||||
CoreUID string `form:"coreUid"` // 核心网唯一标识
|
||||
Name string `form:"name"` // 名称
|
||||
CoreName string `form:"coreName"` // 核心网名称
|
||||
SN string `form:"sn"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
@@ -55,10 +55,10 @@ func (s CoreInfoController) ListAll(c *gin.Context) {
|
||||
// 查询实体参数
|
||||
core := model.CoreInfo{}
|
||||
if querys.CoreUID != "" {
|
||||
core.CoreUID = querys.CoreUID
|
||||
core.CoreUid = querys.CoreUID
|
||||
}
|
||||
if querys.Name != "" {
|
||||
core.Name = querys.Name
|
||||
if querys.CoreName != "" {
|
||||
core.CoreName = querys.CoreName
|
||||
}
|
||||
if querys.SN != "" {
|
||||
core.SN = querys.SN
|
||||
@@ -111,7 +111,7 @@ func (s CoreInfoController) Add(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.coreInfoService.CheckUniqueGroupTitle(body.Name, body.SN, 0)
|
||||
uniqueInfo := s.coreInfoService.CheckUniqueGroupTitle(body.CoreName, body.SN, 0)
|
||||
if !uniqueInfo {
|
||||
c.JSON(200, resp.ErrMsg("name/SN already exists"))
|
||||
return
|
||||
@@ -138,7 +138,7 @@ func (s CoreInfoController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHostCmd := s.coreInfoService.CheckUniqueGroupTitle(body.Name, body.SN, body.ID)
|
||||
uniqueHostCmd := s.coreInfoService.CheckUniqueGroupTitle(body.CoreName, body.SN, body.ID)
|
||||
if !uniqueHostCmd {
|
||||
c.JSON(200, resp.ErrMsg("name/SN already exists"))
|
||||
return
|
||||
@@ -151,7 +151,7 @@ func (s CoreInfoController) Edit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
coreInfo.Name = body.Name
|
||||
coreInfo.CoreName = body.CoreName
|
||||
coreInfo.SN = body.SN
|
||||
coreInfo.TimeZone = body.TimeZone
|
||||
coreInfo.Longitude = body.Longitude
|
||||
|
||||
@@ -14,7 +14,7 @@ func Setup(router *gin.Engine) {
|
||||
logger.Infof("开始加载 ====> ne_core 模块路由")
|
||||
|
||||
// 核心网信息
|
||||
coreInfoGroup := router.Group("/core/info")
|
||||
coreInfoGroup := router.Group("/ne/core/info")
|
||||
{
|
||||
coreInfoGroup.GET("/list/all",
|
||||
middleware.AuthorizeUser(nil),
|
||||
|
||||
@@ -3,10 +3,10 @@ package model
|
||||
// CoreInfo 核心网_基础信息 core_info
|
||||
type CoreInfo struct {
|
||||
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` // 核心网ID
|
||||
CoreUID string `json:"coreUid" gorm:"column:core_uid"` // 核心网唯一标识
|
||||
Name string `json:"name" gorm:"column:name"` // 核心网名称
|
||||
CoreUid string `json:"coreUid" gorm:"column:core_uid"` // 核心网唯一标识
|
||||
CoreName string `json:"coreName" gorm:"column:core_name"` // 核心网名称
|
||||
SN string `json:"sn" gorm:"column:sn"` // 核心网序列号
|
||||
OmcId string `json:"omcId" gorm:"column:omc_id"` // OMC安装生成的唯一编码
|
||||
CoreOMC string `json:"coreOMC" gorm:"column:core_omc"` // 核心网所在OMC唯一编码
|
||||
TimeZone string `json:"timeZone" gorm:"column:time_zone"` // 时区 Asia/Hong_Kong
|
||||
Longitude float64 `json:"longitude" gorm:"column:longitude"` // 经度 -180 to 180
|
||||
Latitude float64 `json:"latitude" gorm:"column:latitude"` // 纬度 -90 to 90
|
||||
|
||||
@@ -53,11 +53,11 @@ func (r CoreInfo) SelectByPage(query map[string]string) ([]model.CoreInfo, int64
|
||||
func (r CoreInfo) Select(param model.CoreInfo) []model.CoreInfo {
|
||||
tx := db.DB("").Model(&model.CoreInfo{})
|
||||
// 查询条件拼接
|
||||
if param.CoreUID != "" {
|
||||
tx = tx.Where("core_uid = ?", param.CoreUID)
|
||||
if param.CoreUid != "" {
|
||||
tx = tx.Where("core_uid = ?", param.CoreUid)
|
||||
}
|
||||
if param.Name != "" {
|
||||
tx = tx.Where("name = ?", param.Name)
|
||||
if param.CoreName != "" {
|
||||
tx = tx.Where("core_name = ?", param.CoreName)
|
||||
}
|
||||
if param.SN != "" {
|
||||
tx = tx.Where("sn = ?", param.SN)
|
||||
@@ -89,6 +89,23 @@ func (r CoreInfo) SelectByIds(ids []int64) []model.CoreInfo {
|
||||
return rows
|
||||
}
|
||||
|
||||
// SelectCoreInfoByCoreUid 通过core_uid查询网元信息
|
||||
func (r CoreInfo) SelectCoreInfoByCoreUid(coreUid string) model.CoreInfo {
|
||||
if coreUid == "" {
|
||||
return model.CoreInfo{}
|
||||
}
|
||||
tx := db.DB("").Model(&model.CoreInfo{})
|
||||
// 构建查询条件
|
||||
tx = tx.Where("core_uid = ?", coreUid)
|
||||
// 查询数据
|
||||
row := model.CoreInfo{}
|
||||
if err := tx.Limit(1).Find(&row).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return row
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r CoreInfo) Insert(param model.CoreInfo) int64 {
|
||||
if param.CreateBy != "" {
|
||||
@@ -140,8 +157,8 @@ func (r CoreInfo) DeleteByIds(ids []int64) int64 {
|
||||
func (r CoreInfo) CheckUnique(param model.CoreInfo) int64 {
|
||||
tx := db.DB("").Model(&model.CoreInfo{})
|
||||
// 查询条件拼接
|
||||
if param.Name != "" {
|
||||
tx = tx.Where("name = ?", param.Name)
|
||||
if param.CoreName != "" {
|
||||
tx = tx.Where("core_name = ?", param.CoreName)
|
||||
}
|
||||
if param.SN != "" {
|
||||
tx = tx.Where("sn = ?", param.SN)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/framework/utils/generate"
|
||||
"be.ems/src/framework/utils/machine"
|
||||
"be.ems/src/modules/ne_core/model"
|
||||
@@ -20,6 +23,55 @@ type CoreInfo struct {
|
||||
coreInfoRepository *repository.CoreInfo // 核心网信息表
|
||||
}
|
||||
|
||||
// FindByCoreId 通过core_id查询核心网信息
|
||||
func (r CoreInfo) FindByCoreId(coreId int64) model.CoreInfo {
|
||||
coreInfo := model.CoreInfo{}
|
||||
key := fmt.Sprintf("%s:*:%d:*", constants.CACHE_NE_CORE, coreId)
|
||||
jsonStr, err := redis.Get("", key)
|
||||
if err == nil && len(jsonStr) > 7 {
|
||||
if err := json.Unmarshal([]byte(jsonStr), &coreInfo); err != nil {
|
||||
return coreInfo
|
||||
}
|
||||
} else {
|
||||
coreInfos := r.coreInfoRepository.SelectByIds([]int64{coreId})
|
||||
if len(coreInfos) == 1 {
|
||||
coreInfo = coreInfos[0]
|
||||
redis.Del("", key)
|
||||
dataByte, err := json.Marshal(coreInfo)
|
||||
if err != nil {
|
||||
return coreInfo
|
||||
}
|
||||
key = fmt.Sprintf("%s:%s:%d:%s", constants.CACHE_NE_CORE, coreInfo.SN, coreInfo.ID, coreInfo.CoreUid)
|
||||
redis.Set("", key, string(dataByte), 0)
|
||||
}
|
||||
}
|
||||
return coreInfo
|
||||
}
|
||||
|
||||
// FindByCoreUid 通过core_uid查询网元信息
|
||||
func (r CoreInfo) FindByCoreUid(coreUid string) model.CoreInfo {
|
||||
coreInfo := model.CoreInfo{}
|
||||
key := fmt.Sprintf("%s:*:*:%s", constants.CACHE_NE_CORE, coreUid)
|
||||
jsonStr, err := redis.Get("", key)
|
||||
if err == nil && len(jsonStr) > 7 {
|
||||
if err := json.Unmarshal([]byte(jsonStr), &coreInfo); err != nil {
|
||||
return coreInfo
|
||||
}
|
||||
} else {
|
||||
coreInfo = r.coreInfoRepository.SelectCoreInfoByCoreUid(coreUid)
|
||||
if coreInfo.CoreUid == coreUid {
|
||||
redis.Del("", key)
|
||||
dataByte, err := json.Marshal(coreInfo)
|
||||
if err != nil {
|
||||
return coreInfo
|
||||
}
|
||||
key = fmt.Sprintf("%s:%s:%d:%s", constants.CACHE_NE_CORE, coreInfo.SN, coreInfo.ID, coreInfo.CoreUid)
|
||||
redis.Set("", key, string(dataByte), 0)
|
||||
}
|
||||
}
|
||||
return coreInfo
|
||||
}
|
||||
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r CoreInfo) FindByPage(query map[string]string) ([]model.CoreInfo, int64) {
|
||||
return r.coreInfoRepository.SelectByPage(query)
|
||||
@@ -44,9 +96,9 @@ func (r CoreInfo) FindById(id int64) model.CoreInfo {
|
||||
|
||||
// Insert 新增信息
|
||||
func (r CoreInfo) Insert(param model.CoreInfo) int64 {
|
||||
param.CoreUID = strings.ToUpper(generate.Code(8))
|
||||
if param.OmcId == "" {
|
||||
param.OmcId = machine.Code
|
||||
param.CoreUid = strings.ToUpper(generate.Code(8))
|
||||
if param.CoreOMC == "" {
|
||||
param.CoreOMC = machine.Code
|
||||
}
|
||||
|
||||
return r.coreInfoRepository.Insert(param)
|
||||
@@ -74,9 +126,9 @@ func (r CoreInfo) DeleteByIds(ids []int64) (int64, error) {
|
||||
}
|
||||
|
||||
// CheckUniqueGroupTitle 校验唯一名称和序号
|
||||
func (r CoreInfo) CheckUniqueGroupTitle(name, sn string, id int64) bool {
|
||||
func (r CoreInfo) CheckUniqueGroupTitle(coreName, sn string, id int64) bool {
|
||||
uniqueId := r.coreInfoRepository.CheckUnique(model.CoreInfo{
|
||||
Name: name,
|
||||
CoreName: coreName,
|
||||
SN: sn,
|
||||
})
|
||||
if uniqueId == id {
|
||||
|
||||
Reference in New Issue
Block a user