feat: 查询核心网无分页接口
This commit is contained in:
@@ -15,14 +15,61 @@ import (
|
||||
|
||||
// 实例化控制层 CoreInfoController 结构体
|
||||
var NewCoreInfo = &CoreInfoController{
|
||||
CoreInfoService: service.NewCoreInfo,
|
||||
coreInfoService: service.NewCoreInfo,
|
||||
}
|
||||
|
||||
// 核心网信息请求
|
||||
//
|
||||
// PATH /core
|
||||
type CoreInfoController struct {
|
||||
CoreInfoService *service.CoreInfo //核心网信息服务
|
||||
coreInfoService *service.CoreInfo //核心网信息服务
|
||||
}
|
||||
|
||||
// 核心网信息列表全部无分页
|
||||
//
|
||||
// GET /list/all
|
||||
//
|
||||
// @Tags core/info
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param coreUid query string true "CoreUID" default(8I73Y01Z)
|
||||
// @Param name query string true "name" default(5AKF59BZ)
|
||||
// @Param sn query string true "sn"
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
// @Summary The list of network element information is all unpaginated
|
||||
// @Description The list of network element information is all unpaginated
|
||||
// @Router /core/info/list/all [get]
|
||||
func (s CoreInfoController) ListAll(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
CoreUID string `form:"coreUid"` // 核心网唯一标识
|
||||
Name string `form:"name"` // 名称
|
||||
SN string `form:"sn"`
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
// 查询实体参数
|
||||
core := model.CoreInfo{}
|
||||
if querys.CoreUID != "" {
|
||||
core.CoreUID = querys.CoreUID
|
||||
}
|
||||
if querys.Name != "" {
|
||||
core.Name = querys.Name
|
||||
}
|
||||
if querys.SN != "" {
|
||||
core.SN = querys.SN
|
||||
}
|
||||
neList := s.coreInfoService.Find(core)
|
||||
if len(neList) == 0 {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.OkData(neList))
|
||||
}
|
||||
|
||||
// 核心网信息列表
|
||||
@@ -30,7 +77,7 @@ type CoreInfoController struct {
|
||||
// GET /list
|
||||
func (s CoreInfoController) List(c *gin.Context) {
|
||||
query := reqctx.QueryMap(c)
|
||||
rows, total := s.CoreInfoService.FindByPage(query)
|
||||
rows, total := s.coreInfoService.FindByPage(query)
|
||||
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
|
||||
}
|
||||
|
||||
@@ -44,7 +91,7 @@ func (s CoreInfoController) Info(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
neHost := s.CoreInfoService.FindById(id)
|
||||
neHost := s.coreInfoService.FindById(id)
|
||||
if neHost.ID != id {
|
||||
c.JSON(200, resp.ErrMsg("not found data"))
|
||||
return
|
||||
@@ -65,14 +112,14 @@ func (s CoreInfoController) Add(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.CoreInfoService.CheckUniqueGroupTitle(body.Name, body.SN, 0)
|
||||
uniqueInfo := s.coreInfoService.CheckUniqueGroupTitle(body.Name, body.SN, 0)
|
||||
if !uniqueInfo {
|
||||
c.JSON(200, resp.ErrMsg("name/SN already exists"))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = reqctx.LoginUserToUserName(c)
|
||||
insertId := s.CoreInfoService.Insert(body)
|
||||
insertId := s.coreInfoService.Insert(body)
|
||||
if insertId > 0 {
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
@@ -92,14 +139,14 @@ func (s CoreInfoController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHostCmd := s.CoreInfoService.CheckUniqueGroupTitle(body.Name, body.SN, body.ID)
|
||||
uniqueHostCmd := s.coreInfoService.CheckUniqueGroupTitle(body.Name, body.SN, body.ID)
|
||||
if !uniqueHostCmd {
|
||||
c.JSON(200, resp.ErrMsg("name/SN already exists"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
coreInfo := s.CoreInfoService.FindById(body.ID)
|
||||
coreInfo := s.coreInfoService.FindById(body.ID)
|
||||
if coreInfo.ID != body.ID {
|
||||
c.JSON(200, resp.ErrMsg("not found data"))
|
||||
return
|
||||
@@ -113,7 +160,7 @@ func (s CoreInfoController) Edit(c *gin.Context) {
|
||||
coreInfo.Address = body.Address
|
||||
coreInfo.Remark = body.Remark
|
||||
body.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
rows := s.CoreInfoService.Update(coreInfo)
|
||||
rows := s.coreInfoService.Update(coreInfo)
|
||||
if rows > 0 {
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
@@ -140,7 +187,7 @@ func (s CoreInfoController) Remove(c *gin.Context) {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
|
||||
rows, err := s.CoreInfoService.DeleteByIds(ids)
|
||||
rows, err := s.coreInfoService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
|
||||
@@ -16,6 +16,10 @@ func Setup(router *gin.Engine) {
|
||||
// 核心网信息
|
||||
coreInfoGroup := router.Group("/core/info")
|
||||
{
|
||||
coreInfoGroup.GET("/list/all",
|
||||
middleware.AuthorizeUser(nil),
|
||||
controller.NewCoreInfo.ListAll,
|
||||
)
|
||||
coreInfoGroup.GET("/list",
|
||||
middleware.AuthorizeUser(nil),
|
||||
controller.NewCoreInfo.List,
|
||||
@@ -37,7 +41,7 @@ func Setup(router *gin.Engine) {
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.coreInfo", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewCoreInfo.Edit,
|
||||
)
|
||||
coreInfoGroup.DELETE(":id",
|
||||
coreInfoGroup.DELETE("/:id",
|
||||
middleware.AuthorizeUser(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.coreInfo", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewCoreInfo.Remove,
|
||||
|
||||
@@ -49,6 +49,29 @@ func (r CoreInfo) SelectByPage(query map[string]string) ([]model.CoreInfo, int64
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// Select 查询集合
|
||||
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.Name != "" {
|
||||
tx = tx.Where("name = ?", param.Name)
|
||||
}
|
||||
if param.SN != "" {
|
||||
tx = tx.Where("sn = ?", param.SN)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
rows := []model.CoreInfo{}
|
||||
if err := tx.Order("id asc").Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r CoreInfo) SelectByIds(ids []int64) []model.CoreInfo {
|
||||
rows := []model.CoreInfo{}
|
||||
|
||||
@@ -12,17 +12,22 @@ import (
|
||||
|
||||
// 实例化服务层 CoreInfo 结构体
|
||||
var NewCoreInfo = &CoreInfo{
|
||||
CoreInfoRepository: repository.NewCoreInfo,
|
||||
coreInfoRepository: repository.NewCoreInfo,
|
||||
}
|
||||
|
||||
// CoreInfo 核心网信息 服务层处理
|
||||
type CoreInfo struct {
|
||||
CoreInfoRepository *repository.CoreInfo // 核心网信息表
|
||||
coreInfoRepository *repository.CoreInfo // 核心网信息表
|
||||
}
|
||||
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r CoreInfo) FindByPage(query map[string]string) ([]model.CoreInfo, int64) {
|
||||
return r.CoreInfoRepository.SelectByPage(query)
|
||||
return r.coreInfoRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// Find 查询列表
|
||||
func (r CoreInfo) Find(core model.CoreInfo) []model.CoreInfo {
|
||||
return r.coreInfoRepository.Select(core)
|
||||
}
|
||||
|
||||
// FindById 通过ID查询
|
||||
@@ -30,9 +35,9 @@ func (r CoreInfo) FindById(id int64) model.CoreInfo {
|
||||
if id <= 0 {
|
||||
return model.CoreInfo{}
|
||||
}
|
||||
neHosts := r.CoreInfoRepository.SelectByIds([]int64{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
rows := r.coreInfoRepository.SelectByIds([]int64{id})
|
||||
if len(rows) > 0 {
|
||||
return rows[0]
|
||||
}
|
||||
return model.CoreInfo{}
|
||||
}
|
||||
@@ -44,24 +49,24 @@ func (r CoreInfo) Insert(param model.CoreInfo) int64 {
|
||||
param.OmcId = machine.Code
|
||||
}
|
||||
|
||||
return r.CoreInfoRepository.Insert(param)
|
||||
return r.coreInfoRepository.Insert(param)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r CoreInfo) Update(param model.CoreInfo) int64 {
|
||||
return r.CoreInfoRepository.Update(param)
|
||||
return r.coreInfoRepository.Update(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r CoreInfo) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
rows := r.CoreInfoRepository.SelectByIds(ids)
|
||||
rows := r.coreInfoRepository.SelectByIds(ids)
|
||||
if len(rows) <= 0 {
|
||||
return 0, fmt.Errorf("coreInfo.noData")
|
||||
}
|
||||
|
||||
if len(rows) == len(ids) {
|
||||
rows := r.CoreInfoRepository.DeleteByIds(ids)
|
||||
rows := r.coreInfoRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
@@ -70,7 +75,7 @@ func (r CoreInfo) DeleteByIds(ids []int64) (int64, error) {
|
||||
|
||||
// CheckUniqueGroupTitle 校验唯一名称和序号
|
||||
func (r CoreInfo) CheckUniqueGroupTitle(name, sn string, id int64) bool {
|
||||
uniqueId := r.CoreInfoRepository.CheckUnique(model.CoreInfo{
|
||||
uniqueId := r.coreInfoRepository.CheckUnique(model.CoreInfo{
|
||||
Name: name,
|
||||
SN: sn,
|
||||
})
|
||||
|
||||
@@ -128,9 +128,9 @@ func (r *NeConfig) FindById(id int64) model.NeConfig {
|
||||
if id <= 0 {
|
||||
return model.NeConfig{}
|
||||
}
|
||||
neHosts := r.neConfigRepository.SelectByIds([]int64{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
rows := r.neConfigRepository.SelectByIds([]int64{id})
|
||||
if len(rows) > 0 {
|
||||
return rows[0]
|
||||
}
|
||||
return model.NeConfig{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user