feat: 网元模块
This commit is contained in:
39
src/modules/net_element/controller/ne_info.go
Normal file
39
src/modules/net_element/controller/ne_info.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/framework/vo/result"
|
||||||
|
netElementService "ems.agt/src/modules/net_element/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化控制层 NeInfoController 结构体
|
||||||
|
var NewNeInfo = &NeInfoController{
|
||||||
|
NeInfoService: netElementService.NewNeInfoImpl,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网元信息请求
|
||||||
|
//
|
||||||
|
// PATH /ne-info
|
||||||
|
type NeInfoController struct {
|
||||||
|
// 网元信息服务
|
||||||
|
NeInfoService netElementService.INeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网元neType和neID查询
|
||||||
|
//
|
||||||
|
// GET /info
|
||||||
|
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
|
||||||
|
neType := c.Query("neType")
|
||||||
|
neId := c.Query("neId")
|
||||||
|
if neType == "" || neId == "" {
|
||||||
|
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := s.NeInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||||
|
if data.NeType == neType {
|
||||||
|
c.JSON(200, result.OkData(data))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, result.Err(nil))
|
||||||
|
}
|
||||||
19
src/modules/net_element/model/ne_info.go
Normal file
19
src/modules/net_element/model/ne_info.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
// NeInfo 网元信息对象
|
||||||
|
type NeInfo struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
NeType string `json:"neType"`
|
||||||
|
NeId string `json:"neId"`
|
||||||
|
RmUID string `json:"rmUid"`
|
||||||
|
NeName string `json:"neName"`
|
||||||
|
IP string `json:"ip"`
|
||||||
|
Port int64 `json:"port"`
|
||||||
|
PvFlag string `json:"pvFlag"` // enum('PNF','VNF')
|
||||||
|
Province string `json:"province"`
|
||||||
|
VendorName string `json:"vendorName"`
|
||||||
|
Dn string `json:"dn"`
|
||||||
|
NeAddress string `json:"neAddress"`
|
||||||
|
Status string `json:"status"` // 0: 在线 1: 下线 2: 备用 3: 工程
|
||||||
|
UpdateTime string `json:"updateTime"`
|
||||||
|
}
|
||||||
23
src/modules/net_element/net_element.go
Normal file
23
src/modules/net_element/net_element.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package netelement
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/framework/logger"
|
||||||
|
"ems.agt/src/framework/middleware"
|
||||||
|
"ems.agt/src/modules/net_element/controller"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 模块路由注册
|
||||||
|
func Setup(router *gin.Engine) {
|
||||||
|
logger.Infof("开始加载 ====> net_element 模块路由")
|
||||||
|
|
||||||
|
// 网元信息
|
||||||
|
netInfoGroup := router.Group("/ne-info")
|
||||||
|
{
|
||||||
|
netInfoGroup.GET("/info",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
controller.NewNeInfo.NeTypeAndID,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/modules/net_element/repository/ne_info.go
Normal file
11
src/modules/net_element/repository/ne_info.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/modules/net_element/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 网元信息 数据层接口
|
||||||
|
type INeInfo interface {
|
||||||
|
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||||
|
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
|
||||||
|
}
|
||||||
69
src/modules/net_element/repository/ne_info.impl.go
Normal file
69
src/modules/net_element/repository/ne_info.impl.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/framework/datasource"
|
||||||
|
"ems.agt/src/framework/logger"
|
||||||
|
"ems.agt/src/framework/utils/repo"
|
||||||
|
"ems.agt/src/modules/net_element/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 NeInfoImpl 结构体
|
||||||
|
var NewNeInfoImpl = &NeInfoImpl{
|
||||||
|
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time from ne_info`,
|
||||||
|
|
||||||
|
resultMap: map[string]string{
|
||||||
|
"id": "ID",
|
||||||
|
"ne_type": "NeType",
|
||||||
|
"ne_id": "NeId",
|
||||||
|
"rm_uid": "RmUID",
|
||||||
|
"ne_name": "NeName",
|
||||||
|
"ip": "IP",
|
||||||
|
"port": "Port",
|
||||||
|
"pv_flag": "PvFlag",
|
||||||
|
"province": "Province",
|
||||||
|
"vendor_name": "VendorName",
|
||||||
|
"dn": "Dn",
|
||||||
|
"ne_address": "NeAddress",
|
||||||
|
"status": "Status",
|
||||||
|
"update_time": "UpdateTime",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// NeInfoImpl 网元信息表 数据层处理
|
||||||
|
type NeInfoImpl struct {
|
||||||
|
// 查询视图对象SQL
|
||||||
|
selectSql string
|
||||||
|
// 结果字段与实体映射
|
||||||
|
resultMap map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertResultRows 将结果记录转实体结果组
|
||||||
|
func (r *NeInfoImpl) convertResultRows(rows []map[string]any) []model.NeInfo {
|
||||||
|
arr := make([]model.NeInfo, 0)
|
||||||
|
for _, row := range rows {
|
||||||
|
item := model.NeInfo{}
|
||||||
|
for key, value := range row {
|
||||||
|
if keyMapper, ok := r.resultMap[key]; ok {
|
||||||
|
repo.SetFieldValue(&item, keyMapper, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arr = append(arr, item)
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||||
|
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||||
|
querySql := r.selectSql + " where ne_type = ? and ne_id = ?"
|
||||||
|
results, err := datasource.RawDB("", querySql, []any{neType, neID})
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("query err => %v", err)
|
||||||
|
return model.NeInfo{}
|
||||||
|
}
|
||||||
|
// 转换实体
|
||||||
|
rows := r.convertResultRows(results)
|
||||||
|
if len(rows) > 0 {
|
||||||
|
return rows[0]
|
||||||
|
}
|
||||||
|
return model.NeInfo{}
|
||||||
|
}
|
||||||
9
src/modules/net_element/service/ne_info.go
Normal file
9
src/modules/net_element/service/ne_info.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import "ems.agt/src/modules/net_element/model"
|
||||||
|
|
||||||
|
// 网元信息 服务层接口
|
||||||
|
type INeInfo interface {
|
||||||
|
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||||
|
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
|
||||||
|
}
|
||||||
22
src/modules/net_element/service/ne_info.impl.go
Normal file
22
src/modules/net_element/service/ne_info.impl.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/modules/net_element/model"
|
||||||
|
"ems.agt/src/modules/net_element/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化服务层 NeInfoImpl 结构体
|
||||||
|
var NewNeInfoImpl = &NeInfoImpl{
|
||||||
|
NeInfoRepository: repository.NewNeInfoImpl,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网元信息 服务层处理
|
||||||
|
type NeInfoImpl struct {
|
||||||
|
// 网元信息数据信息
|
||||||
|
NeInfoRepository repository.INeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||||
|
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||||
|
return r.NeInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user