作者 yangfu

fix: copy sub table

@@ -154,6 +154,11 @@ type ( @@ -154,6 +154,11 @@ type (
154 MainTable *Table 154 MainTable *Table
155 Table *Table 155 Table *Table
156 CopyToTable *Table 156 CopyToTable *Table
  157 +
  158 + // 数据列
  159 + //DataFields []*Field `json:"dataFields"`
  160 + // 手动添加的列
  161 + //ManualFields []*Field `json:"manualFields"`
157 } 162 }
158 163
159 DataCopyTable struct { 164 DataCopyTable struct {
@@ -15,8 +15,8 @@ type ApiByteLib struct { @@ -15,8 +15,8 @@ type ApiByteLib struct {
15 15
16 func NewApiByteLib(host string) *ApiByteLib { 16 func NewApiByteLib(host string) *ApiByteLib {
17 gt := api.NewBaseServiceGateway(host) 17 gt := api.NewBaseServiceGateway(host)
18 - gt.ConnectTimeout = 10 * time.Second  
19 - gt.ReadWriteTimeout = 10 * time.Second 18 + gt.ConnectTimeout = 360 * time.Second
  19 + gt.ReadWriteTimeout = 360 * time.Second
20 gt.Interceptor = func(msg string) { 20 gt.Interceptor = func(msg string) {
21 //log.Logger.Info(msg) 21 //log.Logger.Info(msg)
22 logs.Debug(msg) 22 logs.Debug(msg)
@@ -255,6 +255,7 @@ type ( @@ -255,6 +255,7 @@ type (
255 ReplicationTableName string `json:"replicationTableName"` 255 ReplicationTableName string `json:"replicationTableName"`
256 FieldSchemas []FieldSchema `json:"fieldSchemas"` 256 FieldSchemas []FieldSchema `json:"fieldSchemas"`
257 KeyFieldEnNames []string `json:"keyFieldEnNames"` 257 KeyFieldEnNames []string `json:"keyFieldEnNames"`
  258 + ManuallyFieldSchemas []FieldSchema `json:"manuallyFieldSchemas"`
258 } 259 }
259 260
260 CopyTableResponse struct{} 261 CopyTableResponse struct{}
@@ -272,11 +273,13 @@ type ( @@ -272,11 +273,13 @@ type (
272 273
273 func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest { 274 func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest {
274 var tableType string 275 var tableType string
  276 + var manuallyFieldSchemas = make([]FieldSchema, 0)
275 switch param.Table.TableType { 277 switch param.Table.TableType {
276 case domain.MainTable.ToString(): 278 case domain.MainTable.ToString():
277 tableType = "master" 279 tableType = "master"
278 case domain.SubTable.ToString(): 280 case domain.SubTable.ToString():
279 tableType = "split" 281 tableType = "split"
  282 + manuallyFieldSchemas = ToFieldSchemas(param.Table.ManualFields)
280 case domain.SideTable.ToString(): 283 case domain.SideTable.ToString():
281 tableType = "replication" 284 tableType = "replication"
282 } 285 }
@@ -284,8 +287,9 @@ func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest { @@ -284,8 +287,9 @@ func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest {
284 DatabaseTableName: param.Table.SQLName, 287 DatabaseTableName: param.Table.SQLName,
285 DatabaseTableType: tableType, 288 DatabaseTableType: tableType,
286 ReplicationTableName: param.CopyToTable.SQLName, 289 ReplicationTableName: param.CopyToTable.SQLName,
287 - FieldSchemas: ToFieldSchemas(param.CopyToTable.DataFields), 290 + FieldSchemas: ToFieldSchemas(param.Table.DataFields),
288 KeyFieldEnNames: []string{param.Table.PK.SQLName}, 291 KeyFieldEnNames: []string{param.Table.PK.SQLName},
  292 + ManuallyFieldSchemas: manuallyFieldSchemas,
289 } 293 }
290 } 294 }
291 295
@@ -38,20 +38,19 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab @@ -38,20 +38,19 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
38 if err != nil { 38 if err != nil {
39 return nil, err 39 return nil, err
40 } 40 }
41 - // for i:=range table.ManualFields{  
42 - // f:= table.ManualFields[i].Copy()  
43 - // f.Flag = domain.MainTableField  
44 - // dataFields = append(dataFields,f)  
45 - // } 41 + for i := range table.ManualFields {
  42 + f := table.ManualFields[i].Copy()
  43 + f.Flag = domain.MainTableField
  44 + dataFields = append(dataFields, f)
  45 + }
46 } 46 }
47 // 验证表名是否重复 47 // 验证表名是否重复
48 duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName}) 48 duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName})
49 if err == nil && duplicateTable != nil { 49 if err == nil && duplicateTable != nil {
50 return nil, fmt.Errorf("表名称重复") 50 return nil, fmt.Errorf("表名称重复")
51 } 51 }
52 -  
53 52
54 - sideTable := NewCopyTable(domain.SideTable, tableName,dataFields, table.RowCount). 53 + sideTable := NewCopyTable(domain.SideTable, tableName, dataFields, table.RowCount).
55 WithContext(ctx). 54 WithContext(ctx).
56 WithParentId(table.TableId). 55 WithParentId(table.TableId).
57 WithDataFieldIndex(table.DataFieldIndex) 56 WithDataFieldIndex(table.DataFieldIndex)