feat: 新增网元信息接口

This commit is contained in:
TsMask
2024-02-29 21:01:22 +08:00
parent ae9fe08a1f
commit 0fe92a0d51
7 changed files with 574 additions and 63 deletions

View File

@@ -69,9 +69,38 @@ func (r *NeInfoImpl) ClearNeCacheByNeType(neType string) bool {
return delOk
}
// SelectNeList 查询网元列表
func (r *NeInfoImpl) SelectNeList(ne model.NeInfo, bandStatus bool) []model.NeInfo {
list := r.neInfoRepository.SelectNeList(ne)
// SelectPage 根据条件分页查询
//
// bandStatus 带状态信息
func (r *NeInfoImpl) SelectPage(query map[string]any, bandStatus bool) map[string]any {
data := r.neInfoRepository.SelectPage(query)
// 网元直连读取网元服务状态
if bandStatus {
rows := data["rows"].([]model.NeInfo)
arr := &rows
for i := range *arr {
v := (*arr)[i]
result, err := NeState(v)
if err != nil {
(*arr)[i].ServerState = map[string]any{
"online": false,
}
continue
}
result["online"] = true
(*arr)[i].ServerState = result
}
}
return data
}
// SelectList 查询列表
//
// bandStatus 带状态信息
func (r *NeInfoImpl) SelectList(ne model.NeInfo, bandStatus bool) []model.NeInfo {
list := r.neInfoRepository.SelectList(ne)
// 网元直连读取网元服务状态
if bandStatus {
@@ -92,3 +121,53 @@ func (r *NeInfoImpl) SelectNeList(ne model.NeInfo, bandStatus bool) []model.NeIn
return list
}
// SelectByIds 通过ID查询
func (r *NeInfoImpl) SelectById(infoId string) model.NeInfo {
if infoId == "" {
return model.NeInfo{}
}
neInfos := r.neInfoRepository.SelectByIds([]string{infoId})
if len(neInfos) > 0 {
return neInfos[0]
}
return model.NeInfo{}
}
// Insert 新增信息
func (r *NeInfoImpl) Insert(neInfo model.NeInfo) string {
return r.neInfoRepository.Insert(neInfo)
}
// Update 修改信息
func (r *NeInfoImpl) Update(neInfo model.NeInfo) int64 {
return r.neInfoRepository.Update(neInfo)
}
// DeleteByIds 批量删除信息
func (r *NeInfoImpl) DeleteByIds(infoIds []string) (int64, error) {
// 检查是否存在
ids := r.neInfoRepository.SelectByIds(infoIds)
if len(ids) <= 0 {
return 0, fmt.Errorf("neHostCmd.noData")
}
if len(ids) == len(infoIds) {
rows := r.neInfoRepository.DeleteByIds(infoIds)
return rows, nil
}
// 删除信息失败!
return 0, fmt.Errorf("delete fail")
}
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
func (r *NeInfoImpl) CheckUniqueNeTypeAndNeId(neType, neId, infoId string) bool {
uniqueId := r.neInfoRepository.CheckUniqueNeTypeAndNeId(model.NeInfo{
NeType: neType,
NeId: neId,
})
if uniqueId == infoId {
return true
}
return uniqueId == ""
}