feat(token-parse): 1. add func of parse token 2.add func of query grid、zone、station、component 3.modify package of constant
http://server.baseware.net:9000/project/datart/task/22
This commit is contained in:
parent
1b6211b34b
commit
3e833909d1
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AnchorParamListConfig define anchor params list config struct
|
// AnchorParamListConfig define anchor params list config struct
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,5 @@ const (
|
||||||
// LongAttrKeyLenth define long attribute key length
|
// LongAttrKeyLenth define long attribute key length
|
||||||
LongAttrKeyLenth int = 7
|
LongAttrKeyLenth int = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// component、base_extend、rated、setup、model、stable、bay、craft、integrity、behavior
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
// Package database define database operation functions
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"modelRT/model"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ParseAttrToken define return the attribute model interface based on the input attribute token
|
||||||
|
func ParseAttrToken(ctx context.Context, tx *gorm.DB, attrToken string) (model.AttrModelInterface, error) {
|
||||||
|
attrSlice := strings.Split(attrToken, ".")
|
||||||
|
attrLen := len(attrSlice)
|
||||||
|
if attrLen == 4 {
|
||||||
|
short := &model.ShortAttrInfo{
|
||||||
|
AttrGroupName: attrSlice[2],
|
||||||
|
AttrKey: attrSlice[3],
|
||||||
|
// TODO use redis query
|
||||||
|
// AttrValue: attrSlice[2],
|
||||||
|
}
|
||||||
|
err := FillingShortAttrModel(ctx, tx, attrSlice, short)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return short, nil
|
||||||
|
} else if attrLen == 7 {
|
||||||
|
long := &model.LongAttrInfo{
|
||||||
|
AttrGroupName: attrSlice[5],
|
||||||
|
AttrKey: attrSlice[6],
|
||||||
|
// TODO use redis query
|
||||||
|
// AttrValue: attrSlice[5],
|
||||||
|
}
|
||||||
|
err := FillingLongAttrModel(ctx, tx, attrSlice, long)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return long, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("invalid attribute token format")
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillingShortAttrModel define filling short attribute model info
|
||||||
|
func FillingShortAttrModel(ctx context.Context, tx *gorm.DB, attrItems []string, attrModel *model.ShortAttrInfo) error {
|
||||||
|
component, err := QueryComponentByNsPath(ctx, tx, attrItems[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
attrModel.ComponentInfo = &component
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillingLongAttrModel define filling long attribute model info
|
||||||
|
func FillingLongAttrModel(ctx context.Context, tx *gorm.DB, attrItems []string, attrModel *model.LongAttrInfo) error {
|
||||||
|
grid, err := QueryGridByName(ctx, tx, attrItems[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
attrModel.GridInfo = &grid
|
||||||
|
zone, err := QueryZoneByName(ctx, tx, attrItems[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
attrModel.ZoneInfo = &zone
|
||||||
|
station, err := QueryStationByName(ctx, tx, attrItems[2])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
attrModel.StationInfo = &station
|
||||||
|
component, err := QueryComponentByNsPath(ctx, tx, attrItems[3])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
attrModel.ComponentInfo = &component
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -69,3 +69,17 @@ func QueryComponentByPageID(ctx context.Context, tx *gorm.DB, uuid uuid.UUID) (o
|
||||||
}
|
}
|
||||||
return component, nil
|
return component, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryComponentByNsPath return the result of query circuit diagram component info by ns path from postgresDB
|
||||||
|
func QueryComponentByNsPath(ctx context.Context, tx *gorm.DB, nsPath string) (orm.Component, error) {
|
||||||
|
var component orm.Component
|
||||||
|
// ctx超时判断
|
||||||
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result := tx.WithContext(cancelCtx).Where("NAME = ? ", nsPath).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&component)
|
||||||
|
if result.Error != nil {
|
||||||
|
return orm.Component{}, result.Error
|
||||||
|
}
|
||||||
|
return component, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Package database define database operation functions
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"modelRT/orm"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryGridByName return the result of query circuit diagram grid info by name from postgresDB
|
||||||
|
func QueryGridByName(ctx context.Context, tx *gorm.DB, name string) (orm.Grid, error) {
|
||||||
|
var grid orm.Grid
|
||||||
|
// ctx超时判断
|
||||||
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result := tx.WithContext(cancelCtx).Where("NAME = ? ", name).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&grid)
|
||||||
|
if result.Error != nil {
|
||||||
|
return orm.Grid{}, result.Error
|
||||||
|
}
|
||||||
|
return grid, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Package database define database operation functions
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"modelRT/orm"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryStationByName return the result of query circuit diagram Station info by name from postgresDB
|
||||||
|
func QueryStationByName(ctx context.Context, tx *gorm.DB, name string) (orm.Station, error) {
|
||||||
|
var station orm.Station
|
||||||
|
// ctx超时判断
|
||||||
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result := tx.WithContext(cancelCtx).Where("NAME = ? ", name).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&station)
|
||||||
|
if result.Error != nil {
|
||||||
|
return orm.Station{}, result.Error
|
||||||
|
}
|
||||||
|
return station, nil
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/diagram"
|
"modelRT/diagram"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
"modelRT/orm"
|
"modelRT/orm"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Package database define database operation functions
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"modelRT/orm"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryZoneByName return the result of query circuit diagram Zone info by name from postgresDB
|
||||||
|
func QueryZoneByName(ctx context.Context, tx *gorm.DB, name string) (orm.Zone, error) {
|
||||||
|
var zone orm.Zone
|
||||||
|
// ctx超时判断
|
||||||
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result := tx.WithContext(cancelCtx).Where("NAME = ? ", name).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&zone)
|
||||||
|
if result.Error != nil {
|
||||||
|
return orm.Zone{}, result.Error
|
||||||
|
}
|
||||||
|
return zone, nil
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"modelRT/common/errcode"
|
"modelRT/common/errcode"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/network"
|
"modelRT/network"
|
||||||
"modelRT/orm"
|
"modelRT/orm"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/network"
|
"modelRT/network"
|
||||||
|
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"modelRT/alert"
|
"modelRT/alert"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
"modelRT/network"
|
"modelRT/network"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"modelRT/common/errcode"
|
"modelRT/common/errcode"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/database"
|
"modelRT/database"
|
||||||
"modelRT/diagram"
|
"modelRT/diagram"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"modelRT/alert"
|
"modelRT/alert"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
"modelRT/network"
|
"modelRT/network"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"modelRT/config"
|
"modelRT/config"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
|
|
||||||
"github.com/natefinch/lumberjack"
|
"github.com/natefinch/lumberjack"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
// Package model define model struct of model runtime service
|
// Package model define model struct of model runtime service
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import "modelRT/orm"
|
import (
|
||||||
|
"modelRT/orm"
|
||||||
|
)
|
||||||
|
|
||||||
// AttrModelInterface define basic attr model type interface
|
// AttrModelInterface define basic attr model type interface
|
||||||
type AttrModelInterface interface {
|
type AttrModelInterface interface {
|
||||||
|
|
@ -14,10 +16,69 @@ type AttrModelInterface interface {
|
||||||
|
|
||||||
// LongAttrInfo structure define long attribute key info of component
|
// LongAttrInfo structure define long attribute key info of component
|
||||||
type LongAttrInfo struct {
|
type LongAttrInfo struct {
|
||||||
AttrKey string `json:"attr_key"`
|
AttrGroupName string
|
||||||
|
AttrKey string
|
||||||
|
AttrValue interface{}
|
||||||
|
GridInfo *orm.Grid
|
||||||
|
ZoneInfo *orm.Zone
|
||||||
|
StationInfo *orm.Station
|
||||||
|
ComponentInfo *orm.Component
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGridInfo define return the grid information in the long attribute
|
||||||
|
func (l *LongAttrInfo) GetGridInfo() *orm.Grid {
|
||||||
|
return l.GridInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetZoneInfo define return the zone information in the long attribute
|
||||||
|
func (l *LongAttrInfo) GetZoneInfo() *orm.Zone {
|
||||||
|
return l.ZoneInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStationInfo define return the station information in the long attribute
|
||||||
|
func (l *LongAttrInfo) GetStationInfo() *orm.Station {
|
||||||
|
return l.StationInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetComponentInfo define return the component information in the long attribute
|
||||||
|
func (l *LongAttrInfo) GetComponentInfo() *orm.Component {
|
||||||
|
return l.ComponentInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsLocal define return the is_local information in the long attribute
|
||||||
|
func (l *LongAttrInfo) IsLocal() bool {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShortAttrInfo structure define short attribute key info of component
|
// ShortAttrInfo structure define short attribute key info of component
|
||||||
type ShortAttrInfo struct {
|
type ShortAttrInfo struct {
|
||||||
AttrKey string `json:"attr_key"`
|
AttrGroupName string
|
||||||
|
AttrKey string
|
||||||
|
AttrValue interface{}
|
||||||
|
ComponentInfo *orm.Component
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGridInfo define return the grid information in the short attribute
|
||||||
|
func (s *ShortAttrInfo) GetGridInfo() *orm.Grid {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetZoneInfo define return the zone information in the short attribute
|
||||||
|
func (s *ShortAttrInfo) GetZoneInfo() *orm.Zone {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStationInfo define return the station information in the short attribute
|
||||||
|
func (s *ShortAttrInfo) GetStationInfo() *orm.Station {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetComponentInfo define return the component information in the short attribute
|
||||||
|
func (s *ShortAttrInfo) GetComponentInfo() *orm.Component {
|
||||||
|
return s.ComponentInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsLocal define return the is_local information in the short attribute
|
||||||
|
func (s *ShortAttrInfo) IsLocal() bool {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
// Package model define model struct of model runtime service
|
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/orm"
|
"modelRT/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"modelRT/common/errcode"
|
"modelRT/common/errcode"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
|
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"modelRT/alert"
|
"modelRT/alert"
|
||||||
"modelRT/config"
|
"modelRT/config"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/diagram"
|
"modelRT/diagram"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"modelRT/config"
|
"modelRT/config"
|
||||||
constants "modelRT/constant"
|
"modelRT/constants"
|
||||||
"modelRT/diagram"
|
"modelRT/diagram"
|
||||||
"modelRT/logger"
|
"modelRT/logger"
|
||||||
"modelRT/network"
|
"modelRT/network"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue