feat: 新增网元软件包信息/网元版本信息接口
This commit is contained in:
150
src/modules/network_element/controller/ne_software.go
Normal file
150
src/modules/network_element/controller/ne_software.go
Normal file
@@ -0,0 +1,150 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"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"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeSoftwareController 结构体
|
||||
var NewNeSoftware = &NeSoftwareController{
|
||||
neSoftwareService: neService.NewNeSoftwareImpl,
|
||||
}
|
||||
|
||||
// 网元软件包信息请求
|
||||
//
|
||||
// PATH /software
|
||||
type NeSoftwareController struct {
|
||||
// 网元软件包信息服务
|
||||
neSoftwareService neService.INeSoftware
|
||||
}
|
||||
|
||||
// 网元软件包信息列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeSoftwareController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neSoftwareService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元软件包信息信息
|
||||
//
|
||||
// GET /:softwareId
|
||||
func (s *NeSoftwareController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
softwareId := c.Param("softwareId")
|
||||
if softwareId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
neSoftware := s.neSoftwareService.SelectById(softwareId)
|
||||
if neSoftware.ID != softwareId {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neSoftware))
|
||||
}
|
||||
|
||||
// 网元软件包信息新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeSoftwareController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeSoftware
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueVersion := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, "")
|
||||
if !uniqueVersion {
|
||||
// 网元软件包操作【%s】失败,网元类型与文件名版本已存在
|
||||
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.FileName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
insertId := s.neSoftwareService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元软件包信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeSoftwareController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeSoftware
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueVersion := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, body.ID)
|
||||
if !uniqueVersion {
|
||||
// 网元软件包操作【%s】失败,网元类型与文件名版本已存在
|
||||
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.FileName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neSoftware := s.neSoftwareService.SelectById(body.ID)
|
||||
if neSoftware.ID != body.ID {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
rows := s.neSoftwareService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元软件包信息删除
|
||||
//
|
||||
// DELETE /:softwareIds
|
||||
func (s *NeSoftwareController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
softwareIds := c.Param("softwareIds")
|
||||
if softwareIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(softwareIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neSoftwareService.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))
|
||||
}
|
||||
150
src/modules/network_element/controller/ne_version.go
Normal file
150
src/modules/network_element/controller/ne_version.go
Normal file
@@ -0,0 +1,150 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"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"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeVersionController 结构体
|
||||
var NewNeVersion = &NeVersionController{
|
||||
neVersionService: neService.NewNeVersionImpl,
|
||||
}
|
||||
|
||||
// 网元版本信息请求
|
||||
//
|
||||
// PATH /version
|
||||
type NeVersionController struct {
|
||||
// 网元版本信息服务
|
||||
neVersionService neService.INeVersion
|
||||
}
|
||||
|
||||
// 网元版本信息列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeVersionController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neVersionService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元版本信息信息
|
||||
//
|
||||
// GET /:versionId
|
||||
func (s *NeVersionController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
versionId := c.Param("versionId")
|
||||
if versionId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
neVersion := s.neVersionService.SelectById(versionId)
|
||||
if neVersion.ID != versionId {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neVersion))
|
||||
}
|
||||
|
||||
// 网元版本信息新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeVersionController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeVersion
|
||||
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.neVersionService.CheckUniqueTypeAndID(body.NeType, body.NeId, "")
|
||||
if !uniqueInfo {
|
||||
// 网元版本操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neVersion.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
insertId := s.neVersionService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元版本信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeVersionController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeVersion
|
||||
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.neVersionService.CheckUniqueTypeAndID(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueInfo {
|
||||
// 网元版本操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neVersion.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neVersion := s.neVersionService.SelectById(body.ID)
|
||||
if neVersion.ID != body.ID {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
rows := s.neVersionService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元版本信息删除
|
||||
//
|
||||
// DELETE /:versionIds
|
||||
func (s *NeVersionController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
versionIds := c.Param("versionIds")
|
||||
if versionIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(versionIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neVersionService.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))
|
||||
}
|
||||
@@ -144,6 +144,62 @@ func Setup(router *gin.Engine) {
|
||||
)
|
||||
}
|
||||
|
||||
// 网元版本信息
|
||||
neVersionGroup := neGroup.Group("/version")
|
||||
{
|
||||
neVersionGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeVersion.List,
|
||||
)
|
||||
neVersionGroup.GET("/:versionId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeVersion.Info,
|
||||
)
|
||||
neVersionGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neVersion", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeVersion.Add,
|
||||
)
|
||||
neVersionGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neVersion", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeVersion.Edit,
|
||||
)
|
||||
neVersionGroup.DELETE("/:versionIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neVersion", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeVersion.Remove,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元软件包信息
|
||||
neSoftwareGroup := neGroup.Group("/software")
|
||||
{
|
||||
neSoftwareGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeSoftware.List,
|
||||
)
|
||||
neSoftwareGroup.GET("/:softwareId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeSoftware.Info,
|
||||
)
|
||||
neSoftwareGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeSoftware.Add,
|
||||
)
|
||||
neSoftwareGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeSoftware.Edit,
|
||||
)
|
||||
neSoftwareGroup.DELETE("/:softwareIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeSoftware.Remove,
|
||||
)
|
||||
}
|
||||
|
||||
// UDM鉴权用户信息
|
||||
udmAuthGroup := neGroup.Group("/udm/auth")
|
||||
{
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeHostCmd 结构体
|
||||
var NewNeHostCmdImpl = &NeHostCmd{
|
||||
// 实例化数据层 NewNeHostCmdImpl 结构体
|
||||
var NewNeHostCmdImpl = &NeHostCmdImpl{
|
||||
selectSql: `select
|
||||
cmd_id, cmd_type, group_id, title, command, remark, create_by, create_time, update_by, update_time
|
||||
from ne_host_cmd`,
|
||||
@@ -32,8 +32,8 @@ var NewNeHostCmdImpl = &NeHostCmd{
|
||||
},
|
||||
}
|
||||
|
||||
// NeHostCmd 网元主机连接 数据层处理
|
||||
type NeHostCmd struct {
|
||||
// NeHostCmdImpl 网元主机连接 数据层处理
|
||||
type NeHostCmdImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
@@ -41,7 +41,7 @@ type NeHostCmd struct {
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeHostCmd) convertResultRows(rows []map[string]any) []model.NeHostCmd {
|
||||
func (r *NeHostCmdImpl) convertResultRows(rows []map[string]any) []model.NeHostCmd {
|
||||
arr := make([]model.NeHostCmd, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeHostCmd{}
|
||||
@@ -56,7 +56,7 @@ func (r *NeHostCmd) convertResultRows(rows []map[string]any) []model.NeHostCmd {
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeHostCmd) SelectPage(query map[string]any) map[string]any {
|
||||
func (r *NeHostCmdImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
@@ -118,7 +118,7 @@ func (r *NeHostCmd) SelectPage(query map[string]any) map[string]any {
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeHostCmd) SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd {
|
||||
func (r *NeHostCmdImpl) SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
@@ -153,7 +153,7 @@ func (r *NeHostCmd) SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd {
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHostCmd) SelectByIds(cmdIds []string) []model.NeHostCmd {
|
||||
func (r *NeHostCmdImpl) SelectByIds(cmdIds []string) []model.NeHostCmd {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
querySql := r.selectSql + " where cmd_id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
@@ -167,7 +167,7 @@ func (r *NeHostCmd) SelectByIds(cmdIds []string) []model.NeHostCmd {
|
||||
}
|
||||
|
||||
// CheckUniqueGroupTitle 校验同类型组内是否唯一
|
||||
func (r *NeHostCmd) CheckUniqueGroupTitle(neHostCmd model.NeHostCmd) string {
|
||||
func (r *NeHostCmdImpl) CheckUniqueGroupTitle(neHostCmd model.NeHostCmd) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
@@ -206,7 +206,7 @@ func (r *NeHostCmd) CheckUniqueGroupTitle(neHostCmd model.NeHostCmd) string {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHostCmd) Insert(neHostCmd model.NeHostCmd) string {
|
||||
func (r *NeHostCmdImpl) Insert(neHostCmd model.NeHostCmd) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neHostCmd.CmdType != "" {
|
||||
@@ -257,7 +257,7 @@ func (r *NeHostCmd) Insert(neHostCmd model.NeHostCmd) string {
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHostCmd) Update(neHostCmd model.NeHostCmd) int64 {
|
||||
func (r *NeHostCmdImpl) Update(neHostCmd model.NeHostCmd) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neHostCmd.CmdType != "" {
|
||||
@@ -293,7 +293,7 @@ func (r *NeHostCmd) Update(neHostCmd model.NeHostCmd) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeHostCmd) DeleteByIds(cmdIds []string) int64 {
|
||||
func (r *NeHostCmdImpl) DeleteByIds(cmdIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
sql := "delete from ne_host_cmd where cmd_id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
|
||||
27
src/modules/network_element/repository/ne_software.go
Normal file
27
src/modules/network_element/repository/ne_software.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeSoftware 网元软件包信息 数据层接口
|
||||
type INeSoftware interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neSoftware model.NeSoftware) []model.NeSoftware
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(ids []string) []model.NeSoftware
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neSoftware model.NeSoftware) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neSoftware model.NeSoftware) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) int64
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
CheckUniqueTypeAndFileNameAndVersion(neSoftware model.NeSoftware) string
|
||||
}
|
||||
319
src/modules/network_element/repository/ne_software.impl.go
Normal file
319
src/modules/network_element/repository/ne_software.impl.go
Normal file
@@ -0,0 +1,319 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeSoftware 结构体
|
||||
var NewNeSoftwareImpl = &NeSoftwareImpl{
|
||||
selectSql: `select
|
||||
id, ne_type, file_name, path, version, md5_sum, status, comment, update_time
|
||||
from ne_software`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"file_name": "FileName",
|
||||
"path": "Path",
|
||||
"version": "Version",
|
||||
"md5_sum": "Md5Sum",
|
||||
"status": "Status",
|
||||
"comment": "Comment",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
// NeSoftwareImpl 网元软件包信息 数据层处理
|
||||
type NeSoftwareImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeSoftwareImpl) convertResultRows(rows []map[string]any) []model.NeSoftware {
|
||||
arr := make([]model.NeSoftware, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeSoftware{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeSoftwareImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["fileName"]; ok && v != "" {
|
||||
conditions = append(conditions, "file_name like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["version"]; ok && v != "" {
|
||||
conditions = append(conditions, "version like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_software"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeSoftwareImpl) SelectList(neSoftware model.NeSoftware) []model.NeSoftware {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neSoftware.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neSoftware.NeType)
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
conditions = append(conditions, "version = ?")
|
||||
params = append(params, neSoftware.Version)
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
conditions = append(conditions, "file_name like concat(?, '%')")
|
||||
params = append(params, neSoftware.FileName)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by update_time asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeSoftwareImpl) SelectByIds(cmdIds []string) []model.NeSoftware {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeSoftware{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
func (r *NeSoftwareImpl) CheckUniqueTypeAndFileNameAndVersion(neSoftware model.NeSoftware) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neSoftware.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neSoftware.NeType)
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
conditions = append(conditions, "version = ?")
|
||||
params = append(params, neSoftware.Version)
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
conditions = append(conditions, "file_name = ?")
|
||||
params = append(params, neSoftware.FileName)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select id as 'str' from ne_software " + 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 *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neSoftware.NeType != "" {
|
||||
params["ne_type"] = neSoftware.NeType
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
params["file_name"] = neSoftware.FileName
|
||||
}
|
||||
if neSoftware.Path != "" {
|
||||
params["path"] = neSoftware.Path
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
params["version"] = neSoftware.Version
|
||||
}
|
||||
if neSoftware.Md5Sum != "" {
|
||||
params["md5_sum"] = neSoftware.Md5Sum
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
if neSoftware.Comment != "" {
|
||||
params["comment"] = neSoftware.Comment
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_software (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neSoftware.NeType != "" {
|
||||
params["ne_type"] = neSoftware.NeType
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
params["file_name"] = neSoftware.FileName
|
||||
}
|
||||
if neSoftware.Path != "" {
|
||||
params["path"] = neSoftware.Path
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
params["version"] = neSoftware.Version
|
||||
}
|
||||
if neSoftware.Md5Sum != "" {
|
||||
params["md5_sum"] = neSoftware.Md5Sum
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
if neSoftware.Comment != "" {
|
||||
params["comment"] = neSoftware.Comment
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_software set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neSoftware.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeSoftwareImpl) DeleteByIds(cmdIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
sql := "delete from ne_software where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
27
src/modules/network_element/repository/ne_version.go
Normal file
27
src/modules/network_element/repository/ne_version.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeVersion 网元版本信息 数据层接口
|
||||
type INeVersion interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neVersion model.NeVersion) []model.NeVersion
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(ids []string) []model.NeVersion
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neVersion model.NeVersion) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neVersion model.NeVersion) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) int64
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neVersion model.NeVersion) string
|
||||
}
|
||||
331
src/modules/network_element/repository/ne_version.impl.go
Normal file
331
src/modules/network_element/repository/ne_version.impl.go
Normal file
@@ -0,0 +1,331 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeVersion 结构体
|
||||
var NewNeVersionImpl = &NeVersionImpl{
|
||||
selectSql: `select
|
||||
id, ne_type, ne_id, version, file_path, pre_version, pre_file, new_version, new_file, status, update_time
|
||||
from ne_version`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"ne_id": "NeId",
|
||||
"version": "Version",
|
||||
"file_path": "FilePath",
|
||||
"pre_version": "PreVersion",
|
||||
"pre_file": "PreFile",
|
||||
"new_version": "NewVersion",
|
||||
"new_file": "NewFile",
|
||||
"status": "Status",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
// NeVersionImpl 网元版本信息 数据层处理
|
||||
type NeVersionImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeVersionImpl) convertResultRows(rows []map[string]any) []model.NeVersion {
|
||||
arr := make([]model.NeVersion, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeVersion{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeVersionImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["neId"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["version"]; ok && v != "" {
|
||||
conditions = append(conditions, "version like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["filePath"]; ok && v != "" {
|
||||
conditions = append(conditions, "file_path like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_version"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeVersionImpl) SelectList(neVersion model.NeVersion) []model.NeVersion {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neVersion.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neVersion.NeType)
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neVersion.NeId)
|
||||
}
|
||||
if neVersion.Version != "" {
|
||||
conditions = append(conditions, "version like concat(?, '%')")
|
||||
params = append(params, neVersion.Version)
|
||||
}
|
||||
if neVersion.FilePath != "" {
|
||||
conditions = append(conditions, "file_path like concat(?, '%')")
|
||||
params = append(params, neVersion.FilePath)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by update_time asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeVersionImpl) SelectByIds(cmdIds []string) []model.NeVersion {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeVersion{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
func (r *NeVersionImpl) CheckUniqueTypeAndID(neVersion model.NeVersion) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neVersion.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neVersion.NeType)
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neVersion.NeId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select id as 'str' from ne_version " + 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 *NeVersionImpl) Insert(neVersion model.NeVersion) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neVersion.NeType != "" {
|
||||
params["ne_type"] = neVersion.NeType
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
params["ne_id"] = neVersion.NeId
|
||||
}
|
||||
if neVersion.Version != "" {
|
||||
params["version"] = neVersion.Version
|
||||
}
|
||||
if neVersion.FilePath != "" {
|
||||
params["file_path"] = neVersion.FilePath
|
||||
}
|
||||
if neVersion.PreVersion != "" {
|
||||
params["pre_version"] = neVersion.PreVersion
|
||||
}
|
||||
if neVersion.PreFile != "" {
|
||||
params["pre_file"] = neVersion.PreFile
|
||||
}
|
||||
if neVersion.NewVersion != "" {
|
||||
params["new_version"] = neVersion.NewVersion
|
||||
}
|
||||
if neVersion.NewFile != "" {
|
||||
params["new_file"] = neVersion.NewFile
|
||||
}
|
||||
if neVersion.Status != "" {
|
||||
params["status"] = neVersion.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_version (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeVersionImpl) Update(neVersion model.NeVersion) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neVersion.NeType != "" {
|
||||
params["ne_type"] = neVersion.NeType
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
params["ne_id"] = neVersion.NeId
|
||||
}
|
||||
if neVersion.Version != "" {
|
||||
params["version"] = neVersion.Version
|
||||
}
|
||||
if neVersion.FilePath != "" {
|
||||
params["file_path"] = neVersion.FilePath
|
||||
}
|
||||
if neVersion.PreVersion != "" {
|
||||
params["pre_version"] = neVersion.PreVersion
|
||||
}
|
||||
if neVersion.PreFile != "" {
|
||||
params["pre_file"] = neVersion.PreFile
|
||||
}
|
||||
if neVersion.NewVersion != "" {
|
||||
params["new_version"] = neVersion.NewVersion
|
||||
}
|
||||
if neVersion.NewFile != "" {
|
||||
params["new_file"] = neVersion.NewFile
|
||||
}
|
||||
if neVersion.Status != "" {
|
||||
params["status"] = neVersion.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_version set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neVersion.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeVersionImpl) DeleteByIds(cmdIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
sql := "delete from ne_version where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
27
src/modules/network_element/service/ne_software.go
Normal file
27
src/modules/network_element/service/ne_software.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeSoftware 网元软件包信息 服务层接口
|
||||
type INeSoftware interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neSoftware model.NeSoftware) []model.NeSoftware
|
||||
|
||||
// SelectById 通过ID查询
|
||||
SelectById(id string) model.NeSoftware
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neSoftware model.NeSoftware) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neSoftware model.NeSoftware) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) (int64, error)
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool
|
||||
}
|
||||
80
src/modules/network_element/service/ne_software.impl.go
Normal file
80
src/modules/network_element/service/ne_software.impl.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeSoftwareImpl 结构体
|
||||
var NewNeSoftwareImpl = &NeSoftwareImpl{
|
||||
neSoftwareRepository: repository.NewNeSoftwareImpl,
|
||||
}
|
||||
|
||||
// NeSoftwareImpl 网元软件包信息 服务层处理
|
||||
type NeSoftwareImpl struct {
|
||||
// 网元软件包信息
|
||||
neSoftwareRepository repository.INeSoftware
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeSoftwareImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neSoftwareRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeSoftwareImpl) SelectList(neSoftware model.NeSoftware) []model.NeSoftware {
|
||||
return r.neSoftwareRepository.SelectList(neSoftware)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeSoftwareImpl) SelectById(id string) model.NeSoftware {
|
||||
if id == "" {
|
||||
return model.NeSoftware{}
|
||||
}
|
||||
neHosts := r.neSoftwareRepository.SelectByIds([]string{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.NeSoftware{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
|
||||
return r.neSoftwareRepository.Insert(neSoftware)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
|
||||
return r.neSoftwareRepository.Update(neSoftware)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeSoftwareImpl) DeleteByIds(ids []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
rowIds := r.neSoftwareRepository.SelectByIds(ids)
|
||||
if len(rowIds) <= 0 {
|
||||
return 0, fmt.Errorf("neSoftware.noData")
|
||||
}
|
||||
|
||||
if len(rowIds) == len(ids) {
|
||||
rows := r.neSoftwareRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
func (r *NeSoftwareImpl) CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool {
|
||||
uniqueId := r.neSoftwareRepository.CheckUniqueTypeAndFileNameAndVersion(model.NeSoftware{
|
||||
NeType: neType,
|
||||
FileName: fileName,
|
||||
Version: version,
|
||||
})
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
27
src/modules/network_element/service/ne_version.go
Normal file
27
src/modules/network_element/service/ne_version.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeVersion 网元版本信息 服务层接口
|
||||
type INeVersion interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neVersion model.NeVersion) []model.NeVersion
|
||||
|
||||
// SelectById 通过ID查询
|
||||
SelectById(id string) model.NeVersion
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neVersion model.NeVersion) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neVersion model.NeVersion) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) (int64, error)
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neType, neId, id string) bool
|
||||
}
|
||||
79
src/modules/network_element/service/ne_version.impl.go
Normal file
79
src/modules/network_element/service/ne_version.impl.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeVersionImpl 结构体
|
||||
var NewNeVersionImpl = &NeVersionImpl{
|
||||
neVersionRepository: repository.NewNeVersionImpl,
|
||||
}
|
||||
|
||||
// NeVersionImpl 网元版本信息 服务层处理
|
||||
type NeVersionImpl struct {
|
||||
// 网元版本信息表
|
||||
neVersionRepository repository.INeVersion
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeVersionImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neVersionRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeVersionImpl) SelectList(neVersion model.NeVersion) []model.NeVersion {
|
||||
return r.neVersionRepository.SelectList(neVersion)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeVersionImpl) SelectById(id string) model.NeVersion {
|
||||
if id == "" {
|
||||
return model.NeVersion{}
|
||||
}
|
||||
neHosts := r.neVersionRepository.SelectByIds([]string{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.NeVersion{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeVersionImpl) Insert(neVersion model.NeVersion) string {
|
||||
return r.neVersionRepository.Insert(neVersion)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeVersionImpl) Update(neVersion model.NeVersion) int64 {
|
||||
return r.neVersionRepository.Update(neVersion)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeVersionImpl) DeleteByIds(ids []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
rowIds := r.neVersionRepository.SelectByIds(ids)
|
||||
if len(rowIds) <= 0 {
|
||||
return 0, fmt.Errorf("neVersion.noData")
|
||||
}
|
||||
|
||||
if len(rowIds) == len(ids) {
|
||||
rows := r.neVersionRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
func (r *NeVersionImpl) CheckUniqueTypeAndID(neType, neId, id string) bool {
|
||||
uniqueId := r.neVersionRepository.CheckUniqueTypeAndID(model.NeVersion{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
Reference in New Issue
Block a user