作者 yangfu
提交者 yangfu

feat: query set

正在显示 87 个修改的文件 包含 3362 行增加16 行删除
version: v1
kind: HttpApi
metadata:
service: querySet
path: /query-sets
endpoints:
- method: createQuerySet
route:
post: /
- method: updateQuerySet
route:
put: /{Id}
- method: getQuerySet
route:
get: /{Id}
- method: removeQuerySet
route:
delete: /{Id}
- method: listQuerySet
route:
get: /
params:
- name: offset
- name: limit
- method: changeStatus
route:
post: /change-status
- method: copy
route:
post: /copy
- method: dependencyGraph
route:
post: /dependency-ggraph
- method: move
route:
post: /move
- method: rename
route:
post: /rename
- method: searchQuerySet
route:
post: /search
... ...
version: v1
kind: Attribute
metadata:
name: context
description: 扩展
type:
array: string
... ...
version: v1
kind: Attribute
metadata:
name: flag
description: 标识 1.group 2.query-set
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: name
description: 名称
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: pinName
description: 拼音(排序使用)
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: queryComponents
description: 查询组件
type:
array: string
... ...
version: v1
kind: Attribute
metadata:
name: querySetId
description: 查询集合ID
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: querySetInfo
description: 查询集合信息
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: status
description: 状态 1:启用 2:关闭 (子过程默认启用)
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: type
description: schema:方案 sub-process:子过程
type:
primitive: string
... ...
version: v1
kind: Schema
metadata:
name: querySet
description: 查询集合
attributes:
- ref: querySetId
required: true
- ref: type
required: true
- ref: flag
required: true
- ref: name
required: true
- ref: pinName
required: true
- ref: parentId
required: true
- ref: status
required: true
- ref: querySetInfo
required: true
- ref: queryComponents
required: true
- ref: sort
required: true
- ref: createdAt
required: true
- ref: updatedAt
required: true
- ref: deletedAt
required: true
- ref: context
required: true
... ...
version: v1
kind: Method
metadata:
name: changeStatus
type: command
description: 修改状态
payload:
- ref: querySetId
required: true
- ref: status
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: copy
type: command
description: 移动
payload:
- ref: flag
required: true
- ref: parentId
required: true
- ref: name
required: true
- ref: querySetId
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: createQuerySet
type: command
description: 创建查询集合服务
payload:
- ref: type
required: true
- ref: flag
required: true
- ref: name
required: true
- ref: parentId
required: false
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: dependencyGraph
type: query
description: 依赖关系图
payload:
- ref: querySetId
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: getQuerySet
type: query
description: 返回查询集合服务
payload:
- ref: querySetId
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: listQuerySet
type: query
description: 返回查询集合服务列表
payload:
- ref: offset
required: true
- ref: limit
required: true
result:
- ref: count
required: true
- name: querySets
type:
array: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: move
type: command
description: 移动
payload:
- ref: querySetId
required: true
- ref: parentId
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: removeQuerySet
type: command
description: 移除查询集合服务
payload:
- ref: querySetId
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: rename
type: command
description: 重命名
payload:
- ref: querySetId
required: true
- ref: name
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: searchQuerySet
type: query
description: 返回查询集合服务列表
payload:
- ref: offset
required: true
- ref: limit
required: true
result:
- ref: count
required: true
- name: querySets
type:
array: querySet
required: true
... ...
version: v1
kind: Method
metadata:
name: updateQuerySet
type: command
description: 更新查询集合服务
payload:
- ref: querySetId
required: true
result:
- name: querySet
type:
schema: querySet
required: true
... ...
version: v1
kind: Service
metadata:
name: querySet
description: 查询集合服务
... ...
... ... @@ -13,6 +13,7 @@ require (
github.com/go-pg/pg/v10 v10.10.6
github.com/go-redis/redis v6.15.9+incompatible
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0
github.com/google/uuid v1.3.0
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7
... ...
... ... @@ -2,7 +2,9 @@ package factory
import (
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
)
... ... @@ -25,3 +27,7 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) {
}
return dataTable, nil
}
func FastQuerySetServices(transactionContext application.TransactionContext) (*domainService.QuerySetService, error) {
return domainService.NewQuerySetService(transactionContext.(*pgTransaction.TransactionContext))
}
... ...
... ... @@ -111,3 +111,29 @@ func FastPgMappingRule(transactionContext application.TransactionContext, id int
}
return rep, mod, err
}
// FastPgQuerySet 快速返回查询集合
//
// transactionContext 事务
// id 对象唯一标识
func FastPgQuerySet(transactionContext application.TransactionContext, id int) (domain.QuerySetRepository, *domain.QuerySet, error) {
var rep domain.QuerySetRepository
var mod *domain.QuerySet
var err error
if value, err := CreateQuerySetRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"querySetId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该查询集合不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
... ...
... ... @@ -37,3 +37,11 @@ func CreateMappingRuleRepository(options map[string]interface{}) (domain.Mapping
}
return repository.NewMappingRuleRepository(transactionContext)
}
func CreateQuerySetRepository(options map[string]interface{}) (domain.QuerySetRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewQuerySetRepository(transactionContext)
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ChangeStatusCommand struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
// 状态 1:启用 2:关闭 (子过程默认启用)
Status int `cname:"状态 1:启用 2:关闭 (子过程默认启用)" json:"status" valid:"Required"`
}
func (changeStatusCommand *ChangeStatusCommand) Valid(validation *validation.Validation) {
if !(changeStatusCommand.Status == domain.StatusOn || changeStatusCommand.Status == domain.StatusOff) {
validation.Error("状态值有误")
}
}
func (changeStatusCommand *ChangeStatusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(changeStatusCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(changeStatusCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CopyCommand struct {
// Schema:方案 SubProcess:子过程
Type string `cname:"类型" json:"type" valid:"Required"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId" valid:"Required"`
// 名称
Name string `cname:"名称" json:"name" valid:"Required"`
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
}
func (cmd *CopyCommand) Valid(validation *validation.Validation) {
if err := domain.ValidQuerySetType(cmd.Type); err != nil {
validation.Error(err.Error())
return
}
}
func (cmd *CopyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateQuerySetCommand struct {
// Schema:方案 SubProcess:子过程
Type string `cname:"类型" json:"type" valid:"Required"`
// 标识
Flag string `cname:"标识" json:"flag" valid:"Required"`
// 名称
Name string `cname:"名称" json:"name" valid:"Required"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId,omitempty"`
}
func (cmd *CreateQuerySetCommand) Valid(validation *validation.Validation) {
if err := domain.ValidQuerySetType(cmd.Type); err != nil {
validation.Error(err.Error())
return
}
if err := domain.ValidQuerySetFlag(cmd.Flag); err != nil {
validation.Error(err.Error())
return
}
}
func (cmd *CreateQuerySetCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type MoveCommand struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId" valid:"Required"`
// 排序
Index int `cname:"序号" json:"index" valid:"Required"`
}
func (moveCommand *MoveCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (moveCommand *MoveCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(moveCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(moveCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveQuerySetCommand struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
}
func (removeQuerySetCommand *RemoveQuerySetCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeQuerySetCommand *RemoveQuerySetCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeQuerySetCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeQuerySetCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RenameCommand struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
// 名称
Name string `cname:"名称" json:"name" valid:"Required"`
}
func (renameCommand *RenameCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (renameCommand *RenameCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(renameCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(renameCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateQuerySetCommand struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
QueryComponents []*domain.QueryComponent `cname:"查询组件" json:"queryComponents" valid:"Required"`
}
func (updateQuerySetCommand *UpdateQuerySetCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateQuerySetCommand *UpdateQuerySetCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateQuerySetCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateQuerySetCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
type QuerySetDetailDto struct {
// 查询集合ID
QuerySetId int `json:"querySetId"`
// Schema:方案 SubProcess:子过程
Type string `json:"type"`
// 标识 分组:Group 子过程/方案:Set
Flag string `json:"flag"`
// 名称
Name string `json:"name"`
// 查询组件
QueryComponents []*domain.QueryComponent `json:"queryComponents"`
}
func (d *QuerySetDetailDto) Load(m *domain.QuerySet) *QuerySetDetailDto {
d.QuerySetId = m.QuerySetId
d.Type = m.Type
d.Flag = m.Flag
d.Name = m.Name
d.QueryComponents = m.QueryComponents
return d
}
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
type QuerySetDto struct {
// 查询集合ID
QuerySetId int `json:"querySetId"`
// Schema:方案 SubProcess:子过程
Type string `json:"type"`
// 标识 分组:Group 子过程/方案:Set
Flag string `json:"flag"`
// 名称
Name string `json:"name"`
// 父级ID
ParentId int `json:"parentId"`
// 状态 1:启用 2:关闭 (子过程默认启用)
Status int `json:"status"`
// 排序
Sort int `json:"sort"`
}
func (d *QuerySetDto) Load(m *domain.QuerySet) {
d.QuerySetId = m.QuerySetId
d.Type = m.Type
d.Flag = m.Flag
d.Name = m.Name
d.ParentId = m.ParentId
d.Status = m.Status
d.Sort = m.Sort
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type DependencyGraphQuery struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
}
func (dependencyGraphQuery *DependencyGraphQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (dependencyGraphQuery *DependencyGraphQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(dependencyGraphQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(dependencyGraphQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetQuerySetQuery struct {
// 查询集合ID
QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
}
func (getQuerySetQuery *GetQuerySetQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getQuerySetQuery *GetQuerySetQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getQuerySetQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getQuerySetQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListQuerySetQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listQuerySetQuery *ListQuerySetQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listQuerySetQuery *ListQuerySetQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listQuerySetQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listQuerySetQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/adapter/utils"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchQuerySetQuery struct {
Type string `cname:"类型" json:"type" valid:"Required"`
Flag string `cname:"标识" json:"flag"`
MatchName string `cname:"匹配名称" json:"matchName"`
SortByName string `json:"sortByName"`
SortByTime string `json:"sortByTime"`
}
func (searchQuerySetQuery *SearchQuerySetQuery) Valid(validation *validation.Validation) {
optionsValues := []string{"asc", "desc"}
if searchQuerySetQuery.SortByName != "" && !utils.InSlice(strings.ToLower(searchQuerySetQuery.SortByName), optionsValues) {
validation.Error("排序值有误 ASC|DESC")
}
if searchQuerySetQuery.SortByTime != "" && !utils.InSlice(strings.ToLower(searchQuerySetQuery.SortByTime), optionsValues) {
validation.Error("排序值有误 ASC|DESC")
}
}
func (searchQuerySetQuery *SearchQuerySetQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchQuerySetQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchQuerySetQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/command"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/dto"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/query"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
)
// 查询集合服务
type QuerySetService struct {
}
// 修改状态
func (querySetService *QuerySetService) ChangeStatus(ctx *domain.Context, changeStatusCommand *command.ChangeStatusCommand) (interface{}, error) {
if err := changeStatusCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.ChangeStatus(ctx, changeStatusCommand.QuerySetId, changeStatusCommand.Status); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 移动
func (querySetService *QuerySetService) Copy(ctx *domain.Context, copyCommand *command.CopyCommand) (interface{}, error) {
if err := copyCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Copy(ctx, copyCommand.QuerySetId, copyCommand.Type, copyCommand.ParentId, copyCommand.Name); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 创建查询集合服务
func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, createQuerySetCommand *command.CreateQuerySetCommand) (interface{}, error) {
if err := createQuerySetCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
newQuerySet := &domain.QuerySet{
Type: createQuerySetCommand.Type,
Flag: createQuerySetCommand.Flag,
Name: createQuerySetCommand.Name,
ParentId: createQuerySetCommand.ParentId,
}
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Create(ctx, newQuerySet); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 依赖关系图
func (querySetService *QuerySetService) DependencyGraph(ctx *domain.Context, dependencyGraphQuery *query.DependencyGraphQuery) (interface{}, error) {
if err := dependencyGraphQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 返回查询集合服务
func (querySetService *QuerySetService) GetQuerySet(ctx *domain.Context, getQuerySetQuery *query.GetQuerySetQuery) (interface{}, error) {
if err := getQuerySetQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
_, querySet, err := factory.FastPgQuerySet(transactionContext, getQuerySetQuery.QuerySetId)
if err != nil {
return nil, factory.FastError(err)
}
return (&dto.QuerySetDetailDto{}).Load(querySet), nil
}
// 返回查询集合服务列表
func (querySetService *QuerySetService) ListQuerySet(ctx *domain.Context, listQuerySetQuery *query.ListQuerySetQuery) (interface{}, error) {
if err := listQuerySetQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var querySetRepository domain.QuerySetRepository
if value, err := factory.CreateQuerySetRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
querySetRepository = value
}
if count, querySets, err := querySetRepository.Find(tool_funs.SimpleStructToMap(listQuerySetQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"querySets": querySets,
}, nil
}
}
// 移动
func (querySetService *QuerySetService) Move(ctx *domain.Context, moveCommand *command.MoveCommand) (interface{}, error) {
if err := moveCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Move(ctx, moveCommand.QuerySetId, moveCommand.ParentId, moveCommand.Index); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 移除查询集合服务
func (querySetService *QuerySetService) RemoveQuerySet(ctx *domain.Context, removeQuerySetCommand *command.RemoveQuerySetCommand) (interface{}, error) {
if err := removeQuerySetCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Delete(ctx, removeQuerySetCommand.QuerySetId); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 重命名
func (querySetService *QuerySetService) Rename(ctx *domain.Context, renameCommand *command.RenameCommand) (interface{}, error) {
if err := renameCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Rename(ctx, renameCommand.QuerySetId, renameCommand.Name); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 返回查询集合服务列表
func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, searchQuerySetQuery *query.SearchQuerySetQuery) (interface{}, error) {
if err := searchQuerySetQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
QuerySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
options := utils.ObjectToMap(searchQuerySetQuery)
options["context"] = ctx
count, querySets, err := QuerySetRepository.Find(options)
if err != nil {
return nil, factory.FastError(err)
}
var result = make([]*dto.QuerySetDto, 0)
for _, set := range querySets {
var item = &dto.QuerySetDto{}
item.Load(set)
result = append(result, item)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"querySets": result,
}, nil
}
// 更新查询集合服务
func (querySetService *QuerySetService) UpdateQuerySet(ctx *domain.Context, updateQuerySetCommand *command.UpdateQuerySetCommand) (interface{}, error) {
if err := updateQuerySetCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := factory.FastQuerySetServices(transactionContext)
if err := svr.Update(ctx, updateQuerySetCommand.QuerySetId, updateQuerySetCommand.QueryComponents); err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
func NewQuerySetService(options map[string]interface{}) *QuerySetService {
newQuerySetService := &QuerySetService{}
return newQuerySetService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ApplyOnCommand struct {
// 表Id
TableId int `cname:"表Id" json:"tableId" valid:"Required"`
// 模块
Module int `json:"module"`
}
func (c *ApplyOnCommand) Valid(validation *validation.Validation) {
}
func (c *ApplyOnCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(c)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(c).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ValidExprSqlCommand struct {
domain.FieldExpr
}
func (c *ValidExprSqlCommand) Valid(validation *validation.Validation) {
}
func (c *ValidExprSqlCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(c)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(c).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -17,6 +17,8 @@ type TableDetailDto struct {
ManualFields []*domain.Field `json:"manualFields"`
// 数据列
Fields []*domain.Field `json:"fields"`
// 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块
Module int `json:"module"`
}
func (d *TableDetailDto) Load(table *domain.Table, mainTable *domain.Table) {
... ... @@ -34,4 +36,7 @@ func (d *TableDetailDto) Load(table *domain.Table, mainTable *domain.Table) {
if len(d.ManualFields) == 0 {
d.ManualFields = make([]*domain.Field, 0)
}
if table.TableInfo != nil {
d.Module = table.TableInfo.ApplyOnModule
}
}
... ...
... ... @@ -13,15 +13,34 @@ type TableDto struct {
TableType string `json:"tableType"`
// 名称
Name string `json:"name"`
// 对应数据库名称
SQLName string `json:"sqlName,omitempty"`
// 父级ID
ParentId int `json:"parentId"`
// 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块
Module int `json:"module"`
// 表字段
Fields []*domain.Field `json:"fields"`
}
func (d *TableDto) Load(m *domain.Table) {
func (d *TableDto) Load(m *domain.Table) *TableDto {
d.TableId = m.TableId
d.TableType = m.TableType
d.Name = m.Name
d.ParentId = m.ParentId
if m.TableInfo != nil {
d.Module = m.TableInfo.ApplyOnModule
}
d.Fields = make([]*domain.Field, 0)
return d
}
func (d *TableDto) SetDetailStructInfo(m *domain.Table) *TableDto {
d.Fields = append(d.Fields, m.DataFields...)
d.Fields = append(d.Fields, m.ManualFields...)
d.SQLName = m.SQLName
return d
}
func SuitTableByView(tables []*TableDto, view string, name string) []*TableDto {
... ...
... ... @@ -13,14 +13,15 @@ type SearchTableQuery struct {
// 表名称
Name string `cname:"表名称" json:"name"`
ViewType string `cname:"视图类型 full:完整 main:主表关系" json:"viewType"`
// 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表
// 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表 SubProcess:子过程 Schema:方案
TableTypes []string `cname:"表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表" json:"tableTypes"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId"`
// 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块
Module int `json:"module"`
// 父级ID
ParentTableId int `cname:"父级ID" json:"parentTableId"`
ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"ReturnDetailStructInfo"`
Context *domain.Context
}
... ...
... ... @@ -34,6 +34,7 @@ func (tableService *TableService) DBTablePreview(ctx *domain.Context, cmd *comma
}
var options = starrocks.QueryOptions{
Table: table,
TableName: table.SQLName,
Select: table.Fields(true),
Context: ctx,
... ... @@ -50,6 +51,14 @@ func (tableService *TableService) DBTablePreview(ctx *domain.Context, cmd *comma
},
In: []interface{}{domain.CommonLog.ToString()},
}})
case domain.DBTableQuerySetLog.ToInt():
options.SetCondition([]domain.Condition{{
Field: &domain.Field{
SQLName: "log_type",
SQLType: domain.String.ToString(),
},
In: []interface{}{domain.QuerySetLog.ToString()},
}})
}
dataTable, err = starrocks.Query(options, starrocks.WrapQueryFuncWithDB(pg.GormDB))
... ...
... ... @@ -4,12 +4,15 @@ import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/zeromicro/go-zero/core/collection"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
"strings"
)
// 表服务
... ... @@ -229,6 +232,9 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i
for _, table := range tables {
var item = &dto.TableDto{}
item.Load(table)
if searchQuery.ReturnDetailStructInfo {
item.SetDetailStructInfo(table)
}
result = append(result, item)
}
... ... @@ -258,7 +264,7 @@ func (tableService *TableService) RelationGraph(searchQuery *query.SearchTableQu
}()
tableRepository, _, _ := factory.FastPgTable(transactionContext, 0)
name :=searchQuery.Name
name := searchQuery.Name
searchQuery.Name = ""
_, tables, err := tableRepository.Find(utils.ObjectToMap(searchQuery))
if err != nil {
... ... @@ -275,10 +281,10 @@ func (tableService *TableService) RelationGraph(searchQuery *query.SearchTableQu
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result = dto.SuitTableByView(result,searchQuery.ViewType,name)
result = dto.SuitTableByView(result, searchQuery.ViewType, name)
return map[string]interface{}{
"count": len(result),
"tables":result,
"tables": result,
}, nil
}
... ... @@ -380,6 +386,66 @@ func (tableService *TableService) AddTableStruct(ctx *domain.Context, cmd *comma
return tableDetailDto, nil
}
// 应用于
func (tableService *TableService) ApplyOn(ctx *domain.Context, cmd *command.ApplyOnCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
tableRepository, table, err := factory.FastPgTable(transactionContext, cmd.TableId)
if err != nil {
return nil, factory.FastError(err)
}
if table.TableInfo == nil {
table.TableInfo = domain.NewTableInfo().SetApplyOn(cmd.Module)
} else {
table.TableInfo.SetApplyOn(cmd.Module)
}
table, err = tableRepository.Save(table)
if err != nil {
return nil, factory.FastError(err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command.ValidExprSqlCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
var result string = "成功"
set := collection.NewSet()
for _, f := range cmd.TableFields {
set.AddStr(f.TableSqlName)
}
sql := "select " + cmd.ExprSql + " as expr"
if len(set.KeysStr()) > 0 {
sql += " from " + strings.Join(set.KeysStr(), ",")
}
sql += " limit 1"
tx := starrocks.DB.Exec(sql)
if tx.Error != nil {
result = tx.Error.Error()
}
return map[string]string{
"result": result,
}, nil
}
func NewTableService(options map[string]interface{}) *TableService {
newTableService := &TableService{}
return newTableService
... ...
... ... @@ -31,6 +31,7 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command
}
var options = starrocks.QueryOptions{
Table: table,
TableName: table.SQLName,
Select: table.Fields(true),
}
... ...
... ... @@ -21,6 +21,20 @@ var (
FileVerify OperationType = "FileVerify" // 文件校验
ExcelTableEdit OperationType = "ExcelTableEdit" // 文档表格编辑
CreateSchema OperationType = "CreateSchema" // 新增方案
CreateSubProcess OperationType = "CreateSubProcess" // 新增子过程
AddSetCondition OperationType = "AddSetCondition" // 新增条件判断
EditSetCondition OperationType = "EditSetCondition" // 编辑条件判断
DeleteSetCondition OperationType = "DeleteSetCondition" // 删除条件判断
AddSelectCondition OperationType = "AddSelectCondition" // 新增拆分规则
EditSelectCondition OperationType = "EditSelectCondition" // 编辑拆分规则
DeleteSelectCondition OperationType = "DeleteSelectCondition" // 删除拆分规则
CopyQuerySet OperationType = "CopyQuerySet" // 复制
RenameQuerySet OperationType = "RenameQuerySet" // 重命名
DeleteQuerySet OperationType = "DeleteQuerySet" // 删除
UnKnown OperationType = "UnKnown" // 未知
)
var OperationTypeMap = map[string]string{
... ... @@ -34,11 +48,24 @@ var OperationTypeMap = map[string]string{
FileUpload.ToString(): "文件上传",
FileVerify.ToString(): "文件校验",
ExcelTableEdit.ToString(): "文档表格编辑",
CreateSchema.ToString(): "新增方案",
CreateSubProcess.ToString(): "新增子过程",
AddSetCondition.ToString(): "新增条件判断",
EditSetCondition.ToString(): "编辑条件判断",
DeleteSetCondition.ToString(): "删除条件判断",
AddSelectCondition.ToString(): "新增拆分规则",
EditSelectCondition.ToString(): "编辑拆分规则",
DeleteSelectCondition.ToString(): "删除拆分规则",
CopyQuerySet.ToString(): "复制",
RenameQuerySet.ToString(): "重命名",
DeleteQuerySet.ToString(): "删除",
}
var (
VerifiedStepLog LogType = "VerifiedStepLog"
CommonLog LogType = "CommonLog"
QuerySetLog LogType = "QuerySetLog"
)
var (
... ... @@ -67,6 +94,8 @@ var ObjectTypeMap = map[string]string{
SourceFile.ToString(): "源文件",
VerifiedFile.ToString(): "校验文件",
ObjectDBTable: "业务表",
SchemaTable.ToString(): "方案",
SubProcessTable.ToString(): "子过程",
}
var (
... ... @@ -207,6 +236,64 @@ var DBTables = map[int]*Table{
},
},
},
DBTableQuerySetLog.ToInt(): &Table{
TableId: 1,
TableType: ObjectDBTable,
Name: "日志信息",
SQLName: "metadata.logs",
DataFieldIndex: 6,
PK: &Field{
Index: 0,
Name: "日志ID",
SQLName: "log_id",
SQLType: Int.ToString(),
Flag: PKField,
},
DataFields: []*Field{
{
Index: 1,
Name: "方案/子过程",
SQLName: "object_name",
SQLType: String.ToString(),
Flag: MainTableField,
},
{
Index: 2,
Name: "类型",
SQLName: "object_type",
SQLType: String.ToString(),
Flag: MainTableField,
},
{
Index: 3,
Name: "操作类型",
SQLName: "operation_type",
SQLType: String.ToString(),
Flag: MainTableField,
},
{
Index: 4,
Name: "日志内容",
SQLName: "content",
SQLType: String.ToString(),
Flag: MainTableField,
},
{
Index: 5,
Name: "操作时间",
SQLName: "log_time", //"created_at",
SQLType: String.ToString(),
Flag: MainTableField,
},
{
Index: 6,
Name: "操作人",
SQLName: "operator_name",
SQLType: String.ToString(),
Flag: MainTableField,
},
},
},
}
type DBTable int
... ... @@ -217,7 +304,7 @@ func (t DBTable) ToInt() int {
const (
DBTableTableOperateLog DBTable = 1
DBTableBusinessLog DBTable = 2
DBTableQuerySetLog DBTable = 2
)
const (
... ... @@ -336,3 +423,15 @@ var MapActionExtractColumn = map[string]Action{
Desc: "按数值提取", Name: "by-number",
},
}
const (
StatusOn = 1
StatusOff = 2
)
const (
ModuleAll = ModuleDigitalCenter | ModuleQuerySetCenter | ModuleCalculateCenter
ModuleDigitalCenter = 1
ModuleQuerySetCenter = 2
ModuleCalculateCenter = 4
)
... ...
... ... @@ -31,6 +31,10 @@ func (l LogEntry) Context() *Context {
return l.ctx
}
func (l LogEntry) OperateType() string {
return l.OperationType
}
func NewLogEntry(fileOrTableName string, objectType string, operationType OperationType, ctx *Context) LogEntry {
return LogEntry{
ObjectName: fileOrTableName,
... ...
package domain
import (
"fmt"
"github.com/google/uuid"
"github.com/zeromicro/go-zero/core/collection"
"sort"
"time"
)
// 查询集合
type QuerySet struct {
// 查询集合ID
QuerySetId int `json:"querySetId"`
// Schema:方案 SubProcess:子过程
Type string `json:"type"`
// 标识 分组:Group 子过程/方案:Set
Flag string `json:"flag"`
// 名称
Name string `json:"name"`
// 拼音(排序使用)
PinName string `json:"pinName"`
// 父级ID
ParentId int `json:"parentId"`
// 状态 1:启用 2:关闭 (子过程默认启用)
Status int `json:"status"`
// 查询集合信息
QuerySetInfo *QuerySetInfo `json:"querySetInfo"`
// 查询组件
QueryComponents []*QueryComponent `json:"queryComponents"`
// 排序
Sort int `json:"sort"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 扩展
Context *Context `json:"context"`
}
type QuerySetRepository interface {
Save(querySet *QuerySet) (*QuerySet, error)
Remove(querySet *QuerySet) (*QuerySet, error)
FindOne(queryOptions map[string]interface{}) (*QuerySet, error)
Find(queryOptions map[string]interface{}) (int64, []*QuerySet, error)
}
func (querySet *QuerySet) Identify() interface{} {
if querySet.QuerySetId == 0 {
return nil
}
return querySet.QuerySetId
}
func (querySet *QuerySet) Update(queryComponents []*QueryComponent, tableId int) error {
for i := range queryComponents {
if len(queryComponents[i].Id) == 0 {
uuid, _ := uuid.NewUUID()
queryComponents[i].Id = uuid.String()
}
for j := range queryComponents[i].Conditions {
if len(queryComponents[i].Conditions[j].Id) == 0 {
uuid, _ := uuid.NewUUID()
queryComponents[i].Conditions[j].Id = uuid.String()
}
}
for j := range queryComponents[i].Selects {
if len(queryComponents[i].Selects[j].Id) == 0 {
uuid, _ := uuid.NewUUID()
queryComponents[i].Selects[j].Id = uuid.String()
}
}
}
querySet.QueryComponents = queryComponents
if querySet.QuerySetInfo.BindTableId == 0 {
querySet.QuerySetInfo.BindTableId = tableId
}
querySet.UpdatedAt = time.Now()
return nil
}
func ValidQuerySetType(t string) error {
if t == SchemaTable.ToString() || t == SubProcessTable.ToString() {
return nil
}
return fmt.Errorf("类型有误")
}
func ValidQuerySetFlag(t string) error {
if t == FlagGroup || t == FlagSet {
return nil
}
return fmt.Errorf("标识有误")
}
func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent) []int {
set := collection.NewSet()
for i := range queryComponents {
for _, c := range queryComponents[i].Conditions {
for _, f := range c.FieldLeft.TableFields {
set.AddInt(f.TableId)
}
for _, f := range c.FieldRight.TableFields {
set.AddInt(f.TableId)
}
}
for _, s := range queryComponents[i].Selects {
for _, f := range s.FieldLeft.TableFields {
set.AddInt(f.TableId)
}
for _, f := range s.FieldRight.TableFields {
set.AddInt(f.TableId)
}
}
}
res := set.KeysInt()
sort.Ints(res)
return res
}
... ...
package domain
var (
SchemaTable TableType = "Schema"
SubProcessTable TableType = "SubProcess"
)
var (
FlagGroup = "Group"
FlagSet = "Set"
)
var (
TableSplit SelectExprType = "TableSplit" //拆分
SplitAssign SelectExprType = "SplitAssign" //拆分赋值
NormalAssign SelectExprType = "NormalAssign" //正常赋值
)
type SelectExprType string
type QueryComponent struct {
Id string `json:"id"`
MasterTable QueryComponentTable `json:"masterTable"`
Conditions []ConditionExpr `json:"conditions"`
JoinTables []QueryComponentTable `json:"-"` //joinTables
Selects []SelectExprGroup `json:"selects"`
SelectFromTables []QueryComponentTable `json:"-"` //selectTables
Description string `json:"description"`
}
type ConditionExpr struct { // 条件表达式
Id string `json:"id"`
FieldLeft FieldExpr `json:"fieldLeft"`
FieldRight FieldExpr `json:"fieldRight"`
OperatorSymbol string `json:"operatorSymbol"`
AndOr string `json:"andOr"` // and or
}
type SelectExpr struct { // 查询表达式
Id string `json:"id"`
FieldLeft FieldExpr `json:"fieldLeft"`
FieldRight FieldExpr `json:"fieldRight"` // has value when type is equal to 1
Type string `json:"type"` // 1.拆分 2.拆方赋值 3.正常赋值
//SubGroup []SelectExpr `json:"subGroup,omitempty"`
}
type SelectExprGroup struct { // 查询表达式
SelectExpr
SubSelects []SelectExpr `json:"subSelects,omitempty"`
}
type FieldExpr struct {
//LabelColumns []LabelColumn `json:"labelColumns"`
TableFields []TableField `json:"tableFields"`
//ExprHuman string `json:"exprHuman"`
ExprSql string `json:"exprSql"`
}
type LabelColumn struct {
Column TableField `json:"column,omitempty"`
LabelExpr string `json:"labelExpr"`
}
type TableField struct {
TableId int `json:"tableId"`
TableName string `json:"tableName"`
TableSqlName string `json:"tableSqlName"`
FieldName string `json:"fieldName"`
FieldSqlName string `json:"fieldSqlName"`
}
type QueryComponentTable struct {
// 表Id
TableId int `json:"tableId"`
// 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表
TableType string `json:"tableType"`
// 名称
Name string `json:"name"`
// 对应数据库名称
SQLName string `json:"sqlName"`
// 父级ID
ParentId int `json:"parentId"`
// 所有列
Fields []*Field `json:"fields"`
}
type Join struct {
TableId int
TableName string
TableSqlName string
Conditions []ConditionExpr
On SelectExpr
}
func NewQueryComponentTable(t *Table) QueryComponentTable {
return QueryComponentTable{
TableId: t.TableId,
TableType: t.TableType,
Name: t.Name,
SQLName: t.SQLName,
ParentId: t.ParentId,
Fields: t.Fields(false),
}
}
func ConditionsToMapById(items []*ConditionExpr) map[string]*ConditionExpr {
var res = make(map[string]*ConditionExpr)
for i := range items {
res[items[i].Id] = items[i]
}
return res
}
func SelectsToMapById(items []*SelectExprGroup) map[string]*SelectExprGroup {
var res = make(map[string]*SelectExprGroup)
for i := range items {
res[items[i].Id] = items[i]
}
return res
}
... ...
package domain
import (
"github.com/google/gofuzz"
"github.com/linmadan/egglib-go/utils/json"
"log"
"testing"
)
func TestMockComponents(t *testing.T) {
f := fuzz.New()
var components QueryComponent
f.Fuzz(&components)
d := json.MarshalToString(components)
log.Println(d)
}
... ...
package domain
type QuerySetInfo struct {
BindTableId int // 查询集绑定的表
//DependentTables []int // 依赖的表
}
... ...
... ... @@ -40,6 +40,8 @@ type Table struct {
RowCount int `json:"rowCount,omitempty"`
// 扩展
Context *Context `json:"context"`
// 表信息
TableInfo *TableInfo `json:"tableInfo"`
}
type TableRepository interface {
... ... @@ -67,6 +69,11 @@ func (table *Table) WithContext(ctx *Context) *Table {
return table
}
func (table *Table) WithPrefix(prefix string) *Table {
table.SQLName = fmt.Sprintf("%v_%v", prefix, table.SQLName)
return table
}
func (table *Table) WithParentId(parentId int) *Table {
table.ParentId = parentId
return table
... ...
package domain
type TableInfo struct {
// 应用于模块 1:数控中心 2:拆解模块 4:计算模块
ApplyOnModule int `json:"module"`
// 依赖关联的表
DependencyTables []int `json:"dependencyTables"`
}
func (t *TableInfo) SetApplyOn(applyOn int) *TableInfo {
t.ApplyOnModule = applyOn
return t
}
func (t *TableInfo) SetDependencyTables(tableIds []int) *TableInfo {
t.DependencyTables = tableIds
return t
}
func NewTableInfo() *TableInfo {
return &TableInfo{
ApplyOnModule: 0,
DependencyTables: make([]int, 0),
}
}
... ...
package dao
import pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
func QuerySetCurrentSort(ptr *pgTransaction.TransactionContext, t string, parentId int) (int, error) {
sql := "select max(sort) sort from metadata.query_sets where type =? and parent_id = ?"
var result struct {
Sort int
}
if _, err := ptr.PgTx.Query(&result, sql, t, parentId); err != nil {
return 0, err
}
return result.Sort + 1, nil
}
... ...
... ... @@ -145,6 +145,7 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain.
table.CreatedAt = time.Now()
table.UpdatedAt = time.Now()
table.RowCount = rowCount
table.TableInfo = domain.NewTableInfo()
return table
}
... ...
... ... @@ -32,6 +32,7 @@ func FastLog(transactionContext *pgTransaction.TransactionContext, logType domai
func (ptr *PGLogService) Log(logType domain.LogType, sourceId int, logEntry Log) error {
logRepository, _ := repository.NewLogRepository(ptr.transactionContext)
entry := logEntry.Entry()
entry.OperationType = logEntry.OperateType()
log := &domain.Log{
LogType: logType.ToString(),
SourceId: sourceId,
... ... @@ -45,6 +46,9 @@ func (ptr *PGLogService) Log(logType domain.LogType, sourceId int, logEntry Log)
Context: logEntry.Context(),
LogTime: entry.LogTime,
}
if entry.OperationType == domain.UnKnown.ToString() {
return nil
}
if v, ok := logEntry.Context().GetValue(domain.ContextWithLogLevel); ok {
log.Entry.Level = string(v.(domain.LogLevel))
... ... @@ -64,6 +68,7 @@ type Log interface {
Content() string
Entry() domain.LogEntry
Context() *domain.Context
OperateType() string
}
var _ Log = (*FileUploadSuccessLog)(nil)
... ... @@ -317,3 +322,77 @@ func (l *ExcelTableEditLog) Content() string {
msg := fmt.Sprintf("%v:%v", l.OperateName, strings.Join(fieldsName, "、"))
return msg
}
/* *********************************************拆解模块************************************************** */
type CreateQuerySetLog struct {
domain.LogEntry
Qs *domain.QuerySet
}
func (l *CreateQuerySetLog) OperateType() string {
if l.Qs.Type == domain.SchemaTable.ToString() && l.Qs.Flag == domain.FlagSet {
return domain.CreateSchema.ToString()
}
if l.Qs.Type == domain.SubProcessTable.ToString() && l.Qs.Flag == domain.FlagSet {
return domain.CreateSubProcess.ToString()
}
return domain.UnKnown.ToString()
}
func (l *CreateQuerySetLog) Content() string {
return "新增成功"
}
type RenameQuerySetLog struct {
domain.LogEntry
OldName string
NewName string
}
func (l *RenameQuerySetLog) OperateType() string {
return domain.RenameQuerySet.ToString()
}
func (l *RenameQuerySetLog) Content() string {
return fmt.Sprintf(`"%s"重命名为"%v"`, l.OldName, l.NewName)
}
type DeleteQuerySetLog struct {
domain.LogEntry
DeleteList []*domain.QuerySet
}
func (l *DeleteQuerySetLog) OperateType() string {
if len(l.DeleteList) == 0 {
return domain.UnKnown.ToString()
}
return domain.DeleteQuerySet.ToString()
}
func (l *DeleteQuerySetLog) Content() string {
names := make([]string, 0)
for i := range l.DeleteList {
names = append(names, "\""+l.DeleteList[i].Name+"\"")
}
t := domain.EnumsDescription(domain.ObjectTypeMap, l.DeleteList[0].Type)
if l.DeleteList[0].Flag == domain.FlagGroup {
t += "分组"
}
return fmt.Sprintf(`%s%s删除成功`, t, strings.Join(names, "、"))
}
type CopyQuerySetLog struct {
domain.LogEntry
From *domain.QuerySet
To *domain.QuerySet
}
func (l *CopyQuerySetLog) OperateType() string {
return domain.CopyQuerySet.ToString()
}
func (l *CopyQuerySetLog) Content() string {
return fmt.Sprintf(`%s"%s"复制为%s"%s""`, domain.EnumsDescription(domain.ObjectTypeMap, l.From.Type), l.From.Name,
domain.EnumsDescription(domain.ObjectTypeMap, l.To.Type), l.To.Name)
}
... ...
package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
"strings"
"time"
)
var (
ErrQuerySetNameExists = fmt.Errorf("已存在")
ErrQuerySetParentNotExists = fmt.Errorf("父级不存在")
ErrQuerySetInvalidType = fmt.Errorf("查询集合的类型有误")
)
type QuerySetService struct {
transactionContext *pgTransaction.TransactionContext
}
func NewQuerySetService(transactionContext *pgTransaction.TransactionContext) (*QuerySetService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &QuerySetService{
transactionContext: transactionContext,
}, nil
}
}
func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) error {
newQuerySet := &domain.QuerySet{
Type: qs.Type,
Flag: qs.Flag,
Name: qs.Name,
ParentId: qs.ParentId,
PinName: pin(qs.Name),
Status: domain.StatusOn,
QuerySetInfo: &domain.QuerySetInfo{},
QueryComponents: make([]*domain.QueryComponent, 0),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Context: ctx,
}
querySetRepository, err := repository.NewQuerySetRepository(ptr.transactionContext)
// check parent
options := map[string]interface{}{
"type": qs.Type,
"flag": qs.Flag,
"name": qs.Name,
}
if qs.ParentId > 0 {
parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": qs.ParentId})
if err != nil {
return ErrQuerySetParentNotExists
}
if parent.Type != qs.Type {
return ErrQuerySetInvalidType
}
options["parentId"] = qs.ParentId
}
// check duplicate name
if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == qs.Name {
return ErrQuerySetNameExists
}
// current sort
newQuerySet.Sort, err = dao.QuerySetCurrentSort(ptr.transactionContext, qs.Type, qs.ParentId)
if err != nil {
return err
}
if newQuerySet, err = querySetRepository.Save(newQuerySet); err != nil {
return err
}
// 日志
if err = FastLog(ptr.transactionContext, domain.QuerySetLog, newQuerySet.QuerySetId, &CreateQuerySetLog{
LogEntry: domain.NewLogEntry(newQuerySet.Name, qs.Type, domain.UnKnown, ctx),
Qs: newQuerySet,
}); err != nil {
return err
}
return nil
}
func (ptr *QuerySetService) Update(ctx *domain.Context, querySetId int, queryComponents []*domain.QueryComponent) error {
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
qs, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": querySetId})
if err != nil {
return err
}
// 调用底层的组装sql
// 生成Table
masterTable := queryComponents[0].MasterTable
table, err := ptr.CreateOrReFreshQuerySetTable(ctx, qs, masterTable, queryComponents)
if err != nil {
return err
}
// 生成日志
if err = ptr.UpdateQuerySetLog(ctx, qs, queryComponents); err != nil {
return err
}
// 保存
qs.Update(queryComponents, table.TableId)
_, err = querySetRepository.Save(qs)
if err != nil {
return err
}
return nil
}
func (ptr *QuerySetService) UpdateQuerySetLog(ctx *domain.Context, querySet *domain.QuerySet, queryComponents []*domain.QueryComponent) error {
return nil
}
func (ptr *QuerySetService) CreateOrReFreshQuerySetTable(ctx *domain.Context, querySet *domain.QuerySet, masterTable domain.QueryComponentTable, queryComponents []*domain.QueryComponent) (*domain.Table, error) {
var (
err error
foundMasterTable *domain.Table
)
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
foundMasterTable, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": masterTable.TableId})
if err != nil {
return nil, err
}
masterTable = domain.NewQueryComponentTable(foundMasterTable)
var table *domain.Table = NewTable(domain.TableType(querySet.Type), querySet.Name, masterTable.Fields, 0).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type))
if querySet.QuerySetInfo.BindTableId > 0 {
table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId})
if err != nil {
return nil, err
}
table.DataFields = masterTable.Fields
table.UpdatedAt = time.Now()
}
table.TableInfo.ApplyOnModule = domain.ModuleAll
table.TableInfo.DependencyTables = querySet.GetDependencyTables(queryComponents)
table, err = tableRepository.Save(table)
if err != nil {
return nil, err
}
return table, nil
}
func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name string) error {
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
qs, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": querySetId})
if err != nil {
return err
}
if qs.Name == name {
return nil
}
var oldName = qs.Name
// check duplicate name
if found, foundErr := querySetRepository.FindOne(map[string]interface{}{"context": ctx, "type": qs.Type, "parentId": qs.ParentId, "name": name}); foundErr == nil && found != nil {
return ErrQuerySetNameExists
}
qs.Name = name
_, err = querySetRepository.Save(qs)
if err != nil {
return err
}
// 日志
if err = FastLog(ptr.transactionContext, domain.QuerySetLog, qs.QuerySetId, &RenameQuerySetLog{
LogEntry: domain.NewLogEntry(qs.Name, qs.Type, domain.UnKnown, ctx),
NewName: name,
OldName: oldName,
}); err != nil {
return err
}
return nil
}
func (ptr *QuerySetService) ChangeStatus(ctx *domain.Context, querySetId int, status int) error {
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
qs, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": querySetId})
if err != nil {
return err
}
if qs.Status == status {
return nil
}
if qs.Type != domain.SchemaTable.ToString() {
return fmt.Errorf("方案才可以修改状态")
}
qs.Status = status
_, err = querySetRepository.Save(qs)
if err != nil {
return err
}
return nil
}
func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string, groupId int, name string) error {
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
qs, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": querySetId})
if err != nil {
return err
}
copy := copyQuerySet(qs, t, groupId, name)
copy.Sort, err = dao.QuerySetCurrentSort(ptr.transactionContext, copy.Type, copy.ParentId)
if err != nil {
return err
}
// check duplicate name
options := map[string]interface{}{
"type": t,
"flag": qs.Flag,
"name": name,
"parentId": groupId,
}
if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == name {
return ErrQuerySetNameExists
}
// TODO:create-table
if copy.QuerySetInfo.BindTableId != 0 {
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
table, err := tableRepository.FindOne(map[string]interface{}{"tableId": copy.QuerySetInfo.BindTableId})
if err != nil {
return err
}
NewTable(domain.TableType(t), name, table.DataFields, 0).WithContext(ctx)
}
_, err = querySetRepository.Save(copy)
if err != nil {
return err
}
return nil
}
func copyQuerySet(qs *domain.QuerySet, t string, groupId int, name string) *domain.QuerySet {
var res = &domain.QuerySet{
Type: t,
Flag: qs.Flag,
Name: name,
PinName: pin(name),
ParentId: groupId,
Status: qs.Status,
QuerySetInfo: qs.QuerySetInfo,
QueryComponents: qs.QueryComponents,
Sort: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Context: qs.Context,
}
return res
}
func (ptr *QuerySetService) Delete(ctx *domain.Context, querySetId int) error {
querySets, err := ptr.GetAllChild(ctx, querySetId, true, false)
if err != nil {
return err
}
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
for i := range querySets {
if _, err := querySetRepository.Remove(querySets[i]); err != nil {
return err
}
}
// 日志
if len(querySets) > 0 {
qs := querySets[0]
if err = FastLog(ptr.transactionContext, domain.QuerySetLog, querySetId, &DeleteQuerySetLog{
LogEntry: domain.NewLogEntry(qs.Name, qs.Type, domain.UnKnown, ctx),
DeleteList: querySets,
}); err != nil {
return err
}
}
return nil
}
func (ptr *QuerySetService) Move(ctx *domain.Context, querySetId int, parentId int, sort int) error {
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
qs, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": querySetId})
if err != nil {
return err
}
// check parent
options := map[string]interface{}{
"type": qs.Type,
"flag": qs.Flag,
"name": qs.Name,
"parentId": parentId,
}
if parentId > 0 && qs.ParentId != parentId {
parent, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": parentId})
if err != nil {
return ErrQuerySetParentNotExists
}
if parent.Type != qs.Type {
return ErrQuerySetInvalidType
}
// check duplicate name
if found, foundErr := querySetRepository.FindOne(options); foundErr == nil && found != nil && found.Name == qs.Name {
return ErrQuerySetNameExists
}
}
querySets, err := ptr.GetAllChild(ctx, parentId, false, true)
if err != nil {
return err
}
newSortSet := make([]*domain.QuerySet, 0)
for i := 0; i < len(querySets); i++ {
if querySets[i].QuerySetId == qs.QuerySetId {
continue
}
newSortSet = append(newSortSet, querySets[i])
}
// 移动分组
qs.Sort = sort
qs.ParentId = parentId
newSortSet = insertQuerySetsByIndex(newSortSet, qs, sort)
for i := 0; i < len(newSortSet); i++ {
currentSort := i + 1
if newSortSet[i].Sort == currentSort && newSortSet[i].QuerySetId != querySetId {
continue
}
newSortSet[i].Sort = currentSort
if _, err := querySetRepository.Save(newSortSet[i]); err != nil {
return err
}
}
return nil
}
func insertQuerySetsByIndex(list []*domain.QuerySet, item *domain.QuerySet, index int) []*domain.QuerySet {
if len(list) == 0 {
return []*domain.QuerySet{item}
}
if len(list) < index {
return append(list, item)
}
var res = make([]*domain.QuerySet, 0)
for i := range list {
if i+1 == index {
res = append(res, item)
}
res = append(res, list[i])
}
return res
}
func (ptr *QuerySetService) DependencyGraph(ctx *domain.Context, querySetId int) (interface{}, error) {
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
_, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableTypes": []string{domain.SchemaTable.ToString(), domain.SubProcessTable.ToString()}})
dependencies := make([]dependency, 0)
if err != nil {
return dependencies, err
}
if len(tables) == 0 {
return dependencies, nil
}
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
querySet, err := querySetRepository.FindOne(map[string]interface{}{"context": ctx, "querySetId": querySetId})
if err != nil {
return dependencies, err
}
if querySet.QuerySetInfo.BindTableId == 0 {
return dependencies, nil
}
dependencies = makeDependencyGraph(querySet.QuerySetInfo.BindTableId, tables)
return dependencies, nil
}
func makeDependencyGraph(bindTableId int, tables []*domain.Table) []dependency {
dependencies := make([]dependency, 0)
tableMap := make(map[int]*domain.Table)
graph := make(map[int][]int, 0)
for i := range tables {
tableMap[tables[i].TableId] = tables[i]
graph[tables[i].TableId] = tables[i].TableInfo.DependencyTables
}
// parent depend
dependTables := []int{bindTableId}
foundDependency := make(map[string]bool, 0)
for {
if len(dependTables) == 0 {
break
}
parent := dependTables[0]
parentTable, ok := tableMap[parent]
if !ok {
continue
}
for _, dependChildId := range parentTable.TableInfo.DependencyTables {
dependChild, ok := tableMap[dependChildId]
if !ok {
continue
}
depend := NewDependency(parentTable.TableId, dependChild)
if _, ok := foundDependency[depend.String()]; !ok {
dependencies = append(dependencies, depend)
}
}
dependTables = dependTables[1:]
}
// dependToChild
return dependencies
}
func dependParents(tables []*domain.Table, tableMap map[int]*domain.Table, bindTableId int) []int {
foundDependTable := make(map[int]bool)
traceStack := []int{bindTableId}
res := []int{bindTableId}
for {
if len(traceStack) == 0 {
break
}
last := traceStack[0]
traceStack = traceStack[1:]
table := tableMap[last]
if table == nil {
continue
}
// for
if _, ok := foundDependTable[last]; !ok {
foundDependTable[last] = true
}
}
return res
}
func NewDependency(parentId int, child *domain.Table) dependency {
return dependency{
Id: parentId,
}
}
type dependency struct {
// 标识
Id int `json:"id"`
// 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表
Type string `json:"type"`
// 名称
Name string `json:"name"`
// 依赖的表
DependChildId int `json:"dependChildId"`
}
func (d dependency) String() string {
return fmt.Sprintf("%d-%d", d.Id, d.DependChildId)
}
func (ptr *QuerySetService) GetAllChild(ctx *domain.Context, querySetId int, includeSelf bool, onlyNextLevel bool) ([]*domain.QuerySet, error) {
var result = make([]*domain.QuerySet, 0)
var m = make(map[int]*domain.QuerySet)
var parentIds = []int{querySetId}
querySetRepository, _ := repository.NewQuerySetRepository(ptr.transactionContext)
if includeSelf {
self, err := querySetRepository.FindOne(map[string]interface{}{"querySetId": querySetId})
if err != nil {
return nil, err
}
m[self.QuerySetId] = self
result = append(result, self)
}
for {
if len(parentIds) == 0 {
break
}
_, querySet, err := querySetRepository.Find(map[string]interface{}{"inParentIds": parentIds})
if err != nil {
return nil, err
}
parentIds = make([]int, 0)
for _, item := range querySet {
item := item
if _, ok := m[item.QuerySetId]; ok {
continue
}
m[item.QuerySetId] = item
result = append(result, item)
parentIds = append(parentIds, item.QuerySetId)
}
if onlyNextLevel {
break
}
}
return result, nil
}
... ...
... ... @@ -35,6 +35,7 @@ func Init() {
(*models.Table)(nil),
(*models.Log)(nil),
(*models.MappingRule)(nil),
(*models.QuerySet)(nil),
} {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
Temp: false,
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"time"
)
type QuerySet struct {
tableName string `comment:"查询集合" pg:"metadata.query_sets"`
// 查询集合ID
QuerySetId int `comment:"查询集合ID" pg:"pk:query_set_id"`
// Schema:方案 SubProcess:子过程
Type string `comment:"Schema:方案 SubProcess:子过程"`
// 标识 分组:group 子过程/方案:query-set
Flag string `comment:"标识 1:主表字段 2:手动添加"`
// 名称
Name string `comment:"名称"`
// 拼音(排序使用)
PinName string `comment:"拼音(排序使用)"`
// 父级ID
ParentId int `comment:"父级ID"`
// 状态 1:启用 2:关闭 (子过程默认启用)
Status int `comment:"状态 1:启用 2:关闭 (子过程默认启用)"`
// 查询集合信息
QuerySetInfo *domain.QuerySetInfo `comment:"查询集合信息"`
// 查询组件
QueryComponents []*domain.QueryComponent `comment:"查询组件"`
// 排序
Sort int `comment:"排序"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"`
// 扩展
Context *domain.Context `comment:"扩展"`
}
... ...
... ... @@ -36,5 +36,7 @@ type Table struct {
// 行数
RowCount int `comment:"行数"`
// 扩展
Context *domain.Context `json:"context"`
Context *domain.Context `comment:"扩展"`
// 表信息
TableInfo *domain.TableInfo `comment:"表信息"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
)
func TransformToQuerySetDomainModelFromPgModels(querySetModel *models.QuerySet) (*domain.QuerySet, error) {
return &domain.QuerySet{
QuerySetId: querySetModel.QuerySetId,
Type: querySetModel.Type,
Flag: querySetModel.Flag,
Name: querySetModel.Name,
PinName: querySetModel.PinName,
ParentId: querySetModel.ParentId,
Status: querySetModel.Status,
QuerySetInfo: querySetModel.QuerySetInfo,
QueryComponents: querySetModel.QueryComponents,
Sort: querySetModel.Sort,
CreatedAt: querySetModel.CreatedAt,
UpdatedAt: querySetModel.UpdatedAt,
DeletedAt: querySetModel.DeletedAt,
Context: querySetModel.Context,
}, nil
}
... ...
... ... @@ -26,5 +26,6 @@ func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain.
Version: tableModel.Version,
RowCount: tableModel.RowCount,
Context: tableModel.Context,
TableInfo: tableModel.TableInfo,
}, nil
}
... ...
package repository
import (
"errors"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform"
)
type QuerySetRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *QuerySetRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *QuerySetRepository) Save(querySet *domain.QuerySet) (*domain.QuerySet, error) {
sqlBuildFields := []string{
"query_set_id",
"type",
"flag",
"name",
"pin_name",
"parent_id",
"status",
"query_set_info",
"query_components",
"sort",
"created_at",
"updated_at",
"context",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "query_set_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "query_set_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "query_set_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if querySet.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(
&querySet.QuerySetId,
&querySet.Type,
&querySet.Flag,
&querySet.Name,
&querySet.PinName,
&querySet.ParentId,
&querySet.Status,
&querySet.QuerySetInfo,
&querySet.QueryComponents,
&querySet.Sort,
&querySet.CreatedAt,
&querySet.UpdatedAt,
&querySet.Context,
),
fmt.Sprintf("INSERT INTO metadata.query_sets (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
querySet.Type,
querySet.Flag,
querySet.Name,
querySet.PinName,
querySet.ParentId,
querySet.Status,
querySet.QuerySetInfo,
querySet.QueryComponents,
querySet.Sort,
querySet.CreatedAt,
querySet.UpdatedAt,
querySet.Context,
); err != nil {
return querySet, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&querySet.QuerySetId,
&querySet.Type,
&querySet.Flag,
&querySet.Name,
&querySet.PinName,
&querySet.ParentId,
&querySet.Status,
&querySet.QuerySetInfo,
&querySet.QueryComponents,
&querySet.Sort,
&querySet.CreatedAt,
&querySet.UpdatedAt,
&querySet.Context,
),
fmt.Sprintf("UPDATE metadata.query_sets SET %s WHERE query_set_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
querySet.Type,
querySet.Flag,
querySet.Name,
querySet.PinName,
querySet.ParentId,
querySet.Status,
querySet.QuerySetInfo,
querySet.QueryComponents,
querySet.Sort,
querySet.CreatedAt,
querySet.UpdatedAt,
querySet.Context,
querySet.Identify(),
); err != nil {
return querySet, err
}
}
return querySet, nil
}
func (repository *QuerySetRepository) Remove(querySet *domain.QuerySet) (*domain.QuerySet, error) {
tx := repository.transactionContext.PgTx
querySetModel := new(models.QuerySet)
querySetModel.QuerySetId = querySet.Identify().(int)
if _, err := tx.Model(querySetModel).WherePK().Delete(); err != nil {
return querySet, err
}
return querySet, nil
}
func (repository *QuerySetRepository) FindOne(queryOptions map[string]interface{}) (*domain.QuerySet, error) {
tx := repository.transactionContext.PgTx
querySetModel := new(models.QuerySet)
query := sqlbuilder.BuildQuery(tx.Model(querySetModel), queryOptions)
WhereContext(query, queryOptions)
query.SetWhereByQueryOption("query_set_id = ?", "querySetId")
query.SetWhereByQueryOption("type = ?", "type")
query.SetWhereByQueryOption("flag = ?", "flag")
query.SetWhereByQueryOption("parent_id = ?", "parentId")
query.SetWhereByQueryOption("name = ?", "name")
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if querySetModel.QuerySetId == 0 {
return nil, nil
} else {
return transform.TransformToQuerySetDomainModelFromPgModels(querySetModel)
}
}
func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.QuerySet, error) {
tx := repository.transactionContext.PgTx
var querySetModels []*models.QuerySet
querySets := make([]*domain.QuerySet, 0)
query := sqlbuilder.BuildQuery(tx.Model(&querySetModels), queryOptions)
WhereContext(query, queryOptions)
query.SetWhereByQueryOption("type = ?", "type")
query.SetWhereByQueryOption("flag = ?", "flag")
query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName")
if v, ok := queryOptions["inParentIds"]; ok && len(v.([]int)) > 0 {
query.Where("parent_id in (?)", pg.In(v))
}
if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("pin_name", v.(string))
} else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("created_at", v.(string))
} else {
query.SetOrderDirect("parent_id", "ASC")
query.SetOrderDirect("sort", "ASC")
}
if count, err := query.SelectAndCount(); err != nil {
return 0, querySets, err
} else {
for _, querySetModel := range querySetModels {
if querySet, err := transform.TransformToQuerySetDomainModelFromPgModels(querySetModel); err != nil {
return 0, querySets, err
} else {
querySets = append(querySets, querySet)
}
}
return int64(count), querySets, nil
}
}
func NewQuerySetRepository(transactionContext *pgTransaction.TransactionContext) (*QuerySetRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &QuerySetRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -32,6 +32,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
"version",
"row_count",
"context",
"table_info",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at"))
... ... @@ -57,6 +58,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
&table.Version,
&table.RowCount,
&table.Context,
&table.TableInfo,
),
fmt.Sprintf("INSERT INTO metadata.tables (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
table.TableType,
... ... @@ -72,6 +74,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
table.Version,
table.RowCount,
table.Context,
table.TableInfo,
); err != nil {
return table, err
}
... ... @@ -95,6 +98,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
&table.Version,
&table.RowCount,
&table.Context,
&table.TableInfo,
),
fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? and version=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
table.TableType,
... ... @@ -110,6 +114,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
table.Version,
table.RowCount,
table.Context,
table.TableInfo,
table.Identify(),
oldVersion,
); err != nil {
... ... @@ -164,6 +169,9 @@ func (repository *TableRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["tableTypes"]; ok && len(v.([]string)) > 0 {
query.Where(`table_type in (?)`, pg.In(v.([]string)))
}
if v, ok := queryOptions["module"]; ok && v.(int) > 0 {
query.Where(`(cast(table_info->>'module' as integer) & ?) >0`, v)
}
//query.SetOffsetAndLimit(20)
query.SetOrderDirect("table_id", "DESC")
... ...
... ... @@ -87,18 +87,19 @@ func (o *QueryOptions) SetDefaultOrder() *QueryOptions {
type Condition struct {
domain.Condition
Distinct bool
DisableFormat bool
}
func (c Condition) SetWhere(q *gorm.DB) {
func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) {
if len(c.Like) > 0 {
q.Where(fmt.Sprintf("%v like '%%%v%%'", FormatIfNull(c.Field), c.Like))
q.Where(fmt.Sprintf("%v like '%%%v%%'", c.FormatIfNull(params, c.Field), c.Like))
}
if len(c.In) > 0 {
q.Where(fmt.Sprintf("%v in %v", FormatIfNull(c.Field), c.InArgs(c.In)))
q.Where(fmt.Sprintf("%v in %v", c.FormatIfNull(params, c.Field), c.InArgs(c.In)))
}
if len(c.Ex) > 0 {
in := c.InArgs(c.Ex)
q.Where(fmt.Sprintf("%v not in %v", FormatIfNull(c.Field), in))
q.Where(fmt.Sprintf("%v not in %v", c.FormatIfNull(params, c.Field), in))
}
if len(c.Range) > 0 {
for _, item := range c.Range {
... ... @@ -115,7 +116,7 @@ func (c Condition) SetWhere(q *gorm.DB) {
continue
}
q.Where(fmt.Sprintf("%s %s %s",
FormatIfNull(c.Field),
c.FormatIfNull(params, c.Field),
opVal,
c.formatByOp(item.Op, val),
))
... ... @@ -129,7 +130,10 @@ func (c Condition) SetWhere(q *gorm.DB) {
}
}
func FormatIfNull(f *domain.Field) string {
func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string {
if params.Table != nil && params.Table.TableType == domain.ObjectDBTable {
return f.SQLName
}
if domain.SQLType(f.SQLType).IsString() {
return fmt.Sprintf("ifnull(%s,'')", f.SQLName)
}
... ... @@ -254,7 +258,7 @@ func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) {
if w.Field.Flag == domain.ManualField {
continue
}
w.SetWhere(query)
w.SetWhere(params, query)
}
}
}
... ...
... ... @@ -80,6 +80,17 @@ func (controller *LogController) TableOperateLog() {
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *LogController) QuerySetLog() {
logService := service.NewLogService(nil)
cmd := &command.SearchLogCommand{}
controller.Unmarshal(cmd)
cmd.LogType = domain.QuerySetLog.ToString()
cmd.SortByLogId = "DESC"
cmd.Context = ParseContext(controller.BaseController)
total, data, err := logService.SearchLog(cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *LogController) VerifiedStepLog() {
logService := service.NewLogService(nil)
cmd := &command.SearchLogCommand{}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/command"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/query"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/service"
)
type QuerySetController struct {
beego.BaseController
}
func (controller *QuerySetController) CreateQuerySet() {
querySetService := service.NewQuerySetService(nil)
createQuerySetCommand := &command.CreateQuerySetCommand{}
Must(controller.Unmarshal(createQuerySetCommand))
data, err := querySetService.CreateQuerySet(ParseContext(controller.BaseController), createQuerySetCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) UpdateQuerySet() {
querySetService := service.NewQuerySetService(nil)
updateQuerySetCommand := &command.UpdateQuerySetCommand{}
controller.Unmarshal(updateQuerySetCommand)
Id, _ := controller.GetInt(":querySetId")
updateQuerySetCommand.QuerySetId = Id
data, err := querySetService.UpdateQuerySet(ParseContext(controller.BaseController), updateQuerySetCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) GetQuerySet() {
querySetService := service.NewQuerySetService(nil)
getQuerySetQuery := &query.GetQuerySetQuery{}
Id, _ := controller.GetInt(":querySetId")
getQuerySetQuery.QuerySetId = Id
data, err := querySetService.GetQuerySet(ParseContext(controller.BaseController), getQuerySetQuery)
controller.Response(data, err)
}
func (controller *QuerySetController) RemoveQuerySet() {
querySetService := service.NewQuerySetService(nil)
removeQuerySetCommand := &command.RemoveQuerySetCommand{}
controller.Unmarshal(removeQuerySetCommand)
Id, _ := controller.GetInt(":querySetId")
removeQuerySetCommand.QuerySetId = Id
data, err := querySetService.RemoveQuerySet(ParseContext(controller.BaseController), removeQuerySetCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) ListQuerySet() {
querySetService := service.NewQuerySetService(nil)
listQuerySetQuery := &query.ListQuerySetQuery{}
offset, _ := controller.GetInt("offset")
listQuerySetQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listQuerySetQuery.Limit = limit
data, err := querySetService.ListQuerySet(ParseContext(controller.BaseController), listQuerySetQuery)
controller.Response(data, err)
}
func (controller *QuerySetController) ChangeStatus() {
querySetService := service.NewQuerySetService(nil)
changeStatusCommand := &command.ChangeStatusCommand{}
Must(controller.Unmarshal(changeStatusCommand))
data, err := querySetService.ChangeStatus(ParseContext(controller.BaseController), changeStatusCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) Copy() {
querySetService := service.NewQuerySetService(nil)
copyCommand := &command.CopyCommand{}
Must(controller.Unmarshal(copyCommand))
data, err := querySetService.Copy(ParseContext(controller.BaseController), copyCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) DependencyGraph() {
querySetService := service.NewQuerySetService(nil)
dependencyGraphQuery := &query.DependencyGraphQuery{}
Must(controller.Unmarshal(dependencyGraphQuery))
data, err := querySetService.DependencyGraph(ParseContext(controller.BaseController), dependencyGraphQuery)
controller.Response(data, err)
}
func (controller *QuerySetController) Move() {
querySetService := service.NewQuerySetService(nil)
moveCommand := &command.MoveCommand{}
Must(controller.Unmarshal(moveCommand))
data, err := querySetService.Move(ParseContext(controller.BaseController), moveCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) Rename() {
querySetService := service.NewQuerySetService(nil)
renameCommand := &command.RenameCommand{}
Must(controller.Unmarshal(renameCommand))
data, err := querySetService.Rename(ParseContext(controller.BaseController), renameCommand)
controller.Response(data, err)
}
func (controller *QuerySetController) SearchQuerySet() {
querySetService := service.NewQuerySetService(nil)
searchQuerySetQuery := &query.SearchQuerySetQuery{}
Must(controller.Unmarshal(searchQuerySetQuery))
data, err := querySetService.SearchQuerySet(ParseContext(controller.BaseController), searchQuerySetQuery)
controller.Response(data, err)
}
... ...
... ... @@ -135,6 +135,20 @@ func (controller *TableController) SearchSubTableList() {
controller.Response(data, err)
}
func (controller *TableController) SearchQuerySetTables() {
tableService := service.NewTableService(nil)
cmd := &query.SearchTableQuery{}
Must(controller.Unmarshal(cmd))
if len(cmd.TableTypes) == 0 {
cmd.TableTypes = []string{domain.MainTable.ToString(), domain.SideTable.ToString(), domain.SubTable.ToString(), domain.SubProcessTable.ToString()}
}
cmd.Module = domain.ModuleQuerySetCenter | domain.ModuleCalculateCenter
cmd.ReturnDetailStructInfo = true
cmd.Context = ParseContext(controller.BaseController)
data, err := tableService.Search(cmd)
controller.Response(data, err)
}
func (controller *TableController) UpdateTableStruct() {
tableService := service.NewTableService(nil)
cmd := &command.UpdateTableStructCommand{}
... ... @@ -153,6 +167,22 @@ func (controller *TableController) AddTableStruct() {
controller.Response(data, err)
}
func (controller *TableController) ApplyOn() {
tableService := service.NewTableService(nil)
cmd := &command.ApplyOnCommand{}
Must(controller.Unmarshal(cmd))
data, err := tableService.ApplyOn(ParseContext(controller.BaseController), cmd)
controller.Response(data, err)
}
func (controller *TableController) ValidExprSql() {
tableService := service.NewTableService(nil)
cmd := &command.ValidExprSqlCommand{}
Must(controller.Unmarshal(cmd))
data, err := tableService.ValidExprSql(ParseContext(controller.BaseController), cmd)
controller.Response(data, err)
}
func (controller *TableController) ExportDataTable() {
tableService := service.NewTableService(nil)
cmd := &command.TablePreviewCommand{}
... ...
... ... @@ -14,4 +14,5 @@ func init() {
web.Router("/data/logs/search", &controllers.LogController{}, "Post:SearchLog")
web.Router("/data/logs/table-operate-Log", &controllers.LogController{}, "Post:TableOperateLog")
web.Router("/data/logs/verified-step-Log", &controllers.LogController{}, "Post:VerifiedStepLog")
web.Router("/data/logs/query-set-log", &controllers.LogController{}, "Post:QuerySetLog")
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers"
)
func init() {
web.Router("/data/query-sets/", &controllers.QuerySetController{}, "Post:CreateQuerySet")
web.Router("/data/query-sets/:querySetId", &controllers.QuerySetController{}, "Put:UpdateQuerySet")
web.Router("/data/query-sets/:querySetId", &controllers.QuerySetController{}, "Get:GetQuerySet")
web.Router("/data/query-sets/:querySetId", &controllers.QuerySetController{}, "Delete:RemoveQuerySet")
web.Router("/data/query-sets/", &controllers.QuerySetController{}, "Get:ListQuerySet")
web.Router("/data/query-sets/change-status", &controllers.QuerySetController{}, "Post:ChangeStatus")
web.Router("/data/query-sets/copy", &controllers.QuerySetController{}, "Post:Copy")
web.Router("/data/query-sets/dependency-graph", &controllers.QuerySetController{}, "Post:DependencyGraph")
web.Router("/data/query-sets/move", &controllers.QuerySetController{}, "Post:Move")
web.Router("/data/query-sets/rename", &controllers.QuerySetController{}, "Post:Rename")
web.Router("/data/query-sets/search", &controllers.QuerySetController{}, "Post:SearchQuerySet")
}
... ...
... ... @@ -14,8 +14,11 @@ func init() {
web.Router("/data/tables/", &controllers.TableController{}, "Get:ListTable")
web.Router("/data/tables/search", &controllers.TableController{}, "Post:Search")
web.Router("/data/tables/relation-graph", &controllers.TableController{}, "Post:RelationGraph")
web.Router("/data/tables/apply-on", &controllers.TableController{}, "Post:ApplyOn")
web.Router("/data/tables/valid-expr-sql", &controllers.TableController{}, "Post:ValidExprSql")
web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList")
web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList")
web.Router("/data/tables/search-query-set-tables", &controllers.TableController{}, "Post:SearchQuerySetTables")
//web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable")
//web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable")
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("修改状态", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("修改状态", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"querySetId": "int",
"status": "int",
}
httpExpect.POST("/query-sets/change-status").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("移动", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("移动", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"flag": "int",
"parentId": "int64",
"name": "string",
"querySetId": "int",
}
httpExpect.POST("/query-sets/copy").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("创建查询集合服务", func() {
Describe("提交数据创建查询集合服务", func() {
Context("提交正确的新查询集合数据", func() {
It("返回查询集合数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"type": "string",
"flag": "int",
"name": "string",
"parentId": "int64",
}
httpExpect.POST("/query-sets/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("querySetId").ValueNotEqual("querySetId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("依赖关系图", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("依赖关系图", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"querySetId": "int",
}
httpExpect.POST("/query-sets/dependency-ggraph").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("返回查询集合服务", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据querySetId参数返回查询集合", func() {
Context("传入有效的querySetId", func() {
It("返回查询集合数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/query-sets/{Id}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("返回查询集合服务列表", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回查询集合列表", func() {
Context("传入有效的参数", func() {
It("返回查询集合数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/query-sets/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("querySets").Value("querySets").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("移动", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("移动", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"querySetId": "int",
"parentId": "int64",
}
httpExpect.POST("/query-sets/move").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application"
_ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego"
)
func TestQuerySet(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port QuerySet Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("移除查询集合服务", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除查询集合服务", func() {
Context("传入有效的querySetId", func() {
It("返回被移除查询集合的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/query-sets/{Id}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("重命名", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("重命名", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"querySetId": "int",
"name": "string",
}
httpExpect.POST("/query-sets/rename").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("返回查询集合服务列表", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("返回查询集合服务列表", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"offset": "int",
"limit": "int",
}
httpExpect.POST("/query-sets/search").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package query_set
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
)
var _ = Describe("更新查询集合服务", func() {
var querySetId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&querySetId),
"INSERT INTO query_sets (query_set_id, type, flag, name, pin_name, parent_id, status, query_set_info, query_components, sort, created_at, updated_at, deleted_at, context) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING query_set_id",
"testQuerySetId", "testType", "testFlag", "testName", "testPinName", "testParentId", "testStatus", "testQuerySetInfo", "testQueryComponents", "testSort", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testContext")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新查询集合服务", func() {
Context("提交正确的查询集合数据", func() {
It("返回更新后的查询集合数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"querySetId": "int",
}
httpExpect.PUT("/query-sets/{Id}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("querySetId").ValueEqual("querySetId", querySetId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM query_sets WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...