67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// Package database define database operation functions
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"modelRT/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// FillingShortTokenModel define filling short token model info
|
|
func FillingShortTokenModel(ctx context.Context, tx *gorm.DB, attrItems []string, attrModel *model.ShortAttrInfo) error {
|
|
// TODO 重新创建tokenModel 及相关sql查询函数
|
|
// component, err := QueryComponentByLongToken(ctx, tx, attrItems[0])
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// attrModel.ComponentInfo = &component
|
|
return nil
|
|
}
|
|
|
|
// FillingLongTokenModel define filling long token model info
|
|
func FillingLongTokenModel(ctx context.Context, tx *gorm.DB, attrItems []string, attrModel *model.LongAttrInfo) error {
|
|
// TODO 重新创建tokenModel 及相关sql查询函数
|
|
// component, err := QueryComponentByShortToken(ctx, tx, attrItems[3])
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// attrModel.ComponentInfo = &component
|
|
return nil
|
|
}
|
|
|
|
// ParseDataIdentifierToken define function to parse data identifier token function
|
|
func ParseDataIdentifierToken(ctx context.Context, tx *gorm.DB, identToken string) (model.AttrModelInterface, error) {
|
|
// TODO 使用identityToken代替ShortAttrInfo等
|
|
attrSlice := strings.Split(identToken, ".")
|
|
attrLen := len(attrSlice)
|
|
if attrLen == 4 {
|
|
short := &model.ShortAttrInfo{
|
|
AttrGroupName: attrSlice[2],
|
|
AttrKey: attrSlice[3],
|
|
}
|
|
err := FillingShortTokenModel(ctx, tx, attrSlice, short)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// short.AttrValue = attrValue
|
|
return short, nil
|
|
} else if attrLen == 7 {
|
|
long := &model.LongAttrInfo{
|
|
AttrGroupName: attrSlice[5],
|
|
AttrKey: attrSlice[6],
|
|
}
|
|
err := FillingLongTokenModel(ctx, tx, attrSlice, long)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// long.AttrValue = attrValue
|
|
return long, nil
|
|
}
|
|
return nil, nil
|
|
}
|