|
|
package service
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"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/application/event/command"
|
...
|
...
|
@@ -10,6 +12,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
|
|
|
)
|
|
|
|
|
|
type TableEventService struct {
|
...
|
...
|
@@ -68,6 +71,62 @@ func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *co |
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
func (tableEventService *TableEventService) HandlerTableAffectedMarkToConflictStatus(ctx *domain.Context, cmd *command.TableEventCommand) (interface{}, 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()
|
|
|
}()
|
|
|
|
|
|
data := cmd.EventTable
|
|
|
tableId := 0
|
|
|
switch data.Type {
|
|
|
case domain.TableDataEditEvent:
|
|
|
tableId = data.Table.TableId
|
|
|
case domain.QuerySetUpdateEvent, domain.QuerySetUpdateRenameEvent:
|
|
|
tableId = data.QuerySet.QuerySetInfo.BindTableId
|
|
|
default:
|
|
|
return nil, err
|
|
|
}
|
|
|
if tableId == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
// tableId 相关联的
|
|
|
tableRepository, _, _ := factory.FastPgTable(transactionContext, 0)
|
|
|
|
|
|
_, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "dependencyTable": tableId, "tableTypesNotIn": []string{domain.TemporaryTable.ToString()}})
|
|
|
if errors.Is(err, domain.ErrorNotFound) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
tableIds := make([]int, 0)
|
|
|
for _, table := range tables {
|
|
|
tableIds = append(tableIds, table.TableId)
|
|
|
}
|
|
|
if len(tableIds) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
|
|
|
_, querySets, _ := querySetRepository.Find(map[string]interface{}{"context": ctx, "bindTableIds": tableIds})
|
|
|
for _, querySet := range querySets {
|
|
|
log.Logger.Debug(fmt.Sprintf("【集合状态更新】 id:%v name:%v ReadyStatus:1", querySet.QuerySetId, querySet.Name))
|
|
|
querySet.QuerySetInfo.WithConflictStatus()
|
|
|
_, err = querySetRepository.Save(querySet)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
func NewTableEventService(options map[string]interface{}) *TableEventService {
|
|
|
svr := &TableEventService{}
|
|
|
return svr
|
...
|
...
|
|