作者 yangfu

fix: append data bug

... ... @@ -240,7 +240,7 @@ func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.Exp
}{}
if file.FileType == domain.SourceFile.ToString() {
response.Url = file.FileInfo.Url
response.Ext = file.FileInfo.Ext
response.Ext = domain.XLSX
response.FileName = file.FileInfo.Name
return response, nil
}
... ... @@ -268,8 +268,8 @@ func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.Exp
}
response.Url = domain.DownloadUrl(filename)
response.FileName = filename
response.Ext = file.FileInfo.Ext
response.FileName = file.FileInfo.Name
response.Ext = domain.XLSX
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -168,11 +168,12 @@ type (
type (
ReqAppendData struct {
FileId int
FileUrl string
Table *Table
From []*Field
To []*Field
FileId int
FileUrl string
Table *Table
From []*Field
To []*Field
ExcelTable *Table
}
DataAppendData struct {
... ...
... ... @@ -206,11 +206,12 @@ func ToFieldSchemaEnNames(fields []*domain.Field) []string {
type (
TableAppendRequest struct {
//MasterTableId string `json:"masterTableId"`
OriginalTableId string `json:"originalTableId"`
CheckoutTableFileUrl string `json:"checkoutTableFileUrl"`
DatabaseTableName string `json:"databaseTableName"`
ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
FieldSchemas []FieldSchema `json:"fieldSchemas"`
OriginalTableId string `json:"originalTableId"`
CheckoutTableFileUrl string `json:"checkoutTableFileUrl"`
DatabaseTableName string `json:"databaseTableName"`
ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
FieldSchemas []FieldSchema `json:"fieldSchemas"`
SchemaMap map[string]domain.ColumnSchema `json:"schemaMap"`
}
MasterTablesAppendRequest struct {
... ... @@ -228,17 +229,24 @@ type (
)
func NewTableAppendRequest(param domain.ReqAppendData) TableAppendRequest {
columnSchemas := DomainFieldsToColumnSchemas(param.From)
req := TableAppendRequest{
OriginalTableId: intToString(param.FileId),
CheckoutTableFileUrl: param.FileUrl,
DatabaseTableName: param.Table.SQLName,
ColumnSchemas: DomainFieldsToColumnSchemas(param.Table.DataFields),
ColumnSchemas: DomainFieldsToColumnSchemas(param.ExcelTable.DataFields),
FieldSchemas: ToFieldSchemas(param.Table.DataFields),
SchemaMap: make(map[string]domain.ColumnSchema),
}
if len(param.From) > 0 {
req.ColumnSchemas = DomainFieldsToColumnSchemas(param.From)
req.FieldSchemas = ToFieldSchemas(param.To)
for i := 0; i < len(param.To); i++ {
if len(columnSchemas) > i {
req.SchemaMap[param.To[i].SQLName] = columnSchemas[i]
}
}
//if len(param.From) > 0 {
// req.ColumnSchemas = DomainFieldsToColumnSchemas(param.From)
// req.FieldSchemas = ToFieldSchemas(param.To)
//}
return req
}
... ...
... ... @@ -19,7 +19,6 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int,
if err != nil {
return nil, fmt.Errorf("文件不存在")
}
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId})
if err != nil {
... ... @@ -59,19 +58,23 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int,
}
// 通知底层进行追加数据
requestData := domain.ReqAppendData{Table: table, FileId: fileId, FileUrl: file.FileInfo.Url}
requestData := domain.ReqAppendData{Table: table, FileId: fileId, FileUrl: file.FileInfo.Url, ExcelTable: excelTable}
if len(mappingFields) > 0 {
for _, m := range mappingFields {
if len(m.VerifiedFileFieldName) == 0 {
continue
}
fromField, ok := excelTable.MatchField(&domain.Field{Name: m.VerifiedFileFieldName})
var toField, fromField *domain.Field
var ok bool
toField, ok = table.MatchField(m.MainTableField)
if !ok {
continue
}
toField, ok := table.MatchField(m.MainTableField)
if !ok {
continue
if len(m.VerifiedFileFieldName) == 0 {
fromField = &domain.Field{}
// continue
} else {
fromField, ok = excelTable.MatchField(&domain.Field{Name: m.VerifiedFileFieldName})
if !ok {
continue
}
}
requestData.To = append(requestData.To, toField)
requestData.From = append(requestData.From, fromField)
... ...