作者 yangfu

fix: append data bug

@@ -240,7 +240,7 @@ func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.Exp @@ -240,7 +240,7 @@ func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.Exp
240 }{} 240 }{}
241 if file.FileType == domain.SourceFile.ToString() { 241 if file.FileType == domain.SourceFile.ToString() {
242 response.Url = file.FileInfo.Url 242 response.Url = file.FileInfo.Url
243 - response.Ext = file.FileInfo.Ext 243 + response.Ext = domain.XLSX
244 response.FileName = file.FileInfo.Name 244 response.FileName = file.FileInfo.Name
245 return response, nil 245 return response, nil
246 } 246 }
@@ -268,8 +268,8 @@ func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.Exp @@ -268,8 +268,8 @@ func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.Exp
268 } 268 }
269 269
270 response.Url = domain.DownloadUrl(filename) 270 response.Url = domain.DownloadUrl(filename)
271 - response.FileName = filename  
272 - response.Ext = file.FileInfo.Ext 271 + response.FileName = file.FileInfo.Name
  272 + response.Ext = domain.XLSX
273 273
274 if err := transactionContext.CommitTransaction(); err != nil { 274 if err := transactionContext.CommitTransaction(); err != nil {
275 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 275 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -168,11 +168,12 @@ type ( @@ -168,11 +168,12 @@ type (
168 168
169 type ( 169 type (
170 ReqAppendData struct { 170 ReqAppendData struct {
171 - FileId int  
172 - FileUrl string  
173 - Table *Table  
174 - From []*Field  
175 - To []*Field 171 + FileId int
  172 + FileUrl string
  173 + Table *Table
  174 + From []*Field
  175 + To []*Field
  176 + ExcelTable *Table
176 } 177 }
177 178
178 DataAppendData struct { 179 DataAppendData struct {
@@ -206,11 +206,12 @@ func ToFieldSchemaEnNames(fields []*domain.Field) []string { @@ -206,11 +206,12 @@ func ToFieldSchemaEnNames(fields []*domain.Field) []string {
206 type ( 206 type (
207 TableAppendRequest struct { 207 TableAppendRequest struct {
208 //MasterTableId string `json:"masterTableId"` 208 //MasterTableId string `json:"masterTableId"`
209 - OriginalTableId string `json:"originalTableId"`  
210 - CheckoutTableFileUrl string `json:"checkoutTableFileUrl"`  
211 - DatabaseTableName string `json:"databaseTableName"`  
212 - ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`  
213 - FieldSchemas []FieldSchema `json:"fieldSchemas"` 209 + OriginalTableId string `json:"originalTableId"`
  210 + CheckoutTableFileUrl string `json:"checkoutTableFileUrl"`
  211 + DatabaseTableName string `json:"databaseTableName"`
  212 + ColumnSchemas []domain.ColumnSchema `json:"columnSchemas"`
  213 + FieldSchemas []FieldSchema `json:"fieldSchemas"`
  214 + SchemaMap map[string]domain.ColumnSchema `json:"schemaMap"`
214 } 215 }
215 216
216 MasterTablesAppendRequest struct { 217 MasterTablesAppendRequest struct {
@@ -228,17 +229,24 @@ type ( @@ -228,17 +229,24 @@ type (
228 ) 229 )
229 230
230 func NewTableAppendRequest(param domain.ReqAppendData) TableAppendRequest { 231 func NewTableAppendRequest(param domain.ReqAppendData) TableAppendRequest {
  232 + columnSchemas := DomainFieldsToColumnSchemas(param.From)
231 req := TableAppendRequest{ 233 req := TableAppendRequest{
232 OriginalTableId: intToString(param.FileId), 234 OriginalTableId: intToString(param.FileId),
233 CheckoutTableFileUrl: param.FileUrl, 235 CheckoutTableFileUrl: param.FileUrl,
234 DatabaseTableName: param.Table.SQLName, 236 DatabaseTableName: param.Table.SQLName,
235 - ColumnSchemas: DomainFieldsToColumnSchemas(param.Table.DataFields), 237 + ColumnSchemas: DomainFieldsToColumnSchemas(param.ExcelTable.DataFields),
236 FieldSchemas: ToFieldSchemas(param.Table.DataFields), 238 FieldSchemas: ToFieldSchemas(param.Table.DataFields),
  239 + SchemaMap: make(map[string]domain.ColumnSchema),
237 } 240 }
238 - if len(param.From) > 0 {  
239 - req.ColumnSchemas = DomainFieldsToColumnSchemas(param.From)  
240 - req.FieldSchemas = ToFieldSchemas(param.To) 241 + for i := 0; i < len(param.To); i++ {
  242 + if len(columnSchemas) > i {
  243 + req.SchemaMap[param.To[i].SQLName] = columnSchemas[i]
  244 + }
241 } 245 }
  246 + //if len(param.From) > 0 {
  247 + // req.ColumnSchemas = DomainFieldsToColumnSchemas(param.From)
  248 + // req.FieldSchemas = ToFieldSchemas(param.To)
  249 + //}
242 return req 250 return req
243 } 251 }
244 252
@@ -19,7 +19,6 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int, @@ -19,7 +19,6 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int,
19 if err != nil { 19 if err != nil {
20 return nil, fmt.Errorf("文件不存在") 20 return nil, fmt.Errorf("文件不存在")
21 } 21 }
22 -  
23 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) 22 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
24 table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId}) 23 table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId})
25 if err != nil { 24 if err != nil {
@@ -59,19 +58,23 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int, @@ -59,19 +58,23 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int,
59 } 58 }
60 59
61 // 通知底层进行追加数据 60 // 通知底层进行追加数据
62 - requestData := domain.ReqAppendData{Table: table, FileId: fileId, FileUrl: file.FileInfo.Url} 61 + requestData := domain.ReqAppendData{Table: table, FileId: fileId, FileUrl: file.FileInfo.Url, ExcelTable: excelTable}
63 if len(mappingFields) > 0 { 62 if len(mappingFields) > 0 {
64 for _, m := range mappingFields { 63 for _, m := range mappingFields {
65 - if len(m.VerifiedFileFieldName) == 0 {  
66 - continue  
67 - }  
68 - fromField, ok := excelTable.MatchField(&domain.Field{Name: m.VerifiedFileFieldName}) 64 + var toField, fromField *domain.Field
  65 + var ok bool
  66 + toField, ok = table.MatchField(m.MainTableField)
69 if !ok { 67 if !ok {
70 continue 68 continue
71 } 69 }
72 - toField, ok := table.MatchField(m.MainTableField)  
73 - if !ok {  
74 - continue 70 + if len(m.VerifiedFileFieldName) == 0 {
  71 + fromField = &domain.Field{}
  72 + // continue
  73 + } else {
  74 + fromField, ok = excelTable.MatchField(&domain.Field{Name: m.VerifiedFileFieldName})
  75 + if !ok {
  76 + continue
  77 + }
75 } 78 }
76 requestData.To = append(requestData.To, toField) 79 requestData.To = append(requestData.To, toField)
77 requestData.From = append(requestData.From, fromField) 80 requestData.From = append(requestData.From, fromField)