正在显示
23 个修改的文件
包含
897 行增加
和
539 行删除
@@ -3,3 +3,7 @@ ALTER TABLE files ADD app_key TEXT; | @@ -3,3 +3,7 @@ ALTER TABLE files ADD app_key TEXT; | ||
3 | Update files set file_from = 'ByteBankWebClient'; | 3 | Update files set file_from = 'ByteBankWebClient'; |
4 | 4 | ||
5 | CREATE INDEX IF NOT EXISTS idx_files_app_key ON metadata.files USING btree(app_key); | 5 | CREATE INDEX IF NOT EXISTS idx_files_app_key ON metadata.files USING btree(app_key); |
6 | + | ||
7 | + | ||
8 | +alter table metadata.tables add column apply_at timestamptz; | ||
9 | +update metadata.tables set apply_at = null where table_type in ('MainTable','SubTable','SideTable') and apply_at is null; |
@@ -3,46 +3,50 @@ module gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion | @@ -3,46 +3,50 @@ module gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion | ||
3 | go 1.16 | 3 | go 1.16 |
4 | 4 | ||
5 | require ( | 5 | require ( |
6 | - github.com/ajg/form v1.5.1 // indirect | ||
7 | - github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible // indirect | 6 | + github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible |
8 | github.com/beego/beego/v2 v2.0.1 | 7 | github.com/beego/beego/v2 v2.0.1 |
9 | github.com/bwmarrin/snowflake v0.3.0 | 8 | github.com/bwmarrin/snowflake v0.3.0 |
10 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 9 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
11 | github.com/extrame/xls v0.0.1 | 10 | github.com/extrame/xls v0.0.1 |
12 | - github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | ||
13 | - github.com/fatih/structs v1.1.0 // indirect | ||
14 | github.com/gavv/httpexpect v2.0.0+incompatible | 11 | github.com/gavv/httpexpect v2.0.0+incompatible |
15 | github.com/go-gota/gota v0.12.0 | 12 | github.com/go-gota/gota v0.12.0 |
16 | github.com/go-pg/pg/v10 v10.10.6 | 13 | github.com/go-pg/pg/v10 v10.10.6 |
17 | github.com/go-redis/redis v6.15.9+incompatible | 14 | github.com/go-redis/redis v6.15.9+incompatible |
18 | - github.com/google/go-querystring v1.1.0 // indirect | ||
19 | github.com/google/gofuzz v1.2.0 | 15 | github.com/google/gofuzz v1.2.0 |
20 | github.com/google/uuid v1.3.0 | 16 | github.com/google/uuid v1.3.0 |
21 | github.com/gookit/event v1.0.6 | 17 | github.com/gookit/event v1.0.6 |
22 | - github.com/imkira/go-interpol v1.1.0 // indirect | ||
23 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | 18 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 |
24 | - github.com/moul/http2curl v1.0.0 // indirect | ||
25 | github.com/onsi/ginkgo v1.16.5 | 19 | github.com/onsi/ginkgo v1.16.5 |
26 | github.com/onsi/gomega v1.18.1 | 20 | github.com/onsi/gomega v1.18.1 |
27 | github.com/patrickmn/go-cache v2.1.0+incompatible | 21 | github.com/patrickmn/go-cache v2.1.0+incompatible |
28 | - github.com/sergi/go-diff v1.2.0 // indirect | ||
29 | github.com/shopspring/decimal v1.3.1 | 22 | github.com/shopspring/decimal v1.3.1 |
30 | - github.com/silenceper/wechat/v2 v2.1.4 // indirect | ||
31 | - github.com/smartystreets/goconvey v1.7.2 // indirect | ||
32 | github.com/stretchr/testify v1.7.1 | 23 | github.com/stretchr/testify v1.7.1 |
24 | + github.com/xuri/excelize/v2 v2.6.0 | ||
25 | + github.com/zeromicro/go-zero v1.3.4 | ||
26 | + golang.org/x/text v0.3.7 | ||
27 | + gorm.io/driver/mysql v1.3.6 | ||
28 | + gorm.io/driver/postgres v1.3.9 | ||
29 | + gorm.io/gorm v1.23.8 | ||
30 | +) | ||
31 | + | ||
32 | +require ( | ||
33 | + github.com/ajg/form v1.5.1 // indirect | ||
34 | + github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | ||
35 | + github.com/fatih/structs v1.1.0 // indirect | ||
36 | + github.com/google/go-querystring v1.1.0 // indirect | ||
37 | + github.com/imkira/go-interpol v1.1.0 // indirect | ||
38 | + github.com/moul/http2curl v1.0.0 // indirect | ||
39 | + github.com/sergi/go-diff v1.2.0 // indirect | ||
40 | + github.com/sirupsen/logrus v1.9.0 // indirect | ||
41 | + github.com/smartystreets/goconvey v1.7.2 // indirect | ||
33 | github.com/valyala/fasthttp v1.38.0 // indirect | 42 | github.com/valyala/fasthttp v1.38.0 // indirect |
34 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect | 43 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect |
35 | github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect | 44 | github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect |
36 | - github.com/xuri/excelize/v2 v2.6.0 | ||
37 | github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect | 45 | github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect |
38 | github.com/yudai/gojsondiff v1.0.0 // indirect | 46 | github.com/yudai/gojsondiff v1.0.0 // indirect |
39 | github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | 47 | github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect |
40 | github.com/yudai/pp v2.0.1+incompatible // indirect | 48 | github.com/yudai/pp v2.0.1+incompatible // indirect |
41 | - github.com/zeromicro/go-zero v1.3.4 | ||
42 | - golang.org/x/text v0.3.7 | ||
43 | - gorm.io/driver/mysql v1.3.6 | ||
44 | - gorm.io/driver/postgres v1.3.9 | ||
45 | - gorm.io/gorm v1.23.8 | 49 | + golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect |
46 | ) | 50 | ) |
47 | 51 | ||
48 | replace ( | 52 | replace ( |
@@ -16,7 +16,7 @@ import ( | @@ -16,7 +16,7 @@ import ( | ||
16 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/event" | 16 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/event" |
17 | ) | 17 | ) |
18 | 18 | ||
19 | -const Version = "v1.3.0" | 19 | +const Version = "v1.4.0" |
20 | 20 | ||
21 | func main() { | 21 | func main() { |
22 | defer func() { | 22 | defer func() { |
1 | package service | 1 | package service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "errors" | ||
5 | "fmt" | 4 | "fmt" |
6 | "github.com/linmadan/egglib-go/core/application" | 5 | "github.com/linmadan/egglib-go/core/application" |
7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
@@ -77,62 +76,6 @@ func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *co | @@ -77,62 +76,6 @@ func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *co | ||
77 | return nil, nil | 76 | return nil, nil |
78 | } | 77 | } |
79 | 78 | ||
80 | -func (tableEventService *TableEventService) HandlerTableAffectedMarkToConflictStatus(ctx *domain.Context, cmd *command.TableEventCommand) (interface{}, error) { | ||
81 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
82 | - if err != nil { | ||
83 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
84 | - } | ||
85 | - if err := transactionContext.StartTransaction(); err != nil { | ||
86 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
87 | - } | ||
88 | - defer func() { | ||
89 | - transactionContext.RollbackTransaction() | ||
90 | - }() | ||
91 | - | ||
92 | - data := cmd.EventTable | ||
93 | - tableId := 0 | ||
94 | - switch data.Type { | ||
95 | - case domain.TableStructEditEvent, domain.TableDeleteEvent: | ||
96 | - tableId = data.Table.TableId | ||
97 | - case domain.QuerySetUpdateEvent, domain.QuerySetUpdateRenameEvent: | ||
98 | - tableId = data.QuerySet.QuerySetInfo.BindTableId | ||
99 | - default: | ||
100 | - return nil, err | ||
101 | - } | ||
102 | - if tableId == 0 { | ||
103 | - return nil, nil | ||
104 | - } | ||
105 | - // tableId 相关联的 | ||
106 | - tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) | ||
107 | - | ||
108 | - _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "dependencyTable": tableId, "tableTypesNotIn": []string{domain.TemporaryTable.ToString()}}) | ||
109 | - if errors.Is(err, domain.ErrorNotFound) { | ||
110 | - return nil, nil | ||
111 | - } | ||
112 | - tableIds := make([]int, 0) | ||
113 | - for _, table := range tables { | ||
114 | - tableIds = append(tableIds, table.TableId) | ||
115 | - } | ||
116 | - if len(tableIds) == 0 { | ||
117 | - return nil, nil | ||
118 | - } | ||
119 | - querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0) | ||
120 | - _, querySets, _ := querySetRepository.Find(map[string]interface{}{"context": ctx, "bindTableIds": tableIds}) | ||
121 | - for _, querySet := range querySets { | ||
122 | - log.Logger.Debug(fmt.Sprintf("【集合状态更新】 id:%v name:%v ReadyStatus:1", querySet.QuerySetId, querySet.Name)) | ||
123 | - querySet.QuerySetInfo.WithConflictStatus() | ||
124 | - _, err = querySetRepository.Save(querySet) | ||
125 | - if err != nil { | ||
126 | - return nil, err | ||
127 | - } | ||
128 | - } | ||
129 | - | ||
130 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
131 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
132 | - } | ||
133 | - return nil, nil | ||
134 | -} | ||
135 | - | ||
136 | func NewTableEventService(options map[string]interface{}) *TableEventService { | 79 | func NewTableEventService(options map[string]interface{}) *TableEventService { |
137 | svr := &TableEventService{} | 80 | svr := &TableEventService{} |
138 | delayNotifyTimingWheel, _ := collection.NewTimingWheel(time.Second, 10, svr.TimingWheelFunc) | 81 | delayNotifyTimingWheel, _ := collection.NewTimingWheel(time.Second, 10, svr.TimingWheelFunc) |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "github.com/linmadan/egglib-go/core/application" | ||
7 | + "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/factory" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
11 | + "reflect" | ||
12 | + "sort" | ||
13 | +) | ||
14 | + | ||
15 | +func (tableEventService *TableEventService) HandlerTableAffectedMarkToConflictStatus(ctx *domain.Context, cmd *command.TableEventCommand) (interface{}, error) { | ||
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 | + | ||
27 | + data := cmd.EventTable | ||
28 | + tableId := 0 | ||
29 | + switch data.Type { | ||
30 | + case domain.TableStructEditEvent, domain.TableDeleteEvent: | ||
31 | + tableId = data.Table.TableId | ||
32 | + case domain.QuerySetUpdateEvent: | ||
33 | + // 结构变更才报冲突 | ||
34 | + if !checkStructChange(cmd) { | ||
35 | + return nil, err | ||
36 | + } | ||
37 | + tableId = data.QuerySet.QuerySetInfo.BindTableId | ||
38 | + case domain.QuerySetUpdateRenameEvent: | ||
39 | + tableId = data.QuerySet.QuerySetInfo.BindTableId | ||
40 | + default: | ||
41 | + return nil, err | ||
42 | + } | ||
43 | + if tableId == 0 { | ||
44 | + return nil, nil | ||
45 | + } | ||
46 | + // tableId 相关联的 | ||
47 | + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) | ||
48 | + | ||
49 | + _, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "dependencyTable": tableId, "tableTypesNotIn": []string{domain.TemporaryTable.ToString()}}) | ||
50 | + if errors.Is(err, domain.ErrorNotFound) { | ||
51 | + return nil, nil | ||
52 | + } | ||
53 | + tableIds := make([]int, 0) | ||
54 | + for _, table := range tables { | ||
55 | + tableIds = append(tableIds, table.TableId) | ||
56 | + } | ||
57 | + if len(tableIds) == 0 { | ||
58 | + return nil, nil | ||
59 | + } | ||
60 | + querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0) | ||
61 | + _, querySets, _ := querySetRepository.Find(map[string]interface{}{"context": ctx, "bindTableIds": tableIds}) | ||
62 | + for _, querySet := range querySets { | ||
63 | + log.Logger.Debug(fmt.Sprintf("【集合状态更新】 id:%v name:%v ReadyStatus:1", querySet.QuerySetId, querySet.Name)) | ||
64 | + querySet.QuerySetInfo.WithConflictStatus() | ||
65 | + _, err = querySetRepository.Save(querySet) | ||
66 | + if err != nil { | ||
67 | + return nil, err | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + //tableDependencyService, _ := domainService.NewTableDependencyService(transactionContext.(*pgTransaction.TransactionContext)) | ||
72 | + //tableDependTree := tableDependencyService.TableDependTree(tables, tableId) | ||
73 | + //tree := tableDependTree.Tree | ||
74 | + // | ||
75 | + //querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0) | ||
76 | + //if len(tree) > 0 { | ||
77 | + // _, querySets, _ := querySetRepository.Find(map[string]interface{}{ | ||
78 | + // "types": []string{domain.SchemaTable.ToString(), domain.SubProcessTable.ToString(), domain.CalculateTable.ToString()}, | ||
79 | + // "bindTableIds": tree, | ||
80 | + // }) | ||
81 | + // for _, querySet := range querySets { | ||
82 | + // log.Logger.Debug(fmt.Sprintf("【集合状态更新】 id:%v name:%v 标记冲突", querySet.QuerySetId, querySet.Name)) | ||
83 | + // querySet.QuerySetInfo.WithConflictStatus() | ||
84 | + // _, err = querySetRepository.Save(querySet) | ||
85 | + // if err != nil { | ||
86 | + // return nil, err | ||
87 | + // } | ||
88 | + // } | ||
89 | + //} | ||
90 | + | ||
91 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
92 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
93 | + } | ||
94 | + return nil, nil | ||
95 | +} | ||
96 | + | ||
97 | +func checkStructChange(cmd *command.TableEventCommand) bool { | ||
98 | + var ( | ||
99 | + newSet = cmd.EventTable.QuerySet | ||
100 | + oldSet = cmd.EventTable.OldQuerySet | ||
101 | + newTable = cmd.EventTable.Table | ||
102 | + oldTable = cmd.EventTable.OldTable | ||
103 | + ) | ||
104 | + if newSet == nil || oldSet == nil { | ||
105 | + return false | ||
106 | + } | ||
107 | + var ( | ||
108 | + t string = newSet.Type | ||
109 | + ) | ||
110 | + | ||
111 | + switch t { | ||
112 | + case domain.SchemaTable.ToString(), domain.SubProcessTable.ToString(): | ||
113 | + // 第一步表有变更 | ||
114 | + newSetDepTables := newSet.GetDependencyTables(newSet.QueryComponents) | ||
115 | + oldSetDepTables := newSet.GetDependencyTables(oldSet.QueryComponents) | ||
116 | + sort.SliceStable(newSetDepTables, func(i, j int) bool { | ||
117 | + return newSetDepTables[i] < newSetDepTables[j] | ||
118 | + }) | ||
119 | + sort.SliceStable(oldSetDepTables, func(i, j int) bool { | ||
120 | + return oldSetDepTables[i] < oldSetDepTables[j] | ||
121 | + }) | ||
122 | + if !reflect.DeepEqual(newSetDepTables, oldSetDepTables) { | ||
123 | + log.Logger.Debug(fmt.Sprintf("方案/过程:%v 依赖变更 %v -> %v", t, oldSetDepTables, newSetDepTables)) | ||
124 | + return true | ||
125 | + } | ||
126 | + case domain.CalculateTable.ToString(): | ||
127 | + | ||
128 | + case domain.CalculateItem.ToString(), domain.CalculateSet.ToString(): | ||
129 | + return false | ||
130 | + } | ||
131 | + if newTable == nil || oldTable == nil { | ||
132 | + return false | ||
133 | + } | ||
134 | + // 第二步判断字段是否有变更 | ||
135 | + newTableFields := tableFields(newTable) | ||
136 | + oldTableFields := tableFields(oldTable) | ||
137 | + sort.Strings(newTableFields) | ||
138 | + sort.Strings(oldTableFields) | ||
139 | + if !reflect.DeepEqual(newTableFields, oldTableFields) { | ||
140 | + log.Logger.Debug(fmt.Sprintf("计算表:%v 结构变更 %v -> %v", t, oldTableFields, newTableFields)) | ||
141 | + return true | ||
142 | + } | ||
143 | + return false | ||
144 | +} | ||
145 | + | ||
146 | +func tableFields(t *domain.Table) []string { | ||
147 | + var result = make([]string, 0) | ||
148 | + for _, f := range t.Fields(false) { | ||
149 | + result = append(result, f.Name) | ||
150 | + } | ||
151 | + return result | ||
152 | +} |
@@ -380,17 +380,25 @@ func (querySetService *QuerySetService) UpdateQuerySet(ctx *domain.Context, upda | @@ -380,17 +380,25 @@ func (querySetService *QuerySetService) UpdateQuerySet(ctx *domain.Context, upda | ||
380 | }() | 380 | }() |
381 | var ( | 381 | var ( |
382 | qs *domain.QuerySet | 382 | qs *domain.QuerySet |
383 | + qsTable *domain.Table | ||
384 | + oldQs *domain.QuerySet | ||
385 | + oldQsTable *domain.Table | ||
383 | ) | 386 | ) |
384 | defer func() { | 387 | defer func() { |
385 | if qs != nil { | 388 | if qs != nil { |
386 | - domainService.AsyncEvent(domain.NewEventTable(ctx, domain.QuerySetUpdateEvent).WithQuerySet(qs)) | 389 | + domainService.AsyncEvent(domain.NewEventTable(ctx, domain.QuerySetUpdateEvent). |
390 | + WithQuerySet(qs).WithOldQuerySet(oldQs).WithTable(qsTable).WithOldTable(oldQsTable)) | ||
387 | } | 391 | } |
388 | }() | 392 | }() |
393 | + _, oldQs, _ = factory.FastPgQuerySet(transactionContext, updateQuerySetCommand.QuerySetId) | ||
394 | + if oldQs != nil { | ||
395 | + _, oldQsTable, _ = factory.FastPgTable(transactionContext, oldQs.QuerySetInfo.BindTableId) | ||
396 | + } | ||
389 | svr, _ := factory.FastQuerySetServices(transactionContext) | 397 | svr, _ := factory.FastQuerySetServices(transactionContext) |
390 | if qs, err = svr.Update(ctx, updateQuerySetCommand.QuerySetId, updateQuerySetCommand.QueryComponents); err != nil { | 398 | if qs, err = svr.Update(ctx, updateQuerySetCommand.QuerySetId, updateQuerySetCommand.QueryComponents); err != nil { |
391 | return nil, factory.FastError(err) | 399 | return nil, factory.FastError(err) |
392 | } | 400 | } |
393 | - | 401 | + _, qsTable, _ = factory.FastPgTable(transactionContext, qs.QuerySetInfo.BindTableId) |
394 | if err := transactionContext.CommitTransaction(); err != nil { | 402 | if err := transactionContext.CommitTransaction(); err != nil { |
395 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 403 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
396 | } | 404 | } |
@@ -27,6 +27,9 @@ type TableObjectDto struct { | @@ -27,6 +27,9 @@ type TableObjectDto struct { | ||
27 | InConflict bool `json:"inConflict"` | 27 | InConflict bool `json:"inConflict"` |
28 | // 表字段 | 28 | // 表字段 |
29 | Fields []*domain.Field `json:"fields"` | 29 | Fields []*domain.Field `json:"fields"` |
30 | + // 引用于时间 | ||
31 | + ApplyAt int64 `json:"-"` | ||
32 | + ApplyString string `json:"applyAtString"` | ||
30 | } | 33 | } |
31 | 34 | ||
32 | func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto { | 35 | func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto { |
@@ -40,6 +43,8 @@ func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto { | @@ -40,6 +43,8 @@ func (d *TableObjectDto) Load(m *domain.Table) *TableObjectDto { | ||
40 | d.Module = m.TableInfo.ApplyOnModule | 43 | d.Module = m.TableInfo.ApplyOnModule |
41 | } | 44 | } |
42 | d.Fields = make([]*domain.Field, 0) | 45 | d.Fields = make([]*domain.Field, 0) |
46 | + d.ApplyAt = m.ApplyAt.Unix() | ||
47 | + d.ApplyString = m.ApplyAt.Format("2006-01-02 15:00") | ||
43 | return d | 48 | return d |
44 | } | 49 | } |
45 | 50 |
@@ -17,7 +17,9 @@ type SearchTableQuery struct { | @@ -17,7 +17,9 @@ type SearchTableQuery struct { | ||
17 | TableTypes []string `cname:"表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表" json:"tableTypes" valid:"Required"` | 17 | TableTypes []string `cname:"表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表" json:"tableTypes" valid:"Required"` |
18 | // 父级ID | 18 | // 父级ID |
19 | ParentId int `cname:"父级ID" json:"parentId"` | 19 | ParentId int `cname:"父级ID" json:"parentId"` |
20 | - // 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块 | 20 | + // 当前所处的模块 |
21 | + CurrentModule int `json:"currentModule"` | ||
22 | + // 需要查询的模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块 | ||
21 | Module int `json:"module"` | 23 | Module int `json:"module"` |
22 | // 父级ID | 24 | // 父级ID |
23 | ParentTableId int `cname:"父级ID" json:"parentTableId"` | 25 | ParentTableId int `cname:"父级ID" json:"parentTableId"` |
@@ -98,6 +98,11 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * | @@ -98,6 +98,11 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * | ||
98 | if err != nil { | 98 | if err != nil { |
99 | return nil, factory.FastError(err) | 99 | return nil, factory.FastError(err) |
100 | } | 100 | } |
101 | + if cmd.Where != nil { | ||
102 | + data, length := dataTable.FilterByWhere(*cmd.Where) | ||
103 | + dataTable.Data = data | ||
104 | + dataTable.Total = length | ||
105 | + } | ||
101 | values := removeDuplicate(dataTable.Values(field)) | 106 | values := removeDuplicate(dataTable.Values(field)) |
102 | sort.SliceStable(values, func(i, j int) bool { | 107 | sort.SliceStable(values, func(i, j int) bool { |
103 | return values[i] < values[j] | 108 | return values[i] < values[j] |
@@ -16,6 +16,7 @@ import ( | @@ -16,6 +16,7 @@ import ( | ||
16 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" | 16 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" |
17 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" | 17 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" |
18 | "strings" | 18 | "strings" |
19 | + "time" | ||
19 | ) | 20 | ) |
20 | 21 | ||
21 | // 表服务 | 22 | // 表服务 |
@@ -424,8 +425,10 @@ func (tableService *TableService) ApplyOn(ctx *domain.Context, cmd *command.Appl | @@ -424,8 +425,10 @@ func (tableService *TableService) ApplyOn(ctx *domain.Context, cmd *command.Appl | ||
424 | } | 425 | } |
425 | if table.TableInfo == nil { | 426 | if table.TableInfo == nil { |
426 | table.TableInfo = domain.NewTableInfo().SetApplyOn(cmd.Module) | 427 | table.TableInfo = domain.NewTableInfo().SetApplyOn(cmd.Module) |
428 | + table.ApplyAt = time.Now() | ||
427 | } else { | 429 | } else { |
428 | table.TableInfo.SetApplyOn(cmd.Module) | 430 | table.TableInfo.SetApplyOn(cmd.Module) |
431 | + table.ApplyAt = time.Now() | ||
429 | } | 432 | } |
430 | defer func() { | 433 | defer func() { |
431 | domainService.AsyncEvent(domain.NewEventTable(ctx, domain.TableApplyOnEvent).WithTable(table).WithMetadata("module", cmd.Module)) | 434 | domainService.AsyncEvent(domain.NewEventTable(ctx, domain.TableApplyOnEvent).WithTable(table).WithMetadata("module", cmd.Module)) |
@@ -83,8 +83,8 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -83,8 +83,8 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
83 | if filterTableByFilterRule(t, searchQuery) { | 83 | if filterTableByFilterRule(t, searchQuery) { |
84 | continue | 84 | continue |
85 | } | 85 | } |
86 | - // 默认关闭的都不返回(拆解、计算) | ||
87 | - if t.Status == domain.StatusOff { | 86 | + // 无模块权限 并且 关闭状态的都不返回(拆解、计算) |
87 | + if !moduleHasAuth(searchQuery.CurrentModule, t.TableType) && t.Status == domain.StatusOff { | ||
88 | continue | 88 | continue |
89 | } | 89 | } |
90 | if !domain.TableType(t.TableType).TableIsSplitByGroup() { | 90 | if !domain.TableType(t.TableType).TableIsSplitByGroup() { |
@@ -124,9 +124,11 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -124,9 +124,11 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
124 | sort.Slice(response, func(i, j int) bool { | 124 | sort.Slice(response, func(i, j int) bool { |
125 | item1 := response[i] | 125 | item1 := response[i] |
126 | item2 := response[j] | 126 | item2 := response[j] |
127 | - //k1 := fmt.Sprintf("%v-%v-%v", item1.TableType, item1.ParentId, item1.Id) | ||
128 | - //k2 := fmt.Sprintf("%v-%v-%v", item2.TableType, item2.ParentId, item2.Id) | ||
129 | - //return k1 < k2 | 127 | + // 拆解模块按应用时间倒叙排列 |
128 | + if domain.AssertTableType(item1.TableType, domain.MainTable, domain.SubTable, domain.SideTable) && | ||
129 | + domain.AssertTableType(item2.TableType, domain.MainTable, domain.SubTable, domain.SideTable) { | ||
130 | + return item1.ApplyAt > item2.ApplyAt | ||
131 | + } | ||
130 | return item1.Id < item2.Id | 132 | return item1.Id < item2.Id |
131 | }) | 133 | }) |
132 | return map[string]interface{}{ | 134 | return map[string]interface{}{ |
@@ -160,3 +162,21 @@ func filterTableByFilterRule(item *dto.TableObjectDto, searchQuery *query.Search | @@ -160,3 +162,21 @@ func filterTableByFilterRule(item *dto.TableObjectDto, searchQuery *query.Search | ||
160 | } | 162 | } |
161 | return false | 163 | return false |
162 | } | 164 | } |
165 | + | ||
166 | +// 验证当前模块的权限。属于当前模块可以访问所有 | ||
167 | +func moduleHasAuth(currentModule int, t string) bool { | ||
168 | + if currentModule == 0 { | ||
169 | + return false | ||
170 | + } | ||
171 | + if currentModule == domain.ModuleQuerySetCenter { | ||
172 | + if t == domain.SchemaTable.ToString() || t == domain.SubProcessTable.ToString() || t == domain.CalculateTable.ToString() { | ||
173 | + return true | ||
174 | + } | ||
175 | + } | ||
176 | + if currentModule == domain.ModuleCalculateCenter { | ||
177 | + if t == domain.CalculateItem.ToString() || t == domain.CalculateSet.ToString() { | ||
178 | + return true | ||
179 | + } | ||
180 | + } | ||
181 | + return false | ||
182 | +} |
@@ -27,6 +27,8 @@ type EventTable struct { | @@ -27,6 +27,8 @@ type EventTable struct { | ||
27 | Type EventType | 27 | Type EventType |
28 | Table *Table | 28 | Table *Table |
29 | QuerySet *QuerySet | 29 | QuerySet *QuerySet |
30 | + OldQuerySet *QuerySet | ||
31 | + OldTable *Table | ||
30 | Metadata map[string]interface{} | 32 | Metadata map[string]interface{} |
31 | } | 33 | } |
32 | 34 | ||
@@ -52,11 +54,21 @@ func (et *EventTable) WithTable(t *Table) *EventTable { | @@ -52,11 +54,21 @@ func (et *EventTable) WithTable(t *Table) *EventTable { | ||
52 | return et | 54 | return et |
53 | } | 55 | } |
54 | 56 | ||
57 | +func (et *EventTable) WithOldTable(t *Table) *EventTable { | ||
58 | + et.OldTable = t | ||
59 | + return et | ||
60 | +} | ||
61 | + | ||
55 | func (et *EventTable) WithQuerySet(t *QuerySet) *EventTable { | 62 | func (et *EventTable) WithQuerySet(t *QuerySet) *EventTable { |
56 | et.QuerySet = t | 63 | et.QuerySet = t |
57 | return et | 64 | return et |
58 | } | 65 | } |
59 | 66 | ||
67 | +func (et *EventTable) WithOldQuerySet(t *QuerySet) *EventTable { | ||
68 | + et.OldQuerySet = t | ||
69 | + return et | ||
70 | +} | ||
71 | + | ||
60 | func (et *EventTable) WithMetadata(key string, values interface{}) *EventTable { | 72 | func (et *EventTable) WithMetadata(key string, values interface{}) *EventTable { |
61 | et.Metadata[key] = values | 73 | et.Metadata[key] = values |
62 | return et | 74 | return et |
@@ -67,6 +79,8 @@ func (et *EventTable) ResolveEvent(e event.Event) { | @@ -67,6 +79,8 @@ func (et *EventTable) ResolveEvent(e event.Event) { | ||
67 | et.Type = e.Get("Type").(EventType) | 79 | et.Type = e.Get("Type").(EventType) |
68 | et.Table = e.Get("Table").(*Table) | 80 | et.Table = e.Get("Table").(*Table) |
69 | et.QuerySet = e.Get("QuerySet").(*QuerySet) | 81 | et.QuerySet = e.Get("QuerySet").(*QuerySet) |
82 | + et.OldQuerySet = e.Get("OldQuerySet").(*QuerySet) | ||
83 | + et.OldTable = e.Get("OldTable").(*Table) | ||
70 | et.Metadata = e.Get("Metadata").(map[string]interface{}) | 84 | et.Metadata = e.Get("Metadata").(map[string]interface{}) |
71 | } | 85 | } |
72 | 86 | ||
@@ -75,7 +89,9 @@ func (et *EventTable) FireEvent() event.Event { | @@ -75,7 +89,9 @@ func (et *EventTable) FireEvent() event.Event { | ||
75 | e["Context"] = et.Context | 89 | e["Context"] = et.Context |
76 | e["Type"] = et.Type | 90 | e["Type"] = et.Type |
77 | e["Table"] = et.Table | 91 | e["Table"] = et.Table |
92 | + e["OldTable"] = et.OldTable | ||
78 | e["QuerySet"] = et.QuerySet | 93 | e["QuerySet"] = et.QuerySet |
94 | + e["OldQuerySet"] = et.OldQuerySet | ||
79 | e["Metadata"] = et.Metadata | 95 | e["Metadata"] = et.Metadata |
80 | return event.MustFire(et.Type.ToString(), e) | 96 | return event.MustFire(et.Type.ToString(), e) |
81 | } | 97 | } |
@@ -28,15 +28,15 @@ type LayoutRuleItem struct { | @@ -28,15 +28,15 @@ type LayoutRuleItem struct { | ||
28 | } | 28 | } |
29 | 29 | ||
30 | type LayoutCell struct { | 30 | type LayoutCell struct { |
31 | - Type string `json:"type,omitempty"` // Table TableField Text Null | ||
32 | - Data *LayoutCellData `json:"data,omitempty"` | ||
33 | - Direction string `json:"direction,omitempty"` // 向右:Right 向下:Down | ||
34 | - Position *Location `json:"position"` | ||
35 | - X int `json:"-"` | ||
36 | - Y int `json:"-"` | ||
37 | - Length int `json:"-"` | ||
38 | - BlockData []string `json:"-"` | ||
39 | - ImageData string `json:"-"` | 31 | + Type string `json:"type,omitempty"` // 配置单元类型 字段:TableField 文本:Text |
32 | + Data *LayoutCellData `json:"data,omitempty"` // 配置单元配置值(设置的字段、设置的值) | ||
33 | + Direction string `json:"direction,omitempty"` // 配置单元方向 向右:Right 向下:Down 无方向:Null | ||
34 | + Position *Location `json:"position"` // 配置单元的定位点 | ||
35 | + X int `json:"-"` // 计算后的X坐标 | ||
36 | + Y int `json:"-"` // 计算后的Y坐标 | ||
37 | + Length int `json:"-"` // 数据长度 | ||
38 | + BlockData []string `json:"-"` // 数据块 | ||
39 | + ImageData string `json:"-"` // 调试使用的数据 | ||
40 | } | 40 | } |
41 | type Location struct { | 41 | type Location struct { |
42 | X int `json:"x"` | 42 | X int `json:"x"` |
@@ -45,7 +45,8 @@ type Table struct { | @@ -45,7 +45,8 @@ type Table struct { | ||
45 | Context *Context `json:"context"` | 45 | Context *Context `json:"context"` |
46 | // 表信息 | 46 | // 表信息 |
47 | TableInfo *TableInfo `json:"tableInfo"` | 47 | TableInfo *TableInfo `json:"tableInfo"` |
48 | - | 48 | + // 应用于的时间 |
49 | + ApplyAt time.Time `json:"applyAt"` | ||
49 | // 表头行号 从0开始 | 50 | // 表头行号 从0开始 |
50 | HeaderRow int `json:"-"` | 51 | HeaderRow int `json:"-"` |
51 | } | 52 | } |
@@ -59,6 +59,35 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain | @@ -59,6 +59,35 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain | ||
59 | } | 59 | } |
60 | 60 | ||
61 | func CellsLocationAdjust(cells []*domain.LayoutCell) { | 61 | func CellsLocationAdjust(cells []*domain.LayoutCell) { |
62 | + if len(cells) > 0 { | ||
63 | + addedRows := 0 | ||
64 | + addedColumns := 0 | ||
65 | + preRowMaxDownLength := 1 | ||
66 | + preRawCellX := 0 | ||
67 | + for _, cell := range cells { | ||
68 | + if preRawCellX != cell.X { | ||
69 | + addedColumns = 0 | ||
70 | + addedRows = addedRows + preRowMaxDownLength - 1 | ||
71 | + preRowMaxDownLength = 1 | ||
72 | + preRawCellX = cell.X | ||
73 | + } | ||
74 | + cell.X = addedRows + cell.X | ||
75 | + cell.Y = addedColumns + cell.Y | ||
76 | + println("=======") | ||
77 | + switch cell.Direction { | ||
78 | + case domain.DirectionRight: | ||
79 | + addedColumns = addedColumns + cell.Length - 1 | ||
80 | + case domain.DirectionDown: | ||
81 | + if cell.Length > preRowMaxDownLength { | ||
82 | + preRowMaxDownLength = cell.Length | ||
83 | + } | ||
84 | + case domain.DirectionNone: | ||
85 | + } | ||
86 | + } | ||
87 | + } | ||
88 | +} | ||
89 | + | ||
90 | +func CellsLocationAdjustOld(cells []*domain.LayoutCell) { | ||
62 | xMin := 0 | 91 | xMin := 0 |
63 | xMax := 0 | 92 | xMax := 0 |
64 | yMin := 0 | 93 | yMin := 0 |
@@ -422,48 +451,49 @@ func (d *DataLayoutDataTable) BlockData(cells *domain.LayoutCell) ([]string, int | @@ -422,48 +451,49 @@ func (d *DataLayoutDataTable) BlockData(cells *domain.LayoutCell) ([]string, int | ||
422 | } | 451 | } |
423 | 452 | ||
424 | func (d *DataLayoutDataTable) Shrink() error { | 453 | func (d *DataLayoutDataTable) Shrink() error { |
425 | - x := d.PointEnd.X - d.PointBegin.X | ||
426 | - y := d.PointEnd.Y - d.PointBegin.Y | 454 | + x := d.PointEnd.X - 0 //d.PointBegin.X |
455 | + y := d.PointEnd.Y - 0 //d.PointBegin.Y | ||
427 | data := make([][]string, x+1) | 456 | data := make([][]string, x+1) |
428 | for i := range data { | 457 | for i := range data { |
429 | data[i] = make([]string, y+1) | 458 | data[i] = make([]string, y+1) |
430 | } | 459 | } |
431 | iData := 0 | 460 | iData := 0 |
432 | - for i := d.PointBegin.X; i <= d.PointEnd.X; i++ { | 461 | + for i := 0; i <= d.PointEnd.X; i++ { //d.PointBegin.X |
433 | jData := 0 | 462 | jData := 0 |
434 | - for j := d.PointBegin.Y; j <= d.PointEnd.Y; j++ { | 463 | + for j := 0; j <= d.PointEnd.Y; j++ { //d.PointBegin.Y |
435 | data[iData][jData] = d.DataTable.Data[i][j] | 464 | data[iData][jData] = d.DataTable.Data[i][j] |
436 | jData++ | 465 | jData++ |
437 | } | 466 | } |
438 | iData++ | 467 | iData++ |
439 | } | 468 | } |
440 | - d.DataTable.Data = data | ||
441 | - for i := 0; i <= y; i++ { | ||
442 | - d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{ | ||
443 | - Name: fmt.Sprintf("列%d", i), | ||
444 | - SQLName: fmt.Sprintf("col%d", i), | ||
445 | - SQLType: domain.String.ToString(), | ||
446 | - }) | ||
447 | - } | ||
448 | - // 默认计算集第一行作为标题 | ||
449 | - //if len(data) >= 1 { | ||
450 | - // d.DataTable.Data = data[1:] | ||
451 | - // columnMap := collection.NewSet() | ||
452 | - // for i := 0; i < len(data[0]); i++ { | ||
453 | - // if len(data[0][i]) == 0 { | ||
454 | - // return fmt.Errorf("计算集标题第%d列不能为空", i+1) | ||
455 | - // } | ||
456 | - // if columnMap.Contains(data[0][i]) { | ||
457 | - // return fmt.Errorf("计算集第%d列重复:%v", i+1, data[0][i]) | ||
458 | - // } | ||
459 | - // columnMap.Add(data[0][i]) | 469 | + //d.DataTable.Data = data |
470 | + //for i := 0; i <= y; i++ { | ||
460 | // d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{ | 471 | // d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{ |
461 | - // Name: data[0][i], | 472 | + // Name: fmt.Sprintf("列%d", i), |
462 | // SQLName: fmt.Sprintf("col%d", i), | 473 | // SQLName: fmt.Sprintf("col%d", i), |
463 | // SQLType: domain.String.ToString(), | 474 | // SQLType: domain.String.ToString(), |
464 | // }) | 475 | // }) |
465 | - // } | ||
466 | //} | 476 | //} |
477 | + // 默认计算集第一行作为标题 | ||
478 | + if len(data) >= 1 { | ||
479 | + d.DataTable.Data = data[1:] | ||
480 | + columnMap := collection.NewSet() | ||
481 | + for i := 0; i < len(data[0]); i++ { | ||
482 | + columnValue := strings.TrimSpace(data[0][i]) | ||
483 | + if len(columnValue) == 0 { | ||
484 | + return fmt.Errorf("计算集标题第%d列不能为空", i+1) | ||
485 | + } | ||
486 | + if columnMap.Contains(columnValue) { | ||
487 | + return fmt.Errorf("计算集第%d列重复:%v", i+1, data[0][i]) | ||
488 | + } | ||
489 | + columnMap.Add(columnValue) | ||
490 | + d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{ | ||
491 | + Name: columnValue, | ||
492 | + SQLName: fmt.Sprintf("col%d", i), | ||
493 | + SQLType: domain.String.ToString(), | ||
494 | + }) | ||
495 | + } | ||
496 | + } | ||
467 | return nil | 497 | return nil |
468 | } | 498 | } |
469 | 499 |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/stretchr/testify/assert" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
6 | + "testing" | ||
7 | +) | ||
8 | + | ||
9 | +func TestNewDataLayout(t *testing.T) { | ||
10 | + inputs := []struct { | ||
11 | + cells []*domain.LayoutCell | ||
12 | + flag Location | ||
13 | + title string | ||
14 | + debug bool | ||
15 | + }{ | ||
16 | + { | ||
17 | + title: "配置组多组混合", | ||
18 | + cells: []*domain.LayoutCell{ | ||
19 | + // 分组一 | ||
20 | + { | ||
21 | + X: 0, | ||
22 | + Y: 0, | ||
23 | + Length: 2, | ||
24 | + ImageData: "2", | ||
25 | + Direction: domain.DirectionRight, | ||
26 | + }, | ||
27 | + { | ||
28 | + X: 0, | ||
29 | + Y: 1, | ||
30 | + Length: 3, | ||
31 | + ImageData: "3", | ||
32 | + Direction: domain.DirectionRight, | ||
33 | + }, | ||
34 | + { | ||
35 | + X: 0, | ||
36 | + Y: 2, | ||
37 | + Length: 1, | ||
38 | + ImageData: "", | ||
39 | + Direction: domain.DirectionRight, | ||
40 | + }, | ||
41 | + { | ||
42 | + X: 0, | ||
43 | + Y: 4, | ||
44 | + Length: 5, | ||
45 | + ImageData: "5", | ||
46 | + Direction: domain.DirectionDown, | ||
47 | + }, | ||
48 | + { | ||
49 | + X: 1, | ||
50 | + Y: 1, | ||
51 | + Length: 2, | ||
52 | + ImageData: "a", | ||
53 | + Direction: domain.DirectionDown, | ||
54 | + }, | ||
55 | + { | ||
56 | + X: 1, | ||
57 | + Y: 2, | ||
58 | + Length: 2, | ||
59 | + ImageData: "f", | ||
60 | + Direction: domain.DirectionDown, | ||
61 | + }, | ||
62 | + { | ||
63 | + X: 1, | ||
64 | + Y: 3, | ||
65 | + Length: 2, | ||
66 | + ImageData: "b", | ||
67 | + Direction: domain.DirectionDown, | ||
68 | + }, | ||
69 | + { | ||
70 | + X: 2, | ||
71 | + Y: 0, | ||
72 | + Length: 2, | ||
73 | + ImageData: "e", | ||
74 | + Direction: domain.DirectionDown, | ||
75 | + }, | ||
76 | + { | ||
77 | + X: 2, | ||
78 | + Y: 1, | ||
79 | + Length: 1, | ||
80 | + ImageData: "c", | ||
81 | + Direction: domain.DirectionNone, | ||
82 | + }, | ||
83 | + { | ||
84 | + X: 2, | ||
85 | + Y: 2, | ||
86 | + Length: 1, | ||
87 | + ImageData: "d", | ||
88 | + Direction: domain.DirectionNone, | ||
89 | + }, | ||
90 | + { | ||
91 | + X: 5, | ||
92 | + Y: 0, | ||
93 | + Length: 6, | ||
94 | + ImageData: "g", | ||
95 | + Direction: domain.DirectionDown, | ||
96 | + }, | ||
97 | + }, | ||
98 | + flag: Location{X: 2, Y: 2}, | ||
99 | + }, | ||
100 | + { | ||
101 | + title: "全部无方向", | ||
102 | + cells: []*domain.LayoutCell{ | ||
103 | + { | ||
104 | + X: 0, | ||
105 | + Y: 0, | ||
106 | + Length: 1, | ||
107 | + ImageData: "1", | ||
108 | + Direction: domain.DirectionNone, | ||
109 | + }, | ||
110 | + { | ||
111 | + X: 0, | ||
112 | + Y: 1, | ||
113 | + Length: 1, | ||
114 | + ImageData: "2", | ||
115 | + Direction: domain.DirectionNone, | ||
116 | + }, | ||
117 | + { | ||
118 | + X: 0, | ||
119 | + Y: 2, | ||
120 | + Length: 1, | ||
121 | + ImageData: "3", | ||
122 | + Direction: domain.DirectionNone, | ||
123 | + }, | ||
124 | + { | ||
125 | + X: 1, | ||
126 | + Y: 0, | ||
127 | + Length: 1, | ||
128 | + ImageData: "4", | ||
129 | + Direction: domain.DirectionNone, | ||
130 | + }, | ||
131 | + { | ||
132 | + X: 1, | ||
133 | + Y: 1, | ||
134 | + Length: 1, | ||
135 | + ImageData: "5", | ||
136 | + Direction: domain.DirectionNone, | ||
137 | + }, | ||
138 | + { | ||
139 | + X: 1, | ||
140 | + Y: 2, | ||
141 | + Length: 1, | ||
142 | + ImageData: "6", | ||
143 | + Direction: domain.DirectionNone, | ||
144 | + }, | ||
145 | + { | ||
146 | + X: 2, | ||
147 | + Y: 0, | ||
148 | + Length: 1, | ||
149 | + ImageData: "7", | ||
150 | + Direction: domain.DirectionNone, | ||
151 | + }, | ||
152 | + { | ||
153 | + X: 2, | ||
154 | + Y: 1, | ||
155 | + Length: 1, | ||
156 | + ImageData: "8", | ||
157 | + Direction: domain.DirectionDown, | ||
158 | + }, | ||
159 | + { | ||
160 | + X: 2, | ||
161 | + Y: 2, | ||
162 | + Length: 1, | ||
163 | + ImageData: "9", | ||
164 | + Direction: domain.DirectionNone, | ||
165 | + }, | ||
166 | + }, | ||
167 | + flag: Location{X: 2, Y: 2}, | ||
168 | + }, | ||
169 | + } | ||
170 | + padding := func(cells []*domain.LayoutCell) { | ||
171 | + for _, cell := range cells { | ||
172 | + for i := 0; i < cell.Length; i++ { | ||
173 | + cell.BlockData = append(cell.BlockData, cell.ImageData) | ||
174 | + } | ||
175 | + } | ||
176 | + } | ||
177 | + debugItem := false | ||
178 | + for _, input := range inputs { | ||
179 | + if debugItem && !input.debug { | ||
180 | + continue | ||
181 | + } | ||
182 | + padding(input.cells) | ||
183 | + // 根据数据修改位移 | ||
184 | + CellsLocationAdjust(input.cells) | ||
185 | + // 数据布局 | ||
186 | + res := &domain.DataTable{} | ||
187 | + res, err := DataLayout(res, input.cells) | ||
188 | + if err != nil { | ||
189 | + assert.NoError(t, err) | ||
190 | + } | ||
191 | + printRes(res) | ||
192 | + } | ||
193 | +} |
@@ -75,360 +75,266 @@ func TestDataLayout(t *testing.T) { | @@ -75,360 +75,266 @@ func TestDataLayout(t *testing.T) { | ||
75 | ImageData: "d", | 75 | ImageData: "d", |
76 | Direction: domain.DirectionNone, | 76 | Direction: domain.DirectionNone, |
77 | }, | 77 | }, |
78 | - | ||
79 | - //分组二 右平移10 | ||
80 | - { | ||
81 | - X: 0, | ||
82 | - Y: 10, | ||
83 | - Length: 2, | ||
84 | - ImageData: "2", | ||
85 | - Direction: domain.DirectionRight, | ||
86 | - }, | ||
87 | - { | ||
88 | - X: 0, | ||
89 | - Y: 11, | ||
90 | - Length: 3, | ||
91 | - ImageData: "3", | ||
92 | - Direction: domain.DirectionRight, | ||
93 | - }, | ||
94 | - { | ||
95 | - X: 1, | ||
96 | - Y: 10, | ||
97 | - Length: 2, | ||
98 | - ImageData: "a", | ||
99 | - Direction: domain.DirectionDown, | ||
100 | - }, | ||
101 | - { | ||
102 | - X: 1, | ||
103 | - Y: 11, | ||
104 | - Length: 2, | ||
105 | - ImageData: "f", | ||
106 | - Direction: domain.DirectionDown, | ||
107 | - }, | ||
108 | - { | ||
109 | - X: 1, | ||
110 | - Y: 12, | ||
111 | - Length: 2, | ||
112 | - ImageData: "b", | ||
113 | - Direction: domain.DirectionDown, | ||
114 | - }, | ||
115 | - { | ||
116 | - X: 1, | ||
117 | - Y: 13, | ||
118 | - Length: 2, | ||
119 | - ImageData: "e", | ||
120 | - Direction: domain.DirectionDown, | ||
121 | - }, | ||
122 | - { | ||
123 | - X: 2, | ||
124 | - Y: 10, | ||
125 | - Length: 1, | ||
126 | - ImageData: "c", | ||
127 | - Direction: domain.DirectionNone, | ||
128 | - }, | ||
129 | - { | ||
130 | - X: 2, | ||
131 | - Y: 11, | ||
132 | - Length: 1, | ||
133 | - ImageData: "d", | ||
134 | - Direction: domain.DirectionNone, | ||
135 | - }, | ||
136 | }, | 78 | }, |
137 | flag: Location{X: 2, Y: 2}, | 79 | flag: Location{X: 2, Y: 2}, |
138 | }, | 80 | }, |
139 | - { | ||
140 | - title: "正常多字段横排", | ||
141 | - cells: []*domain.LayoutCell{ | ||
142 | - // 分组一 | ||
143 | - { | ||
144 | - X: 0, | ||
145 | - Y: 0, | ||
146 | - Length: 5, | ||
147 | - ImageData: "a", | ||
148 | - Direction: domain.DirectionRight, | ||
149 | - }, | ||
150 | - { | ||
151 | - X: 1, | ||
152 | - Y: 0, | ||
153 | - Length: 5, | ||
154 | - ImageData: "b", | ||
155 | - Direction: domain.DirectionRight, | ||
156 | - }, | ||
157 | - { | ||
158 | - X: 2, | ||
159 | - Y: 0, | ||
160 | - Length: 5, | ||
161 | - ImageData: "c", | ||
162 | - Direction: domain.DirectionRight, | ||
163 | - }, | ||
164 | - { | ||
165 | - X: 3, | ||
166 | - Y: 0, | ||
167 | - Length: 5, | ||
168 | - ImageData: "d", | ||
169 | - Direction: domain.DirectionRight, | ||
170 | - }, | ||
171 | - | ||
172 | - // 分组二 平移10 | ||
173 | - { | ||
174 | - X: 0, | ||
175 | - Y: 10, | ||
176 | - Length: 5, | ||
177 | - ImageData: "a", | ||
178 | - Direction: domain.DirectionRight, | ||
179 | - }, | ||
180 | - { | ||
181 | - X: 1, | ||
182 | - Y: 10, | ||
183 | - Length: 5, | ||
184 | - ImageData: "b", | ||
185 | - Direction: domain.DirectionRight, | ||
186 | - }, | ||
187 | - { | ||
188 | - X: 2, | ||
189 | - Y: 10, | ||
190 | - Length: 5, | ||
191 | - ImageData: "c", | ||
192 | - Direction: domain.DirectionRight, | ||
193 | - }, | ||
194 | - { | ||
195 | - X: 3, | ||
196 | - Y: 10, | ||
197 | - Length: 5, | ||
198 | - ImageData: "d", | ||
199 | - Direction: domain.DirectionRight, | ||
200 | - }, | ||
201 | - }, | ||
202 | - flag: Location{X: 3, Y: 4}, | ||
203 | - }, | ||
204 | - | ||
205 | - { | ||
206 | - title: "正常多字段横排+计算项目", | ||
207 | - cells: []*domain.LayoutCell{ | ||
208 | - // 分组一 | ||
209 | - { | ||
210 | - X: 0, | ||
211 | - Y: 0, | ||
212 | - Length: 5, | ||
213 | - ImageData: "a", | ||
214 | - Direction: domain.DirectionRight, | ||
215 | - }, | ||
216 | - { | ||
217 | - X: 1, | ||
218 | - Y: 0, | ||
219 | - Length: 5, | ||
220 | - ImageData: "b", | ||
221 | - Direction: domain.DirectionRight, | ||
222 | - }, | ||
223 | - { | ||
224 | - X: 2, | ||
225 | - Y: 0, | ||
226 | - Length: 1, | ||
227 | - ImageData: "c", | ||
228 | - Direction: domain.DirectionNone, | ||
229 | - }, | ||
230 | - { | ||
231 | - X: 3, | ||
232 | - Y: 0, | ||
233 | - Length: 1, | ||
234 | - ImageData: "d", | ||
235 | - Direction: domain.DirectionNone, | ||
236 | - }, | ||
237 | - | ||
238 | - // 分组二 平移10 | ||
239 | - { | ||
240 | - X: 0, | ||
241 | - Y: 10, | ||
242 | - Length: 1, | ||
243 | - ImageData: "a", | ||
244 | - Direction: domain.DirectionRight, | ||
245 | - }, | ||
246 | - { | ||
247 | - X: 1, | ||
248 | - Y: 10, | ||
249 | - Length: 5, | ||
250 | - ImageData: "b", | ||
251 | - Direction: domain.DirectionRight, | ||
252 | - }, | ||
253 | - { | ||
254 | - X: 2, | ||
255 | - Y: 10, | ||
256 | - Length: 1, | ||
257 | - ImageData: "c", | ||
258 | - Direction: domain.DirectionNone, | ||
259 | - }, | ||
260 | - { | ||
261 | - X: 2, | ||
262 | - Y: 11, | ||
263 | - Length: 1, | ||
264 | - ImageData: "e", | ||
265 | - Direction: domain.DirectionNone, | ||
266 | - }, | ||
267 | - { | ||
268 | - X: 3, | ||
269 | - Y: 10, | ||
270 | - Length: 1, | ||
271 | - ImageData: "d", | ||
272 | - Direction: domain.DirectionNone, | ||
273 | - }, | ||
274 | - }, | ||
275 | - flag: Location{X: 2, Y: 1}, | ||
276 | - }, | ||
277 | - | ||
278 | - { | ||
279 | - title: "正常多字段横排+竖排", | ||
280 | - cells: []*domain.LayoutCell{ | ||
281 | - // 分组一 | ||
282 | - { | ||
283 | - X: 0, | ||
284 | - Y: 0, | ||
285 | - Length: 5, | ||
286 | - ImageData: "a", | ||
287 | - Direction: domain.DirectionRight, | ||
288 | - }, | ||
289 | - { | ||
290 | - X: 0, | ||
291 | - Y: 1, | ||
292 | - Length: 5, | ||
293 | - ImageData: "b", | ||
294 | - Direction: domain.DirectionDown, | ||
295 | - }, | ||
296 | - { | ||
297 | - X: 1, | ||
298 | - Y: 0, | ||
299 | - Length: 5, | ||
300 | - ImageData: "c", | ||
301 | - Direction: domain.DirectionRight, | ||
302 | - }, | ||
303 | - { | ||
304 | - X: 2, | ||
305 | - Y: 0, | ||
306 | - Length: 5, | ||
307 | - ImageData: "d", | ||
308 | - Direction: domain.DirectionRight, | ||
309 | - }, | ||
310 | - }, | ||
311 | - flag: Location{X: 2, Y: 1}, | ||
312 | - }, | ||
313 | - | ||
314 | - { | ||
315 | - title: "正常多字段横排(长度不一样)+竖排", | ||
316 | - cells: []*domain.LayoutCell{ | ||
317 | - // 分组一 | ||
318 | - { | ||
319 | - X: 0, | ||
320 | - Y: 0, | ||
321 | - Length: 5, | ||
322 | - ImageData: "a", | ||
323 | - Direction: domain.DirectionRight, | ||
324 | - }, | ||
325 | - { | ||
326 | - X: 0, | ||
327 | - Y: 1, | ||
328 | - Length: 5, | ||
329 | - ImageData: "b", | ||
330 | - Direction: domain.DirectionDown, | ||
331 | - }, | ||
332 | - { | ||
333 | - X: 1, | ||
334 | - Y: 0, | ||
335 | - Length: 6, | ||
336 | - ImageData: "c", | ||
337 | - Direction: domain.DirectionRight, | ||
338 | - }, | ||
339 | - { | ||
340 | - X: 2, | ||
341 | - Y: 0, | ||
342 | - Length: 7, | ||
343 | - ImageData: "d", | ||
344 | - Direction: domain.DirectionRight, | ||
345 | - }, | ||
346 | - }, | ||
347 | - flag: Location{X: 2, Y: 1}, | ||
348 | - }, | ||
349 | - | ||
350 | - { | ||
351 | - title: "测试用例1", | ||
352 | - cells: []*domain.LayoutCell{ | ||
353 | - // 分组一 | ||
354 | - { | ||
355 | - X: 0, | ||
356 | - Y: 0, | ||
357 | - Length: 1, | ||
358 | - ImageData: "a", | ||
359 | - Direction: domain.DirectionNone, | ||
360 | - }, | ||
361 | - { | ||
362 | - X: 0, | ||
363 | - Y: 1, | ||
364 | - Length: 1, | ||
365 | - ImageData: "b", | ||
366 | - Direction: domain.DirectionNone, | ||
367 | - }, | ||
368 | - { | ||
369 | - X: 2, | ||
370 | - Y: 2, | ||
371 | - Length: 5, | ||
372 | - ImageData: "c", | ||
373 | - Direction: domain.DirectionRight, | ||
374 | - }, | ||
375 | - }, | ||
376 | - flag: Location{X: 0, Y: 0}, | ||
377 | - }, | ||
378 | - { | ||
379 | - title: "测试用例3", | ||
380 | - cells: []*domain.LayoutCell{ | ||
381 | - // 分组一 | ||
382 | - { | ||
383 | - X: 0, | ||
384 | - Y: 0, | ||
385 | - Length: 5, | ||
386 | - ImageData: "a", | ||
387 | - Direction: domain.DirectionRight, | ||
388 | - }, | ||
389 | - { | ||
390 | - X: 1, | ||
391 | - Y: 0, | ||
392 | - Length: 5, | ||
393 | - ImageData: "b", | ||
394 | - Direction: domain.DirectionDown, | ||
395 | - }, | ||
396 | - { | ||
397 | - X: 1, | ||
398 | - Y: 1, | ||
399 | - Length: 5, | ||
400 | - ImageData: "c", | ||
401 | - Direction: domain.DirectionRight, | ||
402 | - }, | ||
403 | - { | ||
404 | - X: 2, | ||
405 | - Y: 1, | ||
406 | - Length: 5, | ||
407 | - ImageData: "d", | ||
408 | - Direction: domain.DirectionRight, | ||
409 | - }, | ||
410 | - }, | ||
411 | - flag: Location{X: 2, Y: 1}, | ||
412 | - }, | ||
413 | - { | ||
414 | - title: "测试用例4", | ||
415 | - cells: []*domain.LayoutCell{ | ||
416 | - // 分组一 | ||
417 | - { | ||
418 | - X: 0, | ||
419 | - Y: 0, | ||
420 | - Length: 5, | ||
421 | - ImageData: "a", | ||
422 | - Direction: domain.DirectionDown, | ||
423 | - }, | ||
424 | - { | ||
425 | - X: 0, | ||
426 | - Y: 1, | ||
427 | - Length: 5, | ||
428 | - ImageData: "b", | ||
429 | - Direction: domain.DirectionDown, | ||
430 | - }, | ||
431 | - // , | 81 | + //{ |
82 | + // title: "正常多字段横排", | ||
83 | + // cells: []*domain.LayoutCell{ | ||
84 | + // // 分组一 | ||
85 | + // { | ||
86 | + // X: 0, | ||
87 | + // Y: 0, | ||
88 | + // Length: 5, | ||
89 | + // ImageData: "a", | ||
90 | + // Direction: domain.DirectionRight, | ||
91 | + // }, | ||
92 | + // { | ||
93 | + // X: 1, | ||
94 | + // Y: 0, | ||
95 | + // Length: 5, | ||
96 | + // ImageData: "b", | ||
97 | + // Direction: domain.DirectionRight, | ||
98 | + // }, | ||
99 | + // { | ||
100 | + // X: 2, | ||
101 | + // Y: 0, | ||
102 | + // Length: 5, | ||
103 | + // ImageData: "c", | ||
104 | + // Direction: domain.DirectionRight, | ||
105 | + // }, | ||
106 | + // { | ||
107 | + // X: 3, | ||
108 | + // Y: 0, | ||
109 | + // Length: 5, | ||
110 | + // ImageData: "d", | ||
111 | + // Direction: domain.DirectionRight, | ||
112 | + // }, | ||
113 | + // | ||
114 | + // // 分组二 平移10 | ||
115 | + // { | ||
116 | + // X: 0, | ||
117 | + // Y: 10, | ||
118 | + // Length: 5, | ||
119 | + // ImageData: "a", | ||
120 | + // Direction: domain.DirectionRight, | ||
121 | + // }, | ||
122 | + // { | ||
123 | + // X: 1, | ||
124 | + // Y: 10, | ||
125 | + // Length: 5, | ||
126 | + // ImageData: "b", | ||
127 | + // Direction: domain.DirectionRight, | ||
128 | + // }, | ||
129 | + // { | ||
130 | + // X: 2, | ||
131 | + // Y: 10, | ||
132 | + // Length: 5, | ||
133 | + // ImageData: "c", | ||
134 | + // Direction: domain.DirectionRight, | ||
135 | + // }, | ||
136 | + // { | ||
137 | + // X: 3, | ||
138 | + // Y: 10, | ||
139 | + // Length: 5, | ||
140 | + // ImageData: "d", | ||
141 | + // Direction: domain.DirectionRight, | ||
142 | + // }, | ||
143 | + // }, | ||
144 | + // flag: Location{X: 3, Y: 4}, | ||
145 | + //}, | ||
146 | + // | ||
147 | + //{ | ||
148 | + // title: "正常多字段横排+计算项目", | ||
149 | + // cells: []*domain.LayoutCell{ | ||
150 | + // // 分组一 | ||
151 | + // { | ||
152 | + // X: 0, | ||
153 | + // Y: 0, | ||
154 | + // Length: 5, | ||
155 | + // ImageData: "a", | ||
156 | + // Direction: domain.DirectionRight, | ||
157 | + // }, | ||
158 | + // { | ||
159 | + // X: 1, | ||
160 | + // Y: 0, | ||
161 | + // Length: 5, | ||
162 | + // ImageData: "b", | ||
163 | + // Direction: domain.DirectionRight, | ||
164 | + // }, | ||
165 | + // { | ||
166 | + // X: 2, | ||
167 | + // Y: 0, | ||
168 | + // Length: 1, | ||
169 | + // ImageData: "c", | ||
170 | + // Direction: domain.DirectionNone, | ||
171 | + // }, | ||
172 | + // { | ||
173 | + // X: 3, | ||
174 | + // Y: 0, | ||
175 | + // Length: 1, | ||
176 | + // ImageData: "d", | ||
177 | + // Direction: domain.DirectionNone, | ||
178 | + // }, | ||
179 | + // | ||
180 | + // // 分组二 平移10 | ||
181 | + // { | ||
182 | + // X: 0, | ||
183 | + // Y: 10, | ||
184 | + // Length: 1, | ||
185 | + // ImageData: "a", | ||
186 | + // Direction: domain.DirectionRight, | ||
187 | + // }, | ||
188 | + // { | ||
189 | + // X: 1, | ||
190 | + // Y: 10, | ||
191 | + // Length: 5, | ||
192 | + // ImageData: "b", | ||
193 | + // Direction: domain.DirectionRight, | ||
194 | + // }, | ||
195 | + // { | ||
196 | + // X: 2, | ||
197 | + // Y: 10, | ||
198 | + // Length: 1, | ||
199 | + // ImageData: "c", | ||
200 | + // Direction: domain.DirectionNone, | ||
201 | + // }, | ||
202 | + // { | ||
203 | + // X: 2, | ||
204 | + // Y: 11, | ||
205 | + // Length: 1, | ||
206 | + // ImageData: "e", | ||
207 | + // Direction: domain.DirectionNone, | ||
208 | + // }, | ||
209 | + // { | ||
210 | + // X: 3, | ||
211 | + // Y: 10, | ||
212 | + // Length: 1, | ||
213 | + // ImageData: "d", | ||
214 | + // Direction: domain.DirectionNone, | ||
215 | + // }, | ||
216 | + // }, | ||
217 | + // flag: Location{X: 2, Y: 1}, | ||
218 | + //}, | ||
219 | + // | ||
220 | + //{ | ||
221 | + // title: "正常多字段横排+竖排", | ||
222 | + // cells: []*domain.LayoutCell{ | ||
223 | + // // 分组一 | ||
224 | + // { | ||
225 | + // X: 0, | ||
226 | + // Y: 0, | ||
227 | + // Length: 5, | ||
228 | + // ImageData: "a", | ||
229 | + // Direction: domain.DirectionRight, | ||
230 | + // }, | ||
231 | + // { | ||
232 | + // X: 0, | ||
233 | + // Y: 1, | ||
234 | + // Length: 5, | ||
235 | + // ImageData: "b", | ||
236 | + // Direction: domain.DirectionDown, | ||
237 | + // }, | ||
238 | + // { | ||
239 | + // X: 1, | ||
240 | + // Y: 0, | ||
241 | + // Length: 5, | ||
242 | + // ImageData: "c", | ||
243 | + // Direction: domain.DirectionRight, | ||
244 | + // }, | ||
245 | + // { | ||
246 | + // X: 2, | ||
247 | + // Y: 0, | ||
248 | + // Length: 5, | ||
249 | + // ImageData: "d", | ||
250 | + // Direction: domain.DirectionRight, | ||
251 | + // }, | ||
252 | + // }, | ||
253 | + // flag: Location{X: 2, Y: 1}, | ||
254 | + //}, | ||
255 | + // | ||
256 | + //{ | ||
257 | + // title: "正常多字段横排(长度不一样)+竖排", | ||
258 | + // cells: []*domain.LayoutCell{ | ||
259 | + // // 分组一 | ||
260 | + // { | ||
261 | + // X: 0, | ||
262 | + // Y: 0, | ||
263 | + // Length: 5, | ||
264 | + // ImageData: "a", | ||
265 | + // Direction: domain.DirectionRight, | ||
266 | + // }, | ||
267 | + // { | ||
268 | + // X: 0, | ||
269 | + // Y: 1, | ||
270 | + // Length: 5, | ||
271 | + // ImageData: "b", | ||
272 | + // Direction: domain.DirectionDown, | ||
273 | + // }, | ||
274 | + // { | ||
275 | + // X: 1, | ||
276 | + // Y: 0, | ||
277 | + // Length: 6, | ||
278 | + // ImageData: "c", | ||
279 | + // Direction: domain.DirectionRight, | ||
280 | + // }, | ||
281 | + // { | ||
282 | + // X: 2, | ||
283 | + // Y: 0, | ||
284 | + // Length: 7, | ||
285 | + // ImageData: "d", | ||
286 | + // Direction: domain.DirectionRight, | ||
287 | + // }, | ||
288 | + // }, | ||
289 | + // flag: Location{X: 2, Y: 1}, | ||
290 | + //}, | ||
291 | + // | ||
292 | + //{ | ||
293 | + // title: "测试用例1", | ||
294 | + // cells: []*domain.LayoutCell{ | ||
295 | + // // 分组一 | ||
296 | + // { | ||
297 | + // X: 0, | ||
298 | + // Y: 0, | ||
299 | + // Length: 1, | ||
300 | + // ImageData: "a", | ||
301 | + // Direction: domain.DirectionNone, | ||
302 | + // }, | ||
303 | + // { | ||
304 | + // X: 0, | ||
305 | + // Y: 1, | ||
306 | + // Length: 1, | ||
307 | + // ImageData: "b", | ||
308 | + // Direction: domain.DirectionNone, | ||
309 | + // }, | ||
310 | + // { | ||
311 | + // X: 2, | ||
312 | + // Y: 2, | ||
313 | + // Length: 5, | ||
314 | + // ImageData: "c", | ||
315 | + // Direction: domain.DirectionRight, | ||
316 | + // }, | ||
317 | + // }, | ||
318 | + // flag: Location{X: 0, Y: 0}, | ||
319 | + //}, | ||
320 | + //{ | ||
321 | + // title: "测试用例3", | ||
322 | + // cells: []*domain.LayoutCell{ | ||
323 | + // // 分组一 | ||
324 | + // { | ||
325 | + // X: 0, | ||
326 | + // Y: 0, | ||
327 | + // Length: 5, | ||
328 | + // ImageData: "a", | ||
329 | + // Direction: domain.DirectionRight, | ||
330 | + // }, | ||
331 | + // { | ||
332 | + // X: 1, | ||
333 | + // Y: 0, | ||
334 | + // Length: 5, | ||
335 | + // ImageData: "b", | ||
336 | + // Direction: domain.DirectionDown, | ||
337 | + // }, | ||
432 | // { | 338 | // { |
433 | // X: 1, | 339 | // X: 1, |
434 | // Y: 1, | 340 | // Y: 1, |
@@ -443,42 +349,107 @@ func TestDataLayout(t *testing.T) { | @@ -443,42 +349,107 @@ func TestDataLayout(t *testing.T) { | ||
443 | // ImageData: "d", | 349 | // ImageData: "d", |
444 | // Direction: domain.DirectionRight, | 350 | // Direction: domain.DirectionRight, |
445 | // }, | 351 | // }, |
446 | - }, | ||
447 | - flag: Location{X: 0, Y: 0}, | ||
448 | - }, | ||
449 | - { | ||
450 | - title: "测试用例5", | ||
451 | - cells: []*domain.LayoutCell{ | ||
452 | - // 分组一 | ||
453 | - { | ||
454 | - X: 0, | ||
455 | - Y: 0, | ||
456 | - Length: 5, | ||
457 | - ImageData: "a", | ||
458 | - Direction: domain.DirectionDown, | ||
459 | - }, | ||
460 | - { | ||
461 | - X: 0, | ||
462 | - Y: 1, | ||
463 | - Length: 6, | ||
464 | - ImageData: "b", | ||
465 | - Direction: domain.DirectionDown, | ||
466 | - }, | ||
467 | - { | ||
468 | - X: 1, | ||
469 | - Y: 0, | ||
470 | - Length: 1, | ||
471 | - ImageData: "t", | ||
472 | - Direction: domain.DirectionNone, | ||
473 | - }, | ||
474 | - { | ||
475 | - X: 1, | ||
476 | - Y: 1, | ||
477 | - Length: 1, | ||
478 | - ImageData: "x", | ||
479 | - Direction: domain.DirectionNone, | ||
480 | - }, | ||
481 | - // , | 352 | + // }, |
353 | + // flag: Location{X: 2, Y: 1}, | ||
354 | + //}, | ||
355 | + //{ | ||
356 | + // title: "测试用例4", | ||
357 | + // cells: []*domain.LayoutCell{ | ||
358 | + // // 分组一 | ||
359 | + // { | ||
360 | + // X: 0, | ||
361 | + // Y: 0, | ||
362 | + // Length: 5, | ||
363 | + // ImageData: "a", | ||
364 | + // Direction: domain.DirectionDown, | ||
365 | + // }, | ||
366 | + // { | ||
367 | + // X: 0, | ||
368 | + // Y: 1, | ||
369 | + // Length: 5, | ||
370 | + // ImageData: "b", | ||
371 | + // Direction: domain.DirectionDown, | ||
372 | + // }, | ||
373 | + // // , | ||
374 | + // // { | ||
375 | + // // X: 1, | ||
376 | + // // Y: 1, | ||
377 | + // // Length: 5, | ||
378 | + // // ImageData: "c", | ||
379 | + // // Direction: domain.DirectionRight, | ||
380 | + // // }, | ||
381 | + // // { | ||
382 | + // // X: 2, | ||
383 | + // // Y: 1, | ||
384 | + // // Length: 5, | ||
385 | + // // ImageData: "d", | ||
386 | + // // Direction: domain.DirectionRight, | ||
387 | + // // }, | ||
388 | + // }, | ||
389 | + // flag: Location{X: 0, Y: 0}, | ||
390 | + //}, | ||
391 | + //{ | ||
392 | + // title: "测试用例5", | ||
393 | + // cells: []*domain.LayoutCell{ | ||
394 | + // // 分组一 | ||
395 | + // { | ||
396 | + // X: 0, | ||
397 | + // Y: 0, | ||
398 | + // Length: 5, | ||
399 | + // ImageData: "a", | ||
400 | + // Direction: domain.DirectionDown, | ||
401 | + // }, | ||
402 | + // { | ||
403 | + // X: 0, | ||
404 | + // Y: 1, | ||
405 | + // Length: 6, | ||
406 | + // ImageData: "b", | ||
407 | + // Direction: domain.DirectionDown, | ||
408 | + // }, | ||
409 | + // { | ||
410 | + // X: 1, | ||
411 | + // Y: 0, | ||
412 | + // Length: 1, | ||
413 | + // ImageData: "t", | ||
414 | + // Direction: domain.DirectionNone, | ||
415 | + // }, | ||
416 | + // { | ||
417 | + // X: 1, | ||
418 | + // Y: 1, | ||
419 | + // Length: 1, | ||
420 | + // ImageData: "x", | ||
421 | + // Direction: domain.DirectionNone, | ||
422 | + // }, | ||
423 | + // // , | ||
424 | + // // { | ||
425 | + // // X: 1, | ||
426 | + // // Y: 1, | ||
427 | + // // Length: 5, | ||
428 | + // // ImageData: "c", | ||
429 | + // // Direction: domain.DirectionRight, | ||
430 | + // // }, | ||
431 | + // // { | ||
432 | + // // X: 2, | ||
433 | + // // Y: 1, | ||
434 | + // // Length: 5, | ||
435 | + // // ImageData: "d", | ||
436 | + // // Direction: domain.DirectionRight, | ||
437 | + // // }, | ||
438 | + // }, | ||
439 | + // flag: Location{X: 0, Y: 0}, | ||
440 | + // debug:true, | ||
441 | + //}, | ||
442 | + //{ | ||
443 | + // title: "测试用例6", | ||
444 | + // cells: []*domain.LayoutCell{ | ||
445 | + // // 分组一 | ||
446 | + // { | ||
447 | + // X: 0, | ||
448 | + // Y: 0, | ||
449 | + // Length: 1, | ||
450 | + // ImageData: "a", | ||
451 | + // Direction: domain.DirectionNone, | ||
452 | + // }, | ||
482 | // { | 453 | // { |
483 | // X: 1, | 454 | // X: 1, |
484 | // Y: 1, | 455 | // Y: 1, |
@@ -493,38 +464,9 @@ func TestDataLayout(t *testing.T) { | @@ -493,38 +464,9 @@ func TestDataLayout(t *testing.T) { | ||
493 | // ImageData: "d", | 464 | // ImageData: "d", |
494 | // Direction: domain.DirectionRight, | 465 | // Direction: domain.DirectionRight, |
495 | // }, | 466 | // }, |
496 | - }, | ||
497 | - flag: Location{X: 0, Y: 0}, | ||
498 | - debug:true, | ||
499 | - }, | ||
500 | - { | ||
501 | - title: "测试用例6", | ||
502 | - cells: []*domain.LayoutCell{ | ||
503 | - // 分组一 | ||
504 | - { | ||
505 | - X: 0, | ||
506 | - Y: 0, | ||
507 | - Length: 1, | ||
508 | - ImageData: "a", | ||
509 | - Direction: domain.DirectionNone, | ||
510 | - }, | ||
511 | - { | ||
512 | - X: 1, | ||
513 | - Y: 1, | ||
514 | - Length: 5, | ||
515 | - ImageData: "c", | ||
516 | - Direction: domain.DirectionRight, | ||
517 | - }, | ||
518 | - { | ||
519 | - X: 2, | ||
520 | - Y: 1, | ||
521 | - Length: 5, | ||
522 | - ImageData: "d", | ||
523 | - Direction: domain.DirectionRight, | ||
524 | - }, | ||
525 | - }, | ||
526 | - flag: Location{X: 0, Y: 0}, | ||
527 | - }, | 467 | + // }, |
468 | + // flag: Location{X: 0, Y: 0}, | ||
469 | + //}, | ||
528 | } | 470 | } |
529 | padding := func(cells []*domain.LayoutCell) { | 471 | padding := func(cells []*domain.LayoutCell) { |
530 | for _, cell := range cells { | 472 | for _, cell := range cells { |
@@ -533,9 +475,9 @@ func TestDataLayout(t *testing.T) { | @@ -533,9 +475,9 @@ func TestDataLayout(t *testing.T) { | ||
533 | } | 475 | } |
534 | } | 476 | } |
535 | } | 477 | } |
536 | - debugItem:= false | 478 | + debugItem := false |
537 | for _, input := range inputs { | 479 | for _, input := range inputs { |
538 | - if debugItem && !input.debug{ | 480 | + if debugItem && !input.debug { |
539 | continue | 481 | continue |
540 | } | 482 | } |
541 | padding(input.cells) | 483 | padding(input.cells) |
@@ -41,4 +41,6 @@ type Table struct { | @@ -41,4 +41,6 @@ type Table struct { | ||
41 | Context *domain.Context `comment:"扩展"` | 41 | Context *domain.Context `comment:"扩展"` |
42 | // 表信息 | 42 | // 表信息 |
43 | TableInfo *domain.TableInfo `comment:"表信息"` | 43 | TableInfo *domain.TableInfo `comment:"表信息"` |
44 | + // 应用于的时间 | ||
45 | + ApplyAt time.Time `comment:"应用于的时间"` | ||
44 | } | 46 | } |
@@ -27,5 +27,6 @@ func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain. | @@ -27,5 +27,6 @@ func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain. | ||
27 | RowCount: tableModel.RowCount, | 27 | RowCount: tableModel.RowCount, |
28 | Context: tableModel.Context, | 28 | Context: tableModel.Context, |
29 | TableInfo: tableModel.TableInfo, | 29 | TableInfo: tableModel.TableInfo, |
30 | + ApplyAt: tableModel.ApplyAt, | ||
30 | }, nil | 31 | }, nil |
31 | } | 32 | } |
@@ -33,6 +33,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -33,6 +33,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
33 | "row_count", | 33 | "row_count", |
34 | "context", | 34 | "context", |
35 | "table_info", | 35 | "table_info", |
36 | + "apply_at", | ||
36 | } | 37 | } |
37 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at")) | 38 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at")) |
38 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at")) | 39 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id", "deleted_at")) |
@@ -59,6 +60,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -59,6 +60,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
59 | &table.RowCount, | 60 | &table.RowCount, |
60 | &table.Context, | 61 | &table.Context, |
61 | &table.TableInfo, | 62 | &table.TableInfo, |
63 | + &table.ApplyAt, | ||
62 | ), | 64 | ), |
63 | fmt.Sprintf("INSERT INTO metadata.tables (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 65 | fmt.Sprintf("INSERT INTO metadata.tables (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
64 | table.TableType, | 66 | table.TableType, |
@@ -75,6 +77,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -75,6 +77,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
75 | table.RowCount, | 77 | table.RowCount, |
76 | table.Context, | 78 | table.Context, |
77 | table.TableInfo, | 79 | table.TableInfo, |
80 | + table.ApplyAt, | ||
78 | ); err != nil { | 81 | ); err != nil { |
79 | return table, err | 82 | return table, err |
80 | } | 83 | } |
@@ -99,6 +102,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -99,6 +102,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
99 | &table.RowCount, | 102 | &table.RowCount, |
100 | &table.Context, | 103 | &table.Context, |
101 | &table.TableInfo, | 104 | &table.TableInfo, |
105 | + &table.ApplyAt, | ||
102 | ), | 106 | ), |
103 | fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? and version=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 107 | fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? and version=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
104 | table.TableType, | 108 | table.TableType, |
@@ -115,6 +119,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | @@ -115,6 +119,7 @@ func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, err | ||
115 | table.RowCount, | 119 | table.RowCount, |
116 | table.Context, | 120 | table.Context, |
117 | table.TableInfo, | 121 | table.TableInfo, |
122 | + table.ApplyAt, | ||
118 | table.Identify(), | 123 | table.Identify(), |
119 | oldVersion, | 124 | oldVersion, |
120 | ); err != nil { | 125 | ); err != nil { |
@@ -55,6 +55,7 @@ func init() { | @@ -55,6 +55,7 @@ func init() { | ||
55 | 55 | ||
56 | web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) | 56 | web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) |
57 | web.InsertFilter("/data/*", web.BeforeRouter, middleware.JwtFilter()) | 57 | web.InsertFilter("/data/*", web.BeforeRouter, middleware.JwtFilter()) |
58 | + web.InsertFilter("/api/tables/*", web.BeforeRouter, middleware.JwtFilter()) | ||
58 | web.InsertFilter("/*", web.BeforeRouter, RequestCostBefore()) | 59 | web.InsertFilter("/*", web.BeforeRouter, RequestCostBefore()) |
59 | web.InsertFilter("/*", web.BeforeExec, controllers.BlacklistFilter(controllers.BlacklistRouters)) | 60 | web.InsertFilter("/*", web.BeforeExec, controllers.BlacklistFilter(controllers.BlacklistRouters)) |
60 | web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(true)) // filters.CreateRequstLogFilter(Logger) | 61 | web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(true)) // filters.CreateRequstLogFilter(Logger) |
@@ -146,6 +146,7 @@ func (controller *TableController) SearchQuerySetTables() { | @@ -146,6 +146,7 @@ func (controller *TableController) SearchQuerySetTables() { | ||
146 | domain.SubProcessTable.ToString(), domain.CalculateTable.ToString()} | 146 | domain.SubProcessTable.ToString(), domain.CalculateTable.ToString()} |
147 | } | 147 | } |
148 | cmd.Module = domain.ModuleQuerySetCenter | 148 | cmd.Module = domain.ModuleQuerySetCenter |
149 | + //cmd.CurrentModule = domain.ModuleQuerySetCenter | ||
149 | cmd.ReturnDetailStructInfo = true | 150 | cmd.ReturnDetailStructInfo = true |
150 | cmd.Context = ParseContext(controller.BaseController) | 151 | cmd.Context = ParseContext(controller.BaseController) |
151 | data, err := tableService.Search(cmd) | 152 | data, err := tableService.Search(cmd) |
@@ -160,6 +161,20 @@ func (controller *TableController) TableObjectSearch() { | @@ -160,6 +161,20 @@ func (controller *TableController) TableObjectSearch() { | ||
160 | if cmd.ReturnGroupItem == nil { | 161 | if cmd.ReturnGroupItem == nil { |
161 | cmd.ReturnGroupItem = &defaultReturnGroup | 162 | cmd.ReturnGroupItem = &defaultReturnGroup |
162 | } | 163 | } |
164 | + cmd.CurrentModule = cmd.Module | ||
165 | + cmd.Context = ParseContext(controller.BaseController) | ||
166 | + data, err := tableService.TableObjectSearch(cmd) | ||
167 | + controller.Response(data, err) | ||
168 | +} | ||
169 | + | ||
170 | +func (controller *TableController) ApiTableObjectSearch() { | ||
171 | + tableService := service.NewTableService(nil) | ||
172 | + cmd := &query.SearchTableQuery{} | ||
173 | + Must(controller.Unmarshal(cmd)) | ||
174 | + defaultReturnGroup := true | ||
175 | + if cmd.ReturnGroupItem == nil { | ||
176 | + cmd.ReturnGroupItem = &defaultReturnGroup | ||
177 | + } | ||
163 | cmd.Context = ParseContext(controller.BaseController) | 178 | cmd.Context = ParseContext(controller.BaseController) |
164 | data, err := tableService.TableObjectSearch(cmd) | 179 | data, err := tableService.TableObjectSearch(cmd) |
165 | controller.Response(data, err) | 180 | controller.Response(data, err) |
@@ -45,4 +45,10 @@ func init() { | @@ -45,4 +45,10 @@ func init() { | ||
45 | web.Router("/data/reset-header-row", tableController, "Post:TableResetHeaderRow") | 45 | web.Router("/data/reset-header-row", tableController, "Post:TableResetHeaderRow") |
46 | 46 | ||
47 | web.Router("/data/tables/exec/:name", tableController, "Get:ExecScript") | 47 | web.Router("/data/tables/exec/:name", tableController, "Get:ExecScript") |
48 | + | ||
49 | + // 外部接口 | ||
50 | + web.Router("/api/tables/field-optional-values", tableController, "Post:FieldOptionalValues") | ||
51 | + web.Router("/api/tables/table-object-search", tableController, "Post:ApiTableObjectSearch") | ||
52 | + web.Router("/api/tables/table-preview", tableController, "Post:Preview") | ||
53 | + web.Router("/api/tables/:tableId", tableController, "Get:GetTable") | ||
48 | } | 54 | } |
-
请 注册 或 登录 后发表评论