作者 yangfu

先应用于的排前面

... ... @@ -3,3 +3,7 @@ ALTER TABLE files ADD app_key TEXT;
Update files set file_from = 'ByteBankWebClient';
CREATE INDEX IF NOT EXISTS idx_files_app_key ON metadata.files USING btree(app_key);
alter table metadata.tables add column apply_at timestamptz;
update metadata.tables set apply_at = null where table_type in ('MainTable','SubTable','SideTable') and apply_at is null;
\ No newline at end of file
... ...
... ... @@ -16,7 +16,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/event"
)
const Version = "v1.3.0"
const Version = "v1.4.0"
func main() {
defer func() {
... ...
... ... @@ -27,6 +27,9 @@ type TableObjectDto struct {
InConflict bool `json:"inConflict"`
// 表字段
Fields []*domain.Field `json:"fields"`
// 引用于时间
ApplyAt int64 `json:"-"`
ApplyString string `json:"applyAtString"`
}
func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto {
... ... @@ -40,6 +43,8 @@ func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto {
d.Module = m.TableInfo.ApplyOnModule
}
d.Fields = make([]*domain.Field, 0)
d.ApplyAt = m.ApplyAt.Unix()
d.ApplyString = m.ApplyAt.Format("2006-01-02 15:00")
return d
}
... ...
... ... @@ -16,6 +16,7 @@ import (
"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"
"time"
)
// 表服务
... ... @@ -424,8 +425,10 @@ func (tableService *TableService) ApplyOn(ctx *domain.Context, cmd *command.Appl
}
if table.TableInfo == nil {
table.TableInfo = domain.NewTableInfo().SetApplyOn(cmd.Module)
table.ApplyAt = time.Now()
} else {
table.TableInfo.SetApplyOn(cmd.Module)
table.ApplyAt = time.Now()
}
defer func() {
domainService.AsyncEvent(domain.NewEventTable(ctx, domain.TableApplyOnEvent).WithTable(table).WithMetadata("module", cmd.Module))
... ...
... ... @@ -124,9 +124,11 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
sort.Slice(response, func(i, j int) bool {
item1 := response[i]
item2 := response[j]
//k1 := fmt.Sprintf("%v-%v-%v", item1.TableType, item1.ParentId, item1.Id)
//k2 := fmt.Sprintf("%v-%v-%v", item2.TableType, item2.ParentId, item2.Id)
//return k1 < k2
// 拆解模块按应用时间倒叙排列
if domain.AssertTableType(item1.TableType, domain.MainTable, domain.SubTable, domain.SideTable) &&
domain.AssertTableType(item2.TableType, domain.MainTable, domain.SubTable, domain.SideTable) {
return item1.ApplyAt > item2.ApplyAt
}
return item1.Id < item2.Id
})
return map[string]interface{}{
... ...
... ... @@ -45,7 +45,8 @@ type Table struct {
Context *Context `json:"context"`
// 表信息
TableInfo *TableInfo `json:"tableInfo"`
// 应用于的时间
ApplyAt time.Time `json:"applyAt"`
// 表头行号 从0开始
HeaderRow int `json:"-"`
}
... ...
... ... @@ -41,4 +41,6 @@ type Table struct {
Context *domain.Context `comment:"扩展"`
// 表信息
TableInfo *domain.TableInfo `comment:"表信息"`
// 应用于的时间
ApplyAt time.Time `comment:"应用于的时间"`
}
... ...
... ... @@ -27,5 +27,6 @@ func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain.
RowCount: tableModel.RowCount,
Context: tableModel.Context,
TableInfo: tableModel.TableInfo,
ApplyAt: tableModel.ApplyAt,
}, nil
}
... ...
... ... @@ -33,6 +33,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
"row_count",
"context",
"table_info",
"apply_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at"))
... ... @@ -59,6 +60,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
&table.RowCount,
&table.Context,
&table.TableInfo,
&table.ApplyAt,
),
fmt.Sprintf("INSERT INTO metadata.tables (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
table.TableType,
... ... @@ -75,6 +77,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
table.RowCount,
table.Context,
table.TableInfo,
table.ApplyAt,
); err != nil {
return table, err
}
... ... @@ -99,6 +102,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
&table.RowCount,
&table.Context,
&table.TableInfo,
&table.ApplyAt,
),
fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? and version=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
table.TableType,
... ... @@ -115,6 +119,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err
table.RowCount,
table.Context,
table.TableInfo,
table.ApplyAt,
table.Identify(),
oldVersion,
); err != nil {
... ...