ref: v3变更,,表结构变更coreId/neId

This commit is contained in:
TsMask
2025-09-15 11:00:34 +08:00
parent 60004ded55
commit 38d2e2372a
193 changed files with 3255 additions and 3878 deletions

View File

@@ -8,58 +8,35 @@ import (
"be.ems/src/modules/ne_data/model"
)
// 实例化数据层 NEState 结构体
var NewNEState = &NEState{}
// 实例化数据层 NeState 结构体
var NewNeState = &NeState{}
// NEState 网元状态记录表 数据层处理
type NEState struct{}
// NeState 网元状态记录表 数据层处理
type NeState struct{}
// SelectByPage 分页查询集合
func (r NEState) SelectByPage(query model.NEStateQuery) ([]model.NEState, int64) {
tx := db.DB("").Model(&model.NEState{})
func (r NeState) SelectByPage(query model.NeStateQuery) ([]model.NeState, int64) {
tx := db.DB("").Model(&model.NeState{})
// 查询条件拼接
if query.NeType != "" {
tx = tx.Where("ne_type = ?", query.NeType)
if query.NeID != 0 {
tx = tx.Where("ne_id = ?", query.NeID)
}
if query.NeUID != "" {
tx = tx.Where("ne_uid = ?", query.NeUID)
if query.BeginTime != 0 {
tx = tx.Where("create_time >= ?", query.BeginTime)
}
if query.CoreUID != "" {
tx = tx.Where("core_uid = ?", query.CoreUID)
}
if query.BeginTime != "" {
startTime := query.BeginTime
if len(startTime) == 10 {
startTime = startTime + "000"
}
tx = tx.Where("create_time >= ?", startTime)
}
if query.EndTime != "" {
endTime := query.EndTime
if len(endTime) == 10 {
endTime = endTime + "999"
}
tx = tx.Where("create_time <= ?", endTime)
if query.EndTime != 0 {
tx = tx.Where("create_time <= ?", query.EndTime)
}
// 查询结果
var total int64 = 0
rows := []model.NEState{}
rows := []model.NeState{}
// 查询数量为0直接返回
if err := tx.Count(&total).Error; err != nil || total <= 0 {
return rows, total
}
// 排序
if query.SortField != "" {
sortField := query.SortField
if query.SortOrder == "desc" {
sortField = sortField + " desc"
}
tx = tx.Order(sortField)
}
// 查询数据分页
pageNum, pageSize := db.PageNumSize(query.PageNum, query.PageSize)
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
@@ -72,14 +49,18 @@ func (r NEState) SelectByPage(query model.NEStateQuery) ([]model.NEState, int64)
}
// SelectByIds 通过ID查询
func (r NEState) SelectByIds(ids []string) []model.NEState {
rows := []model.NEState{}
func (r NeState) SelectByIds(ids []string) []model.NeState {
rows := []model.NeState{}
if len(ids) <= 0 {
return rows
}
tx := db.DB("").Model(&model.NEState{})
tx := db.DB("").Model(&model.NeState{})
// 构建查询条件
tx = tx.Where("id in ?", ids)
if len(ids) == 1 {
tx = tx.Where("id = ?", ids[0])
} else {
tx = tx.Where("id in ?", ids)
}
// 查询数据
if err := tx.Find(&rows).Error; err != nil {
logger.Errorf("query find err => %v", err.Error())
@@ -89,12 +70,12 @@ func (r NEState) SelectByIds(ids []string) []model.NEState {
}
// DeleteByTime 删除信息
func (r NEState) DeleteByTime(ltTime int64) int64 {
func (r NeState) DeleteByTime(ltTime int64) int64 {
if ltTime <= 0 {
return 0
}
tx := db.DB("").Where("create_time < ?", ltTime)
if err := tx.Delete(&model.NEState{}).Error; err != nil {
if err := tx.Delete(&model.NeState{}).Error; err != nil {
logger.Errorf("delete err => %v", err.Error())
return 0
}
@@ -102,7 +83,7 @@ func (r NEState) DeleteByTime(ltTime int64) int64 {
}
// Insert 新增信息
func (r NEState) Insert(param model.NEState) int64 {
func (r NeState) Insert(param model.NeState) int64 {
param.CreateTime = time.Now().UnixMilli()
// 执行插入
if err := db.DB("").Create(&param).Error; err != nil {