作者 yangfu

feat: P1 case query set cascade update

1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "errors"
  5 + "fmt"
4 "github.com/linmadan/egglib-go/core/application" 6 "github.com/linmadan/egglib-go/core/application"
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/event/command" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/event/command"
@@ -10,6 +12,7 @@ import ( @@ -10,6 +12,7 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache" 13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache"
12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" 14 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
  15 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
13 ) 16 )
14 17
15 type TableEventService struct { 18 type TableEventService struct {
@@ -68,6 +71,62 @@ func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *co @@ -68,6 +71,62 @@ func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *co
68 return nil, nil 71 return nil, nil
69 } 72 }
70 73
  74 +func (tableEventService *TableEventService) HandlerTableAffectedMarkToConflictStatus(ctx *domain.Context, cmd *command.TableEventCommand) (interface{}, error) {
  75 + transactionContext, err := factory.CreateTransactionContext(nil)
  76 + if err != nil {
  77 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  78 + }
  79 + if err := transactionContext.StartTransaction(); err != nil {
  80 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  81 + }
  82 + defer func() {
  83 + transactionContext.RollbackTransaction()
  84 + }()
  85 +
  86 + data := cmd.EventTable
  87 + tableId := 0
  88 + switch data.Type {
  89 + case domain.TableDataEditEvent:
  90 + tableId = data.Table.TableId
  91 + case domain.QuerySetUpdateEvent, domain.QuerySetUpdateRenameEvent:
  92 + tableId = data.QuerySet.QuerySetInfo.BindTableId
  93 + default:
  94 + return nil, err
  95 + }
  96 + if tableId == 0 {
  97 + return nil, nil
  98 + }
  99 + // tableId 相关联的
  100 + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0)
  101 +
  102 + _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "dependencyTable": tableId, "tableTypesNotIn": []string{domain.TemporaryTable.ToString()}})
  103 + if errors.Is(err, domain.ErrorNotFound) {
  104 + return nil, nil
  105 + }
  106 + tableIds := make([]int, 0)
  107 + for _, table := range tables {
  108 + tableIds = append(tableIds, table.TableId)
  109 + }
  110 + if len(tableIds) == 0 {
  111 + return nil, nil
  112 + }
  113 + querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
  114 + _, querySets, _ := querySetRepository.Find(map[string]interface{}{"context": ctx, "bindTableIds": tableIds})
  115 + for _, querySet := range querySets {
  116 + log.Logger.Debug(fmt.Sprintf("【集合状态更新】 id:%v name:%v ReadyStatus:1", querySet.QuerySetId, querySet.Name))
  117 + querySet.QuerySetInfo.WithConflictStatus()
  118 + _, err = querySetRepository.Save(querySet)
  119 + if err != nil {
  120 + return nil, err
  121 + }
  122 + }
  123 +
  124 + if err := transactionContext.CommitTransaction(); err != nil {
  125 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  126 + }
  127 + return nil, nil
  128 +}
  129 +
71 func NewTableEventService(options map[string]interface{}) *TableEventService { 130 func NewTableEventService(options map[string]interface{}) *TableEventService {
72 svr := &TableEventService{} 131 svr := &TableEventService{}
73 return svr 132 return svr
@@ -12,6 +12,18 @@ func FastError(err error) error { @@ -12,6 +12,18 @@ func FastError(err error) error {
12 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 12 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
13 } 13 }
14 14
  15 +func FastErrorResponse(err error, args ...interface{}) interface{} {
  16 + var response = make(map[string]interface{})
  17 + response["internalErr"] = err.Error()
  18 + for i := 0; i < len(args); i += 2 {
  19 + if i+1 >= len(args) {
  20 + break
  21 + }
  22 + response[args[i].(string)] = args[i+1]
  23 + }
  24 + return response
  25 +}
  26 +
15 func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) { 27 func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) {
16 var err error 28 var err error
17 // 待优化分批下载,压缩 29 // 待优化分批下载,压缩
@@ -109,12 +109,13 @@ func (fileService *FileService) GetFile(ctx *domain.Context, getFileQuery *query @@ -109,12 +109,13 @@ func (fileService *FileService) GetFile(ctx *domain.Context, getFileQuery *query
109 options["fileId"] = getFileQuery.FileId 109 options["fileId"] = getFileQuery.FileId
110 } 110 }
111 if len(getFileQuery.FileName) > 0 { 111 if len(getFileQuery.FileName) > 0 {
112 - options["fileName"] = getFileQuery.FileName 112 + options["fileName"] = domain.FileName(getFileQuery.FileName)
113 } 113 }
114 if len(getFileQuery.FileType) > 0 { 114 if len(getFileQuery.FileType) > 0 {
115 options["fileType"] = getFileQuery.FileType 115 options["fileType"] = getFileQuery.FileType
116 } 116 }
117 - if len(options) == 0 { 117 + // 未传递参数
  118 + if len(options) == 1 {
118 return response, nil 119 return response, nil
119 } 120 }
120 file, _ := fileRepository.FindOne(options) 121 file, _ := fileRepository.FindOne(options)
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RefreshQuerySetCommand struct {
  12 + // 查询集合ID
  13 + QuerySetId int `cname:"查询集合ID" json:"querySetId" valid:"Required"`
  14 +}
  15 +
  16 +func (updateQuerySetCommand *RefreshQuerySetCommand) Valid(validation *validation.Validation) {
  17 + //validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (updateQuerySetCommand *RefreshQuerySetCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(updateQuerySetCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(updateQuerySetCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
@@ -15,6 +15,8 @@ type QuerySetDetailDto struct { @@ -15,6 +15,8 @@ type QuerySetDetailDto struct {
15 QueryComponents []*domain.QueryComponent `json:"queryComponents"` 15 QueryComponents []*domain.QueryComponent `json:"queryComponents"`
16 // 查询集绑定的表 16 // 查询集绑定的表
17 TableId int `json:"tableId"` 17 TableId int `json:"tableId"`
  18 + // 在冲突状态 true:冲突异常 false:正常
  19 + InConflict bool `json:"inConflict"`
18 } 20 }
19 21
20 func (d *QuerySetDetailDto) Load(m *domain.QuerySet, mapTables map[int]*domain.Table) *QuerySetDetailDto { 22 func (d *QuerySetDetailDto) Load(m *domain.QuerySet, mapTables map[int]*domain.Table) *QuerySetDetailDto {
@@ -26,15 +28,31 @@ func (d *QuerySetDetailDto) Load(m *domain.QuerySet, mapTables map[int]*domain.T @@ -26,15 +28,31 @@ func (d *QuerySetDetailDto) Load(m *domain.QuerySet, mapTables map[int]*domain.T
26 if m.QuerySetInfo != nil { 28 if m.QuerySetInfo != nil {
27 d.TableId = m.QuerySetInfo.BindTableId 29 d.TableId = m.QuerySetInfo.BindTableId
28 } 30 }
  31 + hasUpdateTable := false
29 for i, q := range d.QueryComponents { 32 for i, q := range d.QueryComponents {
30 if q.MasterTable != nil && q.MasterTable.TableId != 0 { 33 if q.MasterTable != nil && q.MasterTable.TableId != 0 {
31 if t, ok := mapTables[q.MasterTable.TableId]; ok { 34 if t, ok := mapTables[q.MasterTable.TableId]; ok {
32 d.QueryComponents[i].MasterTable = domain.NewQueryComponentTable(t) 35 d.QueryComponents[i].MasterTable = domain.NewQueryComponentTable(t)
  36 + d.QueryComponents[i].UpdateTables(t)
  37 + hasUpdateTable = true
33 } 38 }
34 } 39 }
35 if d.QueryComponents[i].Aggregation != nil { 40 if d.QueryComponents[i].Aggregation != nil {
36 d.QueryComponents[i].Aggregation.Aggregation.AllFields = d.QueryComponents[i].Aggregation.AggregationFields() 41 d.QueryComponents[i].Aggregation.Aggregation.AllFields = d.QueryComponents[i].Aggregation.AggregationFields()
37 } 42 }
  43 + if !hasUpdateTable && len(mapTables) == 1 {
  44 + for _, t := range mapTables {
  45 + d.QueryComponents[i].UpdateTables(t)
  46 + hasUpdateTable = true
  47 + break
  48 + }
  49 + }
  50 + }
  51 + d.InConflict = false
  52 + if m.QuerySetInfo != nil {
  53 + if m.QuerySetInfo.ReadyStatus == 1 {
  54 + d.InConflict = true
  55 + }
38 } 56 }
39 return d 57 return d
40 } 58 }
@@ -21,6 +21,8 @@ type QuerySetDto struct { @@ -21,6 +21,8 @@ type QuerySetDto struct {
21 Time string `json:"time"` 21 Time string `json:"time"`
22 // 绑定的表ID 22 // 绑定的表ID
23 BindTableId int `json:"tableId"` 23 BindTableId int `json:"tableId"`
  24 + // 在冲突状态 true:冲突异常 false:正常
  25 + InConflict bool `json:"inConflict"`
24 } 26 }
25 27
26 func (d *QuerySetDto) Load(m *domain.QuerySet) *QuerySetDto { 28 func (d *QuerySetDto) Load(m *domain.QuerySet) *QuerySetDto {
@@ -33,6 +35,7 @@ func (d *QuerySetDto) Load(m *domain.QuerySet) *QuerySetDto { @@ -33,6 +35,7 @@ func (d *QuerySetDto) Load(m *domain.QuerySet) *QuerySetDto {
33 d.Sort = m.Sort 35 d.Sort = m.Sort
34 d.Time = m.CreatedAt.Local().Format("2006-01-02 15:04:05") 36 d.Time = m.CreatedAt.Local().Format("2006-01-02 15:04:05")
35 d.BindTableId = m.QuerySetInfo.BindTableId 37 d.BindTableId = m.QuerySetInfo.BindTableId
  38 + d.InConflict = m.QuerySetInfo.ReadyStatus == 1
36 return d 39 return d
37 } 40 }
38 41
@@ -396,6 +396,36 @@ func (querySetService *QuerySetService) UpdateQuerySet(ctx *domain.Context, upda @@ -396,6 +396,36 @@ func (querySetService *QuerySetService) UpdateQuerySet(ctx *domain.Context, upda
396 return struct{}{}, nil 396 return struct{}{}, nil
397 } 397 }
398 398
  399 +// 更新查询集合服务
  400 +func (querySetService *QuerySetService) RefreshQuerySet(ctx *domain.Context, updateQuerySetCommand *command.RefreshQuerySetCommand) (interface{}, error) {
  401 + if err := updateQuerySetCommand.ValidateCommand(); err != nil {
  402 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  403 + }
  404 + transactionContext, err := factory.CreateTransactionContext(nil)
  405 + if err != nil {
  406 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  407 + }
  408 + if err := transactionContext.StartTransaction(); err != nil {
  409 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  410 + }
  411 + defer func() {
  412 + transactionContext.RollbackTransaction()
  413 + }()
  414 + svr, _ := factory.FastQuerySetServices(transactionContext)
  415 + _, querySet, err := factory.FastPgQuerySet(transactionContext, updateQuerySetCommand.QuerySetId)
  416 + if err != nil {
  417 + return nil, factory.FastError(err)
  418 + }
  419 + if err := svr.Update(ctx, updateQuerySetCommand.QuerySetId, querySet.QueryComponents); err != nil {
  420 + return factory.FastErrorResponse(err, "title", fmt.Sprintf("%v:%v", domain.EnumsDescription(domain.ObjectTypeMap, querySet.Type), querySet.Name), "result", "更新失败"), nil
  421 + }
  422 +
  423 + if err := transactionContext.CommitTransaction(); err != nil {
  424 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  425 + }
  426 + return struct{}{}, nil
  427 +}
  428 +
399 func (querySetService *QuerySetService) PreviewPrepare(ctx *domain.Context, updateQuerySetCommand *command.UpdateQuerySetCommand) (interface{}, error) { 429 func (querySetService *QuerySetService) PreviewPrepare(ctx *domain.Context, updateQuerySetCommand *command.UpdateQuerySetCommand) (interface{}, error) {
400 if err := updateQuerySetCommand.ValidateCommand(); err != nil { 430 if err := updateQuerySetCommand.ValidateCommand(); err != nil {
401 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 431 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -23,6 +23,8 @@ type TableObjectDto struct { @@ -23,6 +23,8 @@ type TableObjectDto struct {
23 Flag string `json:"flag,omitempty"` 23 Flag string `json:"flag,omitempty"`
24 // 启用状态 24 // 启用状态
25 Status int `json:"status"` 25 Status int `json:"status"`
  26 + // 冲突状态
  27 + InConflict bool `json:"inConflict"`
26 // 表字段 28 // 表字段
27 Fields []*domain.Field `json:"fields"` 29 Fields []*domain.Field `json:"fields"`
28 } 30 }
@@ -61,6 +63,10 @@ func (d *TableObjectDto) Update(m *domain.QuerySet) *TableObjectDto { @@ -61,6 +63,10 @@ func (d *TableObjectDto) Update(m *domain.QuerySet) *TableObjectDto {
61 d.Flag = m.Flag 63 d.Flag = m.Flag
62 d.Status = m.Status 64 d.Status = m.Status
63 d.ParentId = m.ParentId 65 d.ParentId = m.ParentId
  66 + d.InConflict = false
  67 + if m.QuerySetInfo != nil {
  68 + d.InConflict = m.QuerySetInfo.ReadyStatus == 1
  69 + }
64 return d 70 return d
65 } 71 }
66 72
@@ -362,13 +362,14 @@ func (tableService *TableService) UpdateTableStruct(ctx *domain.Context, cmd *co @@ -362,13 +362,14 @@ func (tableService *TableService) UpdateTableStruct(ctx *domain.Context, cmd *co
362 }() 362 }()
363 363
364 UpdateTableStructService, _ := factory.CreateUpdateTableStructService(transactionContext) 364 UpdateTableStructService, _ := factory.CreateUpdateTableStructService(transactionContext)
365 - if _, err := UpdateTableStructService.UpdateTableStruct(ctx, cmd.TableId, cmd.Fields, cmd.Name); err != nil { 365 + response, err := UpdateTableStructService.UpdateTableStruct(ctx, cmd.TableId, cmd.Fields, cmd.Name)
  366 + if err != nil {
366 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 367 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
367 } 368 }
368 if err := transactionContext.CommitTransaction(); err != nil { 369 if err := transactionContext.CommitTransaction(); err != nil {
369 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 370 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
370 } 371 }
371 - return struct{}{}, nil 372 + return response, nil
372 } 373 }
373 374
374 // 更新表服务 375 // 更新表服务
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
  10 +)
  11 +
  12 +func (tableService *TableService) DependencyGraph(ctx *domain.Context, cmd *query.GetTableQuery) (interface{}, error) {
  13 + if err := cmd.ValidateQuery(); err != nil {
  14 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  15 + }
  16 + transactionContext, err := factory.CreateTransactionContext(nil)
  17 + if err != nil {
  18 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  19 + }
  20 + if err := transactionContext.StartTransaction(); err != nil {
  21 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  22 + }
  23 + defer func() {
  24 + transactionContext.RollbackTransaction()
  25 + }()
  26 + response, err := domainService.DependencyTables(transactionContext.(*pgTransaction.TransactionContext), ctx, cmd.TableId)
  27 + if err := transactionContext.CommitTransaction(); err != nil {
  28 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  29 + }
  30 + return map[string]interface{}{
  31 + "nodes": response,
  32 + }, nil
  33 +}
@@ -9,10 +9,11 @@ func (et EventType) ToString() string { @@ -9,10 +9,11 @@ func (et EventType) ToString() string {
9 } 9 }
10 10
11 const ( 11 const (
12 - TableDataEditEvent EventType = "table.data.edit"  
13 - TableDataImportEvent EventType = "table.data.import"  
14 - TableDeleteEvent EventType = "table.delete"  
15 - QuerySetUpdateEvent EventType = "table.query.set.update" 12 + TableDataEditEvent EventType = "table.data.edit"
  13 + TableDataImportEvent EventType = "table.data.import"
  14 + TableDeleteEvent EventType = "table.delete"
  15 + QuerySetUpdateEvent EventType = "table.query.set.update"
  16 + QuerySetUpdateRenameEvent EventType = "table.query.set.update.rename"
16 ) 17 )
17 18
18 type EventTable struct { 19 type EventTable struct {
@@ -77,6 +77,7 @@ func (querySet *QuerySet) Update(queryComponents []*QueryComponent, tableId int) @@ -77,6 +77,7 @@ func (querySet *QuerySet) Update(queryComponents []*QueryComponent, tableId int)
77 if querySet.QuerySetInfo.BindTableId == 0 { 77 if querySet.QuerySetInfo.BindTableId == 0 {
78 querySet.QuerySetInfo.BindTableId = tableId 78 querySet.QuerySetInfo.BindTableId = tableId
79 } 79 }
  80 + querySet.QuerySetInfo.ResolveConflictStatus()
80 querySet.UpdatedAt = time.Now() 81 querySet.UpdatedAt = time.Now()
81 return nil 82 return nil
82 } 83 }
@@ -38,7 +38,7 @@ type QueryComponent struct { @@ -38,7 +38,7 @@ type QueryComponent struct {
38 Layout *LayoutRule `json:"layout"` 38 Layout *LayoutRule `json:"layout"`
39 } 39 }
40 40
41 -func (qc QueryComponent) AllSelectExpr() []SelectExpr { 41 +func (qc *QueryComponent) AllSelectExpr() []SelectExpr {
42 var res = make([]SelectExpr, 0) 42 var res = make([]SelectExpr, 0)
43 for _, s := range qc.Selects { 43 for _, s := range qc.Selects {
44 res = append(res, s.SelectExpr) 44 res = append(res, s.SelectExpr)
@@ -113,6 +113,24 @@ func (expr *FieldExpr) Complete() string { @@ -113,6 +113,24 @@ func (expr *FieldExpr) Complete() string {
113 return exprSql 113 return exprSql
114 } 114 }
115 115
  116 +func (expr *FieldExpr) UpdateTable(t *Table) {
  117 + if t == nil || t.TableId == 0 {
  118 + return
  119 + }
  120 + matchTableName := ""
  121 + for i, f := range expr.TableFields {
  122 + if f.TableId == t.TableId {
  123 + matchTableName = f.TableName
  124 + if f.TableId == t.TableId {
  125 + expr.TableFields[i].TableName = t.Name
  126 + }
  127 + }
  128 + }
  129 + if len(matchTableName) > 0 {
  130 + expr.ExprHuman = strings.ReplaceAll(expr.ExprHuman, matchTableName, t.Name)
  131 + }
  132 +}
  133 +
116 func (expr *FieldExpr) Tables() []int { 134 func (expr *FieldExpr) Tables() []int {
117 set := collection.NewSet() 135 set := collection.NewSet()
118 for _, f := range expr.TableFields { 136 for _, f := range expr.TableFields {
  1 +package domain
  2 +
  3 +func (qc *QueryComponent) UpdateTables(tables ...*Table) {
  4 + for _, table := range tables {
  5 + qc.updateTable(table)
  6 + }
  7 +}
  8 +func (qc *QueryComponent) updateTable(table *Table) {
  9 + for i := range qc.Conditions {
  10 + qc.Conditions[i].FieldLeft.UpdateTable(table)
  11 + qc.Conditions[i].FieldRight.UpdateTable(table)
  12 + }
  13 + for i := range qc.Selects {
  14 + qc.Selects[i].FieldLeft.UpdateTable(table)
  15 + qc.Selects[i].FieldRight.UpdateTable(table)
  16 + for j := range qc.Selects[i].SubSelects {
  17 + qc.Selects[i].SubSelects[j].FieldLeft.UpdateTable(table)
  18 + qc.Selects[i].SubSelects[j].FieldRight.UpdateTable(table)
  19 + }
  20 + }
  21 + if qc.Formula != nil && len(qc.Formula.ExprHuman) > 0 {
  22 + qc.Formula.FieldExpr.UpdateTable(table)
  23 + }
  24 + if qc.Aggregation != nil {
  25 + for i := range qc.Aggregation.RowFields {
  26 + qc.Aggregation.RowFields[i].Expr.UpdateTable(table)
  27 + }
  28 + for i := range qc.Aggregation.ValueFields {
  29 + qc.Aggregation.ValueFields[i].Expr.UpdateTable(table)
  30 + }
  31 + }
  32 + if qc.Layout != nil {
  33 + for i := range qc.Layout.Cells {
  34 + if qc.Layout.Cells[i].Data == nil || qc.Layout.Cells[i].Data.TableField == nil {
  35 + continue
  36 + }
  37 + if qc.Layout.Cells[i].Data.TableField.TableId == table.TableId {
  38 + qc.Layout.Cells[i].Data.TableField.TableName = table.Name
  39 + }
  40 + }
  41 + }
  42 +}
@@ -2,4 +2,13 @@ package domain @@ -2,4 +2,13 @@ package domain
2 2
3 type QuerySetInfo struct { 3 type QuerySetInfo struct {
4 BindTableId int // 查询集绑定的表 4 BindTableId int // 查询集绑定的表
  5 + ReadyStatus int // 准备状态 0:正常 1:冲突状态
  6 +}
  7 +
  8 +func (q *QuerySetInfo) WithConflictStatus() {
  9 + q.ReadyStatus = 1
  10 +}
  11 +
  12 +func (q *QuerySetInfo) ResolveConflictStatus() {
  13 + q.ReadyStatus = 0
5 } 14 }
@@ -878,7 +878,7 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str @@ -878,7 +878,7 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str
878 return ErrQuerySetNameExists 878 return ErrQuerySetNameExists
879 } 879 }
880 qs.Name = name 880 qs.Name = name
881 - _, err = querySetRepository.Save(qs) 881 + qs, err = querySetRepository.Save(qs)
882 if err != nil { 882 if err != nil {
883 return err 883 return err
884 } 884 }
@@ -896,6 +896,9 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str @@ -896,6 +896,9 @@ func (ptr *QuerySetService) Rename(ctx *domain.Context, querySetId int, name str
896 return err 896 return err
897 } 897 }
898 } 898 }
  899 + defer func() {
  900 + AsyncEvent(domain.NewEventTable(ctx, domain.QuerySetUpdateRenameEvent).WithQuerySet(qs))
  901 + }()
899 // 日志 902 // 日志
900 if err = FastLog(ptr.transactionContext, domain.QuerySetLog, qs.QuerySetId, &RenameQuerySetLog{ 903 if err = FastLog(ptr.transactionContext, domain.QuerySetLog, qs.QuerySetId, &RenameQuerySetLog{
901 LogEntry: domain.NewLogEntry(qs.Name, qs.Type, domain.UnKnown, ctx), 904 LogEntry: domain.NewLogEntry(qs.Name, qs.Type, domain.UnKnown, ctx),
@@ -3,8 +3,10 @@ package domainService @@ -3,8 +3,10 @@ package domainService
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "github.com/zeromicro/go-zero/core/collection"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
8 "time" 10 "time"
9 ) 11 )
10 12
@@ -78,9 +80,66 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl @@ -78,9 +80,66 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl
78 if _, err = ByteCore.SplitTable(domain.ReqSplitTable{FromTable: mainTable, ToSubTable: table}); err != nil { 80 if _, err = ByteCore.SplitTable(domain.ReqSplitTable{FromTable: mainTable, ToSubTable: table}); err != nil {
79 return nil, err 81 return nil, err
80 } 82 }
  83 + //var tablesAffected []TableNode
  84 + //if len(adds) > 0 {
  85 + // tablesAffected, _ = DependencyTables(ptr.transactionContext, ctx, tableId)
  86 + //}
  87 + //return map[string]interface{}{
  88 + // "tablesAffected": tablesAffected,
  89 + //}, nil
81 return struct{}{}, nil 90 return struct{}{}, nil
82 } 91 }
83 92
  93 +func DependencyTables(ptr *pgTransaction.TransactionContext, context *domain.Context, tableId int) ([]TableNode, error) {
  94 + ret := make([]TableNode, 0)
  95 + // tableId 相关联的
  96 + tableRepository, _ := repository.NewTableRepository(ptr)
  97 + _, tables, err := tableRepository.Find(map[string]interface{}{"context": context, "tableTypesNotIn": []string{domain.TemporaryTable.ToString(), domain.ExcelTable.ToString()}})
  98 + if err != nil {
  99 + return nil, err
  100 + }
  101 +
  102 + tableDependencyService, _ := NewTableDependencyService(ptr)
  103 + tableDependTree := tableDependencyService.TableDependTree(tables, tableId)
  104 + set := collection.NewSet()
  105 + stack := utils.NewEmptyStack()
  106 + list := make([]int, 0)
  107 + stack.Push(tableId)
  108 + for {
  109 + item := stack.Pop()
  110 + if item == nil {
  111 + break
  112 + }
  113 + id := item.(int)
  114 + for _, edge := range tableDependTree.Edges {
  115 + if edge.DependChildId == id {
  116 + stack.Push(edge.Id)
  117 + if !set.Contains(edge.Id) {
  118 + set.Add(edge.Id)
  119 + list = append(list, edge.Id)
  120 + }
  121 + }
  122 + }
  123 + }
  124 + if len(list) > 0 {
  125 + querySetRepository, _ := repository.NewQuerySetRepository(ptr)
  126 + _, querySets, _ := querySetRepository.Find(map[string]interface{}{"context": context, "bindTableIds": list})
  127 + for _, id := range list {
  128 + if v, ok := tableDependencyService.TableMap[id]; ok {
  129 + node := NewTableNode(v)
  130 + for _, q := range querySets {
  131 + if q.QuerySetInfo.BindTableId == node.TableId {
  132 + node.QuerySetId = q.QuerySetId
  133 + break
  134 + }
  135 + }
  136 + ret = append(ret, node)
  137 + }
  138 + }
  139 + }
  140 + return ret, nil
  141 +}
  142 +
84 //func MappingFields(mainTable *domain.Table, fields []*domain.Field) []*domain.Field { 143 //func MappingFields(mainTable *domain.Table, fields []*domain.Field) []*domain.Field {
85 // tableFields := mainTable.Fields(false) 144 // tableFields := mainTable.Fields(false)
86 // tableFieldsMap := (domain.Fields)(tableFields).ToMap() 145 // tableFieldsMap := (domain.Fields)(tableFields).ToMap()
@@ -29,6 +29,14 @@ func (controller *QuerySetController) UpdateQuerySet() { @@ -29,6 +29,14 @@ func (controller *QuerySetController) UpdateQuerySet() {
29 controller.Response(data, err) 29 controller.Response(data, err)
30 } 30 }
31 31
  32 +func (controller *QuerySetController) RefreshQuerySet() {
  33 + querySetService := service.NewQuerySetService(nil)
  34 + updateQuerySetCommand := &command.RefreshQuerySetCommand{}
  35 + Must(controller.Unmarshal(updateQuerySetCommand))
  36 + data, err := querySetService.RefreshQuerySet(ParseContext(controller.BaseController), updateQuerySetCommand)
  37 + controller.Response(data, err)
  38 +}
  39 +
32 func (controller *QuerySetController) PreviewPrepare() { 40 func (controller *QuerySetController) PreviewPrepare() {
33 querySetService := service.NewQuerySetService(nil) 41 querySetService := service.NewQuerySetService(nil)
34 updateQuerySetCommand := &command.UpdateQuerySetCommand{} 42 updateQuerySetCommand := &command.UpdateQuerySetCommand{}
@@ -276,3 +276,11 @@ func (controller *TableController) RowEdit() { @@ -276,3 +276,11 @@ func (controller *TableController) RowEdit() {
276 data, err := tableService.RowEditV2(ParseContext(controller.BaseController), cmd) 276 data, err := tableService.RowEditV2(ParseContext(controller.BaseController), cmd)
277 controller.Response(data, err) 277 controller.Response(data, err)
278 } 278 }
  279 +
  280 +func (controller *TableController) DependencyGraph() {
  281 + tableService := service.NewTableService(nil)
  282 + updateTableCommand := &query.GetTableQuery{}
  283 + controller.Unmarshal(updateTableCommand)
  284 + data, err := tableService.DependencyGraph(ParseContext(controller.BaseController), updateTableCommand)
  285 + controller.Response(data, err)
  286 +}
@@ -19,6 +19,7 @@ func init() { @@ -19,6 +19,7 @@ func init() {
19 web.Router("/data/query-sets/rename", &controllers.QuerySetController{}, "Post:Rename") 19 web.Router("/data/query-sets/rename", &controllers.QuerySetController{}, "Post:Rename")
20 web.Router("/data/query-sets/search", &controllers.QuerySetController{}, "Post:SearchQuerySet") 20 web.Router("/data/query-sets/search", &controllers.QuerySetController{}, "Post:SearchQuerySet")
21 web.Router("/data/query-sets/preview-prepare", &controllers.QuerySetController{}, "Post:PreviewPrepare") 21 web.Router("/data/query-sets/preview-prepare", &controllers.QuerySetController{}, "Post:PreviewPrepare")
  22 + web.Router("/data/query-sets/refresh", &controllers.QuerySetController{}, "Post:RefreshQuerySet")
22 23
23 web.Router("/data/query-sets/formula/", &controllers.QuerySetController{}, "Post:CreateQuerySet") 24 web.Router("/data/query-sets/formula/", &controllers.QuerySetController{}, "Post:CreateQuerySet")
24 web.Router("/data/query-sets/formula/:querySetId", &controllers.QuerySetController{}, "Put:UpdateQuerySet") 25 web.Router("/data/query-sets/formula/:querySetId", &controllers.QuerySetController{}, "Put:UpdateQuerySet")
@@ -21,6 +21,7 @@ func init() { @@ -21,6 +21,7 @@ func init() {
21 web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList") 21 web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList")
22 web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList") 22 web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList")
23 web.Router("/data/tables/search-query-set-tables", &controllers.TableController{}, "Post:SearchQuerySetTables") 23 web.Router("/data/tables/search-query-set-tables", &controllers.TableController{}, "Post:SearchQuerySetTables")
  24 + web.Router("/data/tables/dependency-graph", &controllers.TableController{}, "Post:DependencyGraph")
24 25
25 //web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable") 26 //web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable")
26 //web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable") 27 //web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable")
@@ -14,4 +14,5 @@ func RegisterEvent() { @@ -14,4 +14,5 @@ func RegisterEvent() {
14 event.On(domain.TableDataImportEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High) 14 event.On(domain.TableDataImportEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
15 event.On(domain.TableDeleteEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High) 15 event.On(domain.TableDeleteEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
16 event.On(domain.QuerySetUpdateEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High) 16 event.On(domain.QuerySetUpdateEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
  17 + event.On(domain.QuerySetUpdateRenameEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
17 } 18 }
@@ -14,5 +14,9 @@ func tableDataChangeHandler(e event.Event) error { @@ -14,5 +14,9 @@ func tableDataChangeHandler(e event.Event) error {
14 _, err := svr.Handler(nil, &command.TableEventCommand{ 14 _, err := svr.Handler(nil, &command.TableEventCommand{
15 EventTable: et, 15 EventTable: et,
16 }) 16 })
  17 +
  18 + svr.HandlerTableAffectedMarkToConflictStatus(et.Context, &command.TableEventCommand{
  19 + EventTable: et,
  20 + })
17 return err 21 return err
18 } 22 }