作者 yangfu

fix: copy sub table

... ... @@ -154,6 +154,11 @@ type (
MainTable *Table
Table *Table
CopyToTable *Table
// 数据列
//DataFields []*Field `json:"dataFields"`
// 手动添加的列
//ManualFields []*Field `json:"manualFields"`
}
DataCopyTable struct {
... ...
... ... @@ -15,8 +15,8 @@ type ApiByteLib struct {
func NewApiByteLib(host string) *ApiByteLib {
gt := api.NewBaseServiceGateway(host)
gt.ConnectTimeout = 10 * time.Second
gt.ReadWriteTimeout = 10 * time.Second
gt.ConnectTimeout = 360 * time.Second
gt.ReadWriteTimeout = 360 * time.Second
gt.Interceptor = func(msg string) {
//log.Logger.Info(msg)
logs.Debug(msg)
... ...
... ... @@ -255,6 +255,7 @@ type (
ReplicationTableName string `json:"replicationTableName"`
FieldSchemas []FieldSchema `json:"fieldSchemas"`
KeyFieldEnNames []string `json:"keyFieldEnNames"`
ManuallyFieldSchemas []FieldSchema `json:"manuallyFieldSchemas"`
}
CopyTableResponse struct{}
... ... @@ -272,11 +273,13 @@ type (
func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest {
var tableType string
var manuallyFieldSchemas = make([]FieldSchema, 0)
switch param.Table.TableType {
case domain.MainTable.ToString():
tableType = "master"
case domain.SubTable.ToString():
tableType = "split"
manuallyFieldSchemas = ToFieldSchemas(param.Table.ManualFields)
case domain.SideTable.ToString():
tableType = "replication"
}
... ... @@ -284,8 +287,9 @@ func NewCopyTableRequest(param domain.ReqCopyTable) CopyTableRequest {
DatabaseTableName: param.Table.SQLName,
DatabaseTableType: tableType,
ReplicationTableName: param.CopyToTable.SQLName,
FieldSchemas: ToFieldSchemas(param.CopyToTable.DataFields),
FieldSchemas: ToFieldSchemas(param.Table.DataFields),
KeyFieldEnNames: []string{param.Table.PK.SQLName},
ManuallyFieldSchemas: manuallyFieldSchemas,
}
}
... ...
... ... @@ -38,20 +38,19 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
if err != nil {
return nil, err
}
// for i:=range table.ManualFields{
// f:= table.ManualFields[i].Copy()
// f.Flag = domain.MainTableField
// dataFields = append(dataFields,f)
// }
for i := range table.ManualFields {
f := table.ManualFields[i].Copy()
f.Flag = domain.MainTableField
dataFields = append(dataFields, f)
}
}
// 验证表名是否重复
duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName})
if err == nil && duplicateTable != nil {
return nil, fmt.Errorf("表名称重复")
}
sideTable := NewCopyTable(domain.SideTable, tableName,dataFields, table.RowCount).
sideTable := NewCopyTable(domain.SideTable, tableName, dataFields, table.RowCount).
WithContext(ctx).
WithParentId(table.TableId).
WithDataFieldIndex(table.DataFieldIndex)
... ...