正在显示
21 个修改的文件
包含
459 行增加
和
6 行删除
@@ -9,7 +9,7 @@ HTTP_PORT = 8081 | @@ -9,7 +9,7 @@ HTTP_PORT = 8081 | ||
9 | ENABLE_KAFKA_LOG11 = true | 9 | ENABLE_KAFKA_LOG11 = true |
10 | HTTPS_PORT = 8143 | 10 | HTTPS_PORT = 8143 |
11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com | 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
12 | -# AUTH_SERVER_HOST = http://127.0.0.1:8081 | 12 | +# AUTH_SERVER_HOST = http://127.0.0.1:8081 192.168.100.9:8303 |
13 | BYTE_CORE_HOST = http://47.97.5.102:8303 | 13 | BYTE_CORE_HOST = http://47.97.5.102:8303 |
14 | METADATA_BASTION_HOST = http://106.75.231.90:9999 | 14 | METADATA_BASTION_HOST = http://106.75.231.90:9999 |
15 | 15 | ||
@@ -22,7 +22,8 @@ STARROCKS_DB_NAME = character_library | @@ -22,7 +22,8 @@ STARROCKS_DB_NAME = character_library | ||
22 | STARROCKS_USER = root | 22 | STARROCKS_USER = root |
23 | STARROCKS_PASSWORD = eagle1010 | 23 | STARROCKS_PASSWORD = eagle1010 |
24 | STARROCKS_HOST = 220.250.41.79 | 24 | STARROCKS_HOST = 220.250.41.79 |
25 | -STARROCKS_PORT = 9030 | 25 | +#9030 |
26 | +STARROCKS_PORT = 9430 | ||
26 | 27 | ||
27 | BLACK_LIST_USER = 0 | 28 | BLACK_LIST_USER = 0 |
28 | BLACK_LIST_COMPANY = 1612991734952759296 | 29 | BLACK_LIST_COMPANY = 1612991734952759296 |
@@ -108,7 +108,7 @@ spec: | @@ -108,7 +108,7 @@ spec: | ||
108 | - name: STARROCKS_HOST | 108 | - name: STARROCKS_HOST |
109 | value: "220.250.41.79" | 109 | value: "220.250.41.79" |
110 | - name: STARROCKS_PORT | 110 | - name: STARROCKS_PORT |
111 | - value: "9030" | 111 | + value: "9430" |
112 | - name: STARROCKS_DB_NAME | 112 | - name: STARROCKS_DB_NAME |
113 | value: "character_library_standard" | 113 | value: "character_library_standard" |
114 | - name: STARROCKS_USER | 114 | - name: STARROCKS_USER |
@@ -106,7 +106,7 @@ spec: | @@ -106,7 +106,7 @@ spec: | ||
106 | - name: STARROCKS_HOST | 106 | - name: STARROCKS_HOST |
107 | value: "220.250.41.79" | 107 | value: "220.250.41.79" |
108 | - name: STARROCKS_PORT | 108 | - name: STARROCKS_PORT |
109 | - value: "9030" | 109 | + value: "9430" |
110 | - name: STARROCKS_DB_NAME | 110 | - name: STARROCKS_DB_NAME |
111 | value: "character_library" | 111 | value: "character_library" |
112 | - name: STARROCKS_USER | 112 | - name: STARROCKS_USER |
1 | +package command | ||
2 | + | ||
3 | +type GenerateBusinessTableRequest struct { | ||
4 | + TableName string `json:"tableRemarkName"` | ||
5 | + TableFullName string `json:"tableSqlName"` | ||
6 | + Fields []FieldSchemas `json:"fields"` | ||
7 | + ShowTableNameBy int `json:"showTableNameBy"` // 展示表名 0:原表名 1:表名备注 | ||
8 | + ShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 字段名在字库的显示 0:字段原名 1:字段备注 | ||
9 | +} |
1 | +package command | ||
2 | + | ||
3 | +type UpdateBusinessTableRequest struct { | ||
4 | + TableName string `json:"tableRemarkName"` | ||
5 | + TableFullName string `json:"tableFullName"` | ||
6 | + Fields []FieldSchemas `json:"fields"` | ||
7 | + ShowTableNameBy int `json:"showTableNameBy"` // 展示表名 0:原表名 1:表名备注 | ||
8 | + ShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 字段名在字库的显示 0:字段原名 1:字段备注 | ||
9 | +} | ||
10 | + | ||
11 | +type FieldSchemas struct { | ||
12 | + FieldEnName string `json:"fieldEnName"` | ||
13 | + FieldType string `json:"fieldType"` | ||
14 | + FieldZhName string `json:"fieldZhName"` | ||
15 | +} |
pkg/application/table/query/show_tables.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
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/command" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" | ||
13 | + "strings" | ||
14 | +) | ||
15 | + | ||
16 | +func (tableService *TableService) ShowBusinessDatabases(ctx *domain.Context, cmd *query.ShowBusinessDatabasesRequest) (interface{}, error) { | ||
17 | + byteCoreService := domainService.ByteCoreService{} | ||
18 | + response, err := byteCoreService.ShowBusinessDatabases(bytelib.ReqShowBusinessDatabases{}) | ||
19 | + if err != nil { | ||
20 | + return nil, factory.FastError(err) | ||
21 | + } | ||
22 | + return response, err | ||
23 | +} | ||
24 | + | ||
25 | +func (tableService *TableService) ShowBusinessTables(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) { | ||
26 | + byteCoreService := domainService.ByteCoreService{} | ||
27 | + response, err := byteCoreService.ShowBusinessTables(bytelib.ReqShowBusinessTables{ | ||
28 | + DatabaseEnName: cmd.DatabaseEnName, | ||
29 | + DatabaseType: cmd.DatabaseType, | ||
30 | + }) | ||
31 | + if err != nil { | ||
32 | + return nil, factory.FastError(err) | ||
33 | + } | ||
34 | + result := make([]map[string]interface{}, 0) | ||
35 | + for _, t := range response.TableFullNames { | ||
36 | + result = append(result, map[string]interface{}{ | ||
37 | + "name": t, | ||
38 | + }) | ||
39 | + } | ||
40 | + return map[string]interface{}{ | ||
41 | + "list": result, | ||
42 | + }, err | ||
43 | +} | ||
44 | + | ||
45 | +func (tableService *TableService) QueryBusinessTable(ctx *domain.Context, cmd *query.ShowTableDataRequest) (interface{}, error) { | ||
46 | + byteCoreService := domainService.ByteCoreService{} | ||
47 | + response, err := byteCoreService.QueryBusinessTable(bytelib.ReqQueryBusinessTable{ | ||
48 | + TableFullName: cmd.TableFullName, | ||
49 | + PageNumber: cmd.PageNumber - 1, // 分页从0开始 | ||
50 | + PageSize: cmd.PageSize, | ||
51 | + }) | ||
52 | + if err != nil { | ||
53 | + return nil, factory.FastError(err) | ||
54 | + } | ||
55 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
56 | + if err != nil { | ||
57 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
58 | + } | ||
59 | + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) | ||
60 | + table, _ := tableRepository.FindBusinessTable(constant.COMPANY_SU_TIAN_XIA, response.TableFullName) | ||
61 | + if table != nil { | ||
62 | + response.TableRemarkName = table.Name | ||
63 | + response.ShowTableNameBy = table.TableInfo.BusinessTableShowTableNameBy | ||
64 | + response.ShowTableFieldNameBy = table.TableInfo.BusinessTableShowTableFieldNameBy | ||
65 | + for i, f := range response.FieldSchemas { | ||
66 | + for j, jf := range table.DataFields { | ||
67 | + if jf.SQLName == f.FieldEnName { | ||
68 | + response.FieldSchemas[i].FieldZhName = table.DataFields[j].Name | ||
69 | + } | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + } | ||
74 | + return response, err | ||
75 | +} | ||
76 | + | ||
77 | +func (tableService *TableService) UpdateBusinessTable(ctx *domain.Context, cmd *command.UpdateBusinessTableRequest) (interface{}, error) { | ||
78 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
79 | + if err != nil { | ||
80 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
81 | + } | ||
82 | + if err := transactionContext.StartTransaction(); err != nil { | ||
83 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
84 | + } | ||
85 | + defer func() { | ||
86 | + transactionContext.RollbackTransaction() | ||
87 | + }() | ||
88 | + var tableRepository domain.TableRepository | ||
89 | + if value, err := factory.CreateTableRepository(map[string]interface{}{ | ||
90 | + "transactionContext": transactionContext, | ||
91 | + }); err != nil { | ||
92 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
93 | + } else { | ||
94 | + tableRepository = value | ||
95 | + } | ||
96 | + | ||
97 | + ctx.CompanyId = int(constant.COMPANY_SU_TIAN_XIA) | ||
98 | + | ||
99 | + var ( | ||
100 | + fields = make([]*domain.Field, 0) | ||
101 | + mainTable *domain.Table | ||
102 | + ) | ||
103 | + for i, f := range cmd.Fields { | ||
104 | + fields = append(fields, &domain.Field{ | ||
105 | + Index: i + 1, | ||
106 | + Name: f.FieldZhName, | ||
107 | + SQLName: f.FieldEnName, | ||
108 | + SQLType: f.FieldType, //TODO:类型转换 | ||
109 | + Flag: domain.MainTableField, | ||
110 | + }) | ||
111 | + } | ||
112 | + table, _ := tableRepository.FindBusinessTable(constant.COMPANY_SU_TIAN_XIA, cmd.TableFullName) | ||
113 | + if table == nil { | ||
114 | + mainTable = domainService.NewTable(domain.BusinessTable, cmd.TableName, fields, 0). | ||
115 | + WithContext(ctx). | ||
116 | + WithPrefix(domain.BusinessTable.ToString()) | ||
117 | + mainTable.SQLName = cmd.TableFullName | ||
118 | + mainTable.DataFields = fields | ||
119 | + mainTable.TableInfo.BusinessTableShowTableNameBy = cmd.ShowTableNameBy | ||
120 | + mainTable.TableInfo.BusinessTableShowTableFieldNameBy = cmd.ShowTableFieldNameBy | ||
121 | + mainTable.TableInfo.TableFrom = 1 | ||
122 | + | ||
123 | + if mainTable, err = tableRepository.Save(mainTable); err != nil { | ||
124 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
125 | + } | ||
126 | + } else { | ||
127 | + table.Name = cmd.TableName | ||
128 | + table.DataFields = fields | ||
129 | + table.TableInfo.BusinessTableShowTableNameBy = cmd.ShowTableNameBy | ||
130 | + table.TableInfo.BusinessTableShowTableFieldNameBy = cmd.ShowTableFieldNameBy | ||
131 | + if table, err = tableRepository.Save(table); err != nil { | ||
132 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
137 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
138 | + } | ||
139 | + return mainTable, nil | ||
140 | +} | ||
141 | + | ||
142 | +func (tableService *TableService) GenerateBusinessTable(ctx *domain.Context, cmd *command.GenerateBusinessTableRequest) (interface{}, error) { | ||
143 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
144 | + if err != nil { | ||
145 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
146 | + } | ||
147 | + if err := transactionContext.StartTransaction(); err != nil { | ||
148 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
149 | + } | ||
150 | + defer func() { | ||
151 | + transactionContext.RollbackTransaction() | ||
152 | + }() | ||
153 | + var tableRepository domain.TableRepository | ||
154 | + if value, err := factory.CreateTableRepository(map[string]interface{}{ | ||
155 | + "transactionContext": transactionContext, | ||
156 | + }); err != nil { | ||
157 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
158 | + } else { | ||
159 | + tableRepository = value | ||
160 | + } | ||
161 | + ctx.CompanyId = int(constant.COMPANY_SU_TIAN_XIA) | ||
162 | + | ||
163 | + duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": cmd.TableName, | ||
164 | + "tableTypes": []string{string(domain.MainTable), string(domain.SubTable), string(domain.SideTable)}}) | ||
165 | + if err == nil && duplicateTable != nil { | ||
166 | + return nil, factory.FastError(fmt.Errorf("表名称重复")) | ||
167 | + } | ||
168 | + | ||
169 | + var ( | ||
170 | + fields = make([]*domain.Field, 0) | ||
171 | + mainTable *domain.Table | ||
172 | + hasPkField bool | ||
173 | + ) | ||
174 | + for i, f := range cmd.Fields { | ||
175 | + if strings.ToLower(f.FieldEnName) == "id" { | ||
176 | + hasPkField = true | ||
177 | + continue | ||
178 | + } | ||
179 | + var filedName = f.FieldZhName | ||
180 | + // 使用备注名 | ||
181 | + if cmd.ShowTableFieldNameBy == 0 { | ||
182 | + filedName = f.FieldEnName | ||
183 | + } | ||
184 | + // 字段为空时显示原字段名 | ||
185 | + if cmd.ShowTableFieldNameBy == 1 && filedName == "" { | ||
186 | + filedName = f.FieldEnName | ||
187 | + } | ||
188 | + fields = append(fields, &domain.Field{ | ||
189 | + Index: i + 1, | ||
190 | + Name: filedName, | ||
191 | + SQLName: f.FieldEnName, | ||
192 | + SQLType: f.FieldType, //TODO:类型转换 | ||
193 | + Flag: domain.MainTableField, | ||
194 | + }) | ||
195 | + } | ||
196 | + if !hasPkField { | ||
197 | + return nil, factory.FastError(fmt.Errorf("业务表未包含字段 `id`")) | ||
198 | + } | ||
199 | + var tableName = cmd.TableName | ||
200 | + if cmd.ShowTableNameBy == 0 { | ||
201 | + tableName = cmd.TableFullName | ||
202 | + } | ||
203 | + mainTable = domainService.NewTable(domain.MainTable, tableName, fields, 0). | ||
204 | + WithContext(ctx). | ||
205 | + WithPrefix(domain.MainTable.ToString()).ApplyDefaultModule() | ||
206 | + mainTable.SQLName = cmd.TableFullName | ||
207 | + mainTable.TableInfo.TableFrom = 1 | ||
208 | + mainTable.DataFields = fields | ||
209 | + if mainTable, err = tableRepository.Save(mainTable); err != nil { | ||
210 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
211 | + } | ||
212 | + | ||
213 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
214 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
215 | + } | ||
216 | + return nil, nil | ||
217 | +} |
@@ -31,6 +31,8 @@ var BLACK_LIST_USER int64 | @@ -31,6 +31,8 @@ var BLACK_LIST_USER int64 | ||
31 | var BLACK_LIST_COMPANY int64 | 31 | var BLACK_LIST_COMPANY int64 |
32 | var WHITE_LIST_USERS []int | 32 | var WHITE_LIST_USERS []int |
33 | 33 | ||
34 | +var COMPANY_SU_TIAN_XIA int64 = 1689162984523304960 | ||
35 | + | ||
34 | func init() { | 36 | func init() { |
35 | LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) | 37 | LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) |
36 | MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) | 38 | MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) |
@@ -47,6 +49,8 @@ func init() { | @@ -47,6 +49,8 @@ func init() { | ||
47 | BLACK_LIST_COMPANY = Configurator.DefaultInt64("BLACK_LIST_COMPANY", BLACK_LIST_COMPANY) | 49 | BLACK_LIST_COMPANY = Configurator.DefaultInt64("BLACK_LIST_COMPANY", BLACK_LIST_COMPANY) |
48 | DIGITAL_SERVER_HOST = Configurator.DefaultString("DIGITAL_SERVER_HOST", DIGITAL_SERVER_HOST) | 50 | DIGITAL_SERVER_HOST = Configurator.DefaultString("DIGITAL_SERVER_HOST", DIGITAL_SERVER_HOST) |
49 | 51 | ||
52 | + COMPANY_SU_TIAN_XIA = Configurator.DefaultInt64("COMPANY_SU_TIAN_XIA", COMPANY_SU_TIAN_XIA) | ||
53 | + | ||
50 | whiteListUsers := strings.Split(Configurator.DefaultString("WHITE_LIST_USERS", ""), ",") | 54 | whiteListUsers := strings.Split(Configurator.DefaultString("WHITE_LIST_USERS", ""), ",") |
51 | for _, userId := range whiteListUsers { | 55 | for _, userId := range whiteListUsers { |
52 | v, _ := strconv.Atoi(userId) | 56 | v, _ := strconv.Atoi(userId) |
@@ -104,6 +104,7 @@ var ( | @@ -104,6 +104,7 @@ var ( | ||
104 | SubTable TableType = "SubTable" | 104 | SubTable TableType = "SubTable" |
105 | ExcelTable TableType = "ExcelTable" | 105 | ExcelTable TableType = "ExcelTable" |
106 | TemporaryTable TableType = "TemporaryTable" | 106 | TemporaryTable TableType = "TemporaryTable" |
107 | + BusinessTable TableType = "BusinessTable" // 业务表 | ||
107 | ) | 108 | ) |
108 | 109 | ||
109 | var ( | 110 | var ( |
@@ -55,6 +55,7 @@ type TableRepository interface { | @@ -55,6 +55,7 @@ type TableRepository interface { | ||
55 | Save(table *Table) (*Table, error) | 55 | Save(table *Table) (*Table, error) |
56 | Remove(table *Table) (*Table, error) | 56 | Remove(table *Table) (*Table, error) |
57 | FindOne(queryOptions map[string]interface{}) (*Table, error) | 57 | FindOne(queryOptions map[string]interface{}) (*Table, error) |
58 | + FindBusinessTable(companyId int64, sqlName string) (*Table, error) | ||
58 | Find(queryOptions map[string]interface{}) (int64, []*Table, error) | 59 | Find(queryOptions map[string]interface{}) (int64, []*Table, error) |
59 | } | 60 | } |
60 | 61 | ||
@@ -109,6 +110,14 @@ func (table *Table) WithParentId(parentId int) *Table { | @@ -109,6 +110,14 @@ func (table *Table) WithParentId(parentId int) *Table { | ||
109 | return table | 110 | return table |
110 | } | 111 | } |
111 | 112 | ||
113 | +func (table *Table) WithTableInfo(t *Table) *Table { | ||
114 | + if t.TableInfo == nil { | ||
115 | + return table | ||
116 | + } | ||
117 | + table.TableInfo.TableFrom = t.TableInfo.TableFrom | ||
118 | + return table | ||
119 | +} | ||
120 | + | ||
112 | func (table *Table) WithDataFieldIndex(dataFieldIndex int) *Table { | 121 | func (table *Table) WithDataFieldIndex(dataFieldIndex int) *Table { |
113 | table.DataFieldIndex = dataFieldIndex | 122 | table.DataFieldIndex = dataFieldIndex |
114 | return table | 123 | return table |
@@ -5,6 +5,10 @@ type TableInfo struct { | @@ -5,6 +5,10 @@ type TableInfo struct { | ||
5 | ApplyOnModule int `json:"module"` | 5 | ApplyOnModule int `json:"module"` |
6 | // 依赖关联的表 | 6 | // 依赖关联的表 |
7 | DependencyTables []int `json:"dependencyTables"` | 7 | DependencyTables []int `json:"dependencyTables"` |
8 | + // 表来源 | ||
9 | + TableFrom int `json:"tableFrom"` // 0:字库导入 1:字库实表同步 | ||
10 | + BusinessTableShowTableNameBy int `json:"showTableNameBy"` // 【业务表】展示表名 0:原表名 1:表名备注 | ||
11 | + BusinessTableShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 【业务表】字段名在字库的显示 0:字段原名 1:字段备注 | ||
8 | } | 12 | } |
9 | 13 | ||
10 | func (t *TableInfo) SetApplyOn(applyOn int) *TableInfo { | 14 | func (t *TableInfo) SetApplyOn(applyOn int) *TableInfo { |
@@ -278,3 +278,36 @@ func (gateway ApiByteLib) FormulasClear(param domain.ReqFormulasClear) (*domain. | @@ -278,3 +278,36 @@ func (gateway ApiByteLib) FormulasClear(param domain.ReqFormulasClear) (*domain. | ||
278 | var response = domain.DataFormulasClear{} | 278 | var response = domain.DataFormulasClear{} |
279 | return &response, nil | 279 | return &response, nil |
280 | } | 280 | } |
281 | + | ||
282 | +func (gateway ApiByteLib) ShowBusinessDatabases(request ReqShowBusinessDatabases) (*DataShowBusinessDatabases, error) { | ||
283 | + url := gateway.Host() + "/databases/show-business-databases" | ||
284 | + method := "post" | ||
285 | + var data DataShowBusinessDatabases | ||
286 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
287 | + if err != nil { | ||
288 | + return nil, err | ||
289 | + } | ||
290 | + return &data, nil | ||
291 | +} | ||
292 | + | ||
293 | +func (gateway ApiByteLib) ShowBusinessTables(request ReqShowBusinessTables) (*DataShowBusinessTables, error) { | ||
294 | + url := gateway.Host() + "/databases/show-tables" | ||
295 | + method := "post" | ||
296 | + var data DataShowBusinessTables | ||
297 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
298 | + if err != nil { | ||
299 | + return nil, err | ||
300 | + } | ||
301 | + return &data, nil | ||
302 | +} | ||
303 | + | ||
304 | +func (gateway ApiByteLib) QueryBusinessTable(request ReqQueryBusinessTable) (*DataQueryBusinessTable, error) { | ||
305 | + url := gateway.Host() + "/databases/query-table" | ||
306 | + method := "post" | ||
307 | + var data DataQueryBusinessTable | ||
308 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
309 | + if err != nil { | ||
310 | + return nil, err | ||
311 | + } | ||
312 | + return &data, nil | ||
313 | +} |
@@ -332,3 +332,49 @@ type ( | @@ -332,3 +332,49 @@ type ( | ||
332 | FormulasClearResponse struct { | 332 | FormulasClearResponse struct { |
333 | } | 333 | } |
334 | ) | 334 | ) |
335 | + | ||
336 | +type ( | ||
337 | + ReqShowBusinessDatabases struct { | ||
338 | + } | ||
339 | + DataShowBusinessDatabases struct { | ||
340 | + BusinessDatabases []struct { | ||
341 | + DatabaseDescription string `json:"databaseDescription"` | ||
342 | + DatabaseEnName string `json:"databaseEnName"` | ||
343 | + DatabaseType string `json:"databaseType"` | ||
344 | + DatabaseZhName string `json:"databaseZhName"` | ||
345 | + } `json:"businessDatabases"` | ||
346 | + } | ||
347 | +) | ||
348 | + | ||
349 | +type ( | ||
350 | + ReqShowBusinessTables struct { | ||
351 | + DatabaseEnName string `json:"databaseEnName"` | ||
352 | + DatabaseType string `json:"databaseType"` | ||
353 | + } | ||
354 | + DataShowBusinessTables struct { | ||
355 | + TableFullNames []string `json:"tableFullNames"` | ||
356 | + } | ||
357 | +) | ||
358 | + | ||
359 | +type ( | ||
360 | + ReqQueryBusinessTable struct { | ||
361 | + TableFullName string `json:"tableFullName"` | ||
362 | + PageNumber int `json:"pageNumber"` | ||
363 | + PageSize int `json:"pageSize"` | ||
364 | + } | ||
365 | + DataQueryBusinessTable struct { | ||
366 | + DataCount int `json:"dataCount"` | ||
367 | + FieldSchemas []struct { | ||
368 | + FieldDescription string `json:"fieldDescription"` | ||
369 | + FieldEnName string `json:"fieldEnName"` | ||
370 | + FieldType string `json:"fieldType"` | ||
371 | + FieldZhName string `json:"fieldZhName"` | ||
372 | + IsAllowNull bool `json:"isAllowNull"` | ||
373 | + } `json:"fieldSchemas"` | ||
374 | + ShowData [][]string `json:"showData"` | ||
375 | + TableFullName string `json:"tableFullName"` | ||
376 | + TableRemarkName string `json:"tableRemarkName"` | ||
377 | + ShowTableNameBy int `json:"showTableNameBy"` // 展示表名 0:原表名 1:表名备注 | ||
378 | + ShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 字段名在字库的显示 0:字段原名 1:字段备注 | ||
379 | + } | ||
380 | +) |
@@ -170,6 +170,21 @@ func (ptr *ByteCoreService) FormulasClear(param domain.ReqFormulasClear) (*domai | @@ -170,6 +170,21 @@ func (ptr *ByteCoreService) FormulasClear(param domain.ReqFormulasClear) (*domai | ||
170 | return apiByteLib.FormulasClear(param) | 170 | return apiByteLib.FormulasClear(param) |
171 | } | 171 | } |
172 | 172 | ||
173 | +func (ptr *ByteCoreService) ShowBusinessDatabases(param bytelib.ReqShowBusinessDatabases) (*bytelib.DataShowBusinessDatabases, error) { | ||
174 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
175 | + return apiByteLib.ShowBusinessDatabases(param) | ||
176 | +} | ||
177 | + | ||
178 | +func (ptr *ByteCoreService) ShowBusinessTables(param bytelib.ReqShowBusinessTables) (*bytelib.DataShowBusinessTables, error) { | ||
179 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
180 | + return apiByteLib.ShowBusinessTables(param) | ||
181 | +} | ||
182 | + | ||
183 | +func (ptr *ByteCoreService) QueryBusinessTable(param bytelib.ReqQueryBusinessTable) (*bytelib.DataQueryBusinessTable, error) { | ||
184 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
185 | + return apiByteLib.QueryBusinessTable(param) | ||
186 | +} | ||
187 | + | ||
173 | func (ptr *ByteCoreService) ExcelExprCalcPersistence(expr *domain.FieldFormulaExpr, param domain.ReqFormulasGenerate, persistence bool) error { | 188 | func (ptr *ByteCoreService) ExcelExprCalcPersistence(expr *domain.FieldFormulaExpr, param domain.ReqFormulasGenerate, persistence bool) error { |
174 | if len(param.QueryComponents) == 0 { | 189 | if len(param.QueryComponents) == 0 { |
175 | return nil | 190 | return nil |
@@ -45,7 +45,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl | @@ -45,7 +45,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl | ||
45 | fields = MappingFieldsV2(mainTable, fields) | 45 | fields = MappingFieldsV2(mainTable, fields) |
46 | dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.MainTableField}) | 46 | dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.MainTableField}) |
47 | manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.ManualField}) | 47 | manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.ManualField}) |
48 | - table := NewTable(domain.SubTable, name, fields, mainTable.RowCount).WithContext(ctx).WithPrefix(string(domain.SubTable)) | 48 | + table := NewTable(domain.SubTable, name, fields, mainTable.RowCount).WithContext(ctx).WithPrefix(string(domain.SubTable)).WithTableInfo(mainTable) |
49 | table.DataFieldIndex = mainTable.DataFieldIndex | 49 | table.DataFieldIndex = mainTable.DataFieldIndex |
50 | table.DataFields = dataFields | 50 | table.DataFields = dataFields |
51 | table.ManualFields = manualFields | 51 | table.ManualFields = manualFields |
@@ -55,7 +55,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab | @@ -55,7 +55,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab | ||
55 | WithContext(ctx). | 55 | WithContext(ctx). |
56 | WithParentId(table.TableId). | 56 | WithParentId(table.TableId). |
57 | WithDataFieldIndex(table.DataFieldIndex). | 57 | WithDataFieldIndex(table.DataFieldIndex). |
58 | - WithPrefix(domain.SideTable.ToString()) | 58 | + WithPrefix(domain.SideTable.ToString()). |
59 | + WithTableInfo(table) | ||
59 | if sideTable, err = tableRepository.Save(sideTable); err != nil { | 60 | if sideTable, err = tableRepository.Save(sideTable); err != nil { |
60 | return nil, err | 61 | return nil, err |
61 | } | 62 | } |
@@ -165,6 +165,28 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) | @@ -165,6 +165,28 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) | ||
165 | return transform.TransformToTableDomainModelFromPgModels(tableModel) | 165 | return transform.TransformToTableDomainModelFromPgModels(tableModel) |
166 | } | 166 | } |
167 | } | 167 | } |
168 | + | ||
169 | +func (repository *TableRepository) FindBusinessTable(companyId int64, sqlName string) (*domain.Table, error) { | ||
170 | + tx := repository.transactionContext.DB() | ||
171 | + tableModel := new(models.Table) | ||
172 | + query := sqlbuilder.BuildQuery(tx.Model(tableModel), nil) | ||
173 | + query.Where("context->'companyId'='?'", companyId) | ||
174 | + query.Where("sql_name = ?", sqlName) | ||
175 | + query.Where("table_type = ?", domain.BusinessTable.ToString()) | ||
176 | + if err := query.First(); err != nil { | ||
177 | + if err.Error() == "pg: no rows in result set" { | ||
178 | + return nil, domain.ErrorNotFound | ||
179 | + } else { | ||
180 | + return nil, err | ||
181 | + } | ||
182 | + } | ||
183 | + if tableModel.TableId == 0 { | ||
184 | + return nil, nil | ||
185 | + } else { | ||
186 | + return transform.TransformToTableDomainModelFromPgModels(tableModel) | ||
187 | + } | ||
188 | +} | ||
189 | + | ||
168 | func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) { | 190 | func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) { |
169 | tx := repository.transactionContext.DB() | 191 | tx := repository.transactionContext.DB() |
170 | var tableModels []*models.Table | 192 | var tableModels []*models.Table |
@@ -177,6 +199,9 @@ func (repository *TableRepository) Find(queryOptions map[string]interface{}) (in | @@ -177,6 +199,9 @@ func (repository *TableRepository) Find(queryOptions map[string]interface{}) (in | ||
177 | if v, ok := queryOptions["tableIds"]; ok && len(v.([]int)) > 0 { | 199 | if v, ok := queryOptions["tableIds"]; ok && len(v.([]int)) > 0 { |
178 | query.Where(`table_id in (?)`, pg.In(v.([]int))) | 200 | query.Where(`table_id in (?)`, pg.In(v.([]int))) |
179 | } | 201 | } |
202 | + if v, ok := queryOptions["sqlNames"]; ok && len(v.([]string)) > 0 { | ||
203 | + query.Where(`sql_name in (?)`, pg.In(v.([]string))) | ||
204 | + } | ||
180 | if v, ok := queryOptions["tableTypes"]; ok && len(v.([]string)) > 0 { | 205 | if v, ok := queryOptions["tableTypes"]; ok && len(v.([]string)) > 0 { |
181 | query.Where(`table_type in (?)`, pg.In(v.([]string))) | 206 | query.Where(`table_type in (?)`, pg.In(v.([]string))) |
182 | } | 207 | } |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service" | ||
7 | +) | ||
8 | + | ||
9 | +func (controller *TableController) ShowBusinessDatabases() { | ||
10 | + tableService := service.NewTableService(nil) | ||
11 | + cmd := &query.ShowBusinessDatabasesRequest{} | ||
12 | + Must(controller.Unmarshal(cmd)) | ||
13 | + data, err := tableService.ShowBusinessDatabases(ParseContext(controller.BaseController), cmd) | ||
14 | + controller.Response(data, err) | ||
15 | +} | ||
16 | + | ||
17 | +func (controller *TableController) ShowBusinessTables() { | ||
18 | + tableService := service.NewTableService(nil) | ||
19 | + cmd := &query.ShowTablesRequest{} | ||
20 | + Must(controller.Unmarshal(cmd)) | ||
21 | + data, err := tableService.ShowBusinessTables(ParseContext(controller.BaseController), cmd) | ||
22 | + controller.Response(data, err) | ||
23 | +} | ||
24 | + | ||
25 | +func (controller *TableController) QueryBusinessTable() { | ||
26 | + tableService := service.NewTableService(nil) | ||
27 | + cmd := &query.ShowTableDataRequest{} | ||
28 | + Must(controller.Unmarshal(cmd)) | ||
29 | + data, err := tableService.QueryBusinessTable(ParseContext(controller.BaseController), cmd) | ||
30 | + controller.Response(data, err) | ||
31 | +} | ||
32 | + | ||
33 | +func (controller *TableController) UpdateBusinessTable() { | ||
34 | + tableService := service.NewTableService(nil) | ||
35 | + cmd := &command.UpdateBusinessTableRequest{} | ||
36 | + Must(controller.Unmarshal(cmd)) | ||
37 | + data, err := tableService.UpdateBusinessTable(ParseContext(controller.BaseController), cmd) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *TableController) GenerateBusinessTable() { | ||
42 | + tableService := service.NewTableService(nil) | ||
43 | + cmd := &command.GenerateBusinessTableRequest{} | ||
44 | + Must(controller.Unmarshal(cmd)) | ||
45 | + data, err := tableService.GenerateBusinessTable(ParseContext(controller.BaseController), cmd) | ||
46 | + controller.Response(data, err) | ||
47 | +} |
@@ -13,4 +13,10 @@ func init() { | @@ -13,4 +13,10 @@ func init() { | ||
13 | web.Router("/api/app-table-file/append-data", &controllers.FileController{}, "Post:AppendDataAppTableFile") | 13 | web.Router("/api/app-table-file/append-data", &controllers.FileController{}, "Post:AppendDataAppTableFile") |
14 | web.Router("/api/app-table-file/list", &controllers.FileController{}, "Post:ListAppTableFile") | 14 | web.Router("/api/app-table-file/list", &controllers.FileController{}, "Post:ListAppTableFile") |
15 | web.Router("/api/app-table-file/update", &controllers.FileController{}, "Post:UpdateAppTableFile") | 15 | web.Router("/api/app-table-file/update", &controllers.FileController{}, "Post:UpdateAppTableFile") |
16 | + | ||
17 | + web.Router("/api/business-table/show-business-databases", &controllers.TableController{}, "Post:ShowBusinessDatabases") | ||
18 | + web.Router("/api/business-table/show-tables", &controllers.TableController{}, "Post:ShowBusinessTables") | ||
19 | + web.Router("/api/business-table/query-table", &controllers.TableController{}, "Post:QueryBusinessTable") | ||
20 | + web.Router("/api/business-table/update", &controllers.TableController{}, "Post:UpdateBusinessTable") | ||
21 | + web.Router("/api/business-table/generate", &controllers.TableController{}, "Post:GenerateBusinessTable") | ||
16 | } | 22 | } |
-
请 注册 或 登录 后发表评论