...
|
...
|
@@ -15,6 +15,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/apilib"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
|
|
|
"os"
|
|
|
"strings"
|
|
|
"time"
|
...
|
...
|
@@ -347,6 +348,134 @@ func (fileService *FileService) AppTableAppendData(ctx *domain.Context, cmd *com |
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
func (fileService *FileService) AppTableAppendDataDirect(ctx *domain.Context, cmd *command.AppTableFileAppendDataCommand) (interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
fileRepository, file, _ := factory.FastPgFile(transactionContext, 0)
|
|
|
file, err = fileRepository.FindOne(map[string]interface{}{"appKey": cmd.AppKey, "fileName": cmd.Name, "fileType": domain.SourceFile})
|
|
|
if err == domain.ErrorNotFound {
|
|
|
return nil, factory.FastError(errors.New("文件不存在"))
|
|
|
}
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
if file.FileInfo.TableId == 0 {
|
|
|
return nil, factory.FastError(errors.New("表不存在"))
|
|
|
}
|
|
|
var (
|
|
|
titles = make([]string, 0)
|
|
|
table *domain.Table
|
|
|
)
|
|
|
_, table, err = factory.FastPgTable(transactionContext, file.FileInfo.TableId)
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
for _, f := range table.Fields(false) {
|
|
|
titles = append(titles, f.Name)
|
|
|
}
|
|
|
mapNameField := domain.Fields(table.Fields(false)).ToMap()
|
|
|
for _, f := range cmd.Fields {
|
|
|
found := false
|
|
|
for _, column := range titles {
|
|
|
if column == f.Name {
|
|
|
found = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !found {
|
|
|
titles = append(titles, f.Name)
|
|
|
}
|
|
|
}
|
|
|
var mapData = make([]map[string]string, 0)
|
|
|
for i := range cmd.Data {
|
|
|
mapItem := make(map[string]string)
|
|
|
for k, v := range cmd.Data[i] {
|
|
|
if f, ok := mapNameField[k]; ok {
|
|
|
mapItem[f.SQLName] = v
|
|
|
}
|
|
|
}
|
|
|
mapData = append(mapData, mapItem)
|
|
|
}
|
|
|
editDataService, _ := factory.CreateTableEditDataService(transactionContext)
|
|
|
_, err = editDataService.BatchAdd(ctx, domain.EditDataRequest{
|
|
|
TableId: table.TableId,
|
|
|
Table: table,
|
|
|
Where: domain.Where{},
|
|
|
UpdateList: nil,
|
|
|
AddList: domainService.MapArrayToFieldValues(mapData, table, nil, false),
|
|
|
RemoveList: nil,
|
|
|
IgnoreTableType: true,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
func (fileService *FileService) AppTableFileList(ctx *domain.Context, cmd *query.ListAppTableFileCommand) (interface{}, error) {
|
|
|
return fileService.GetAppFile(ctx, cmd.AppKey, cmd.Name)
|
|
|
}
|
|
|
|
|
|
func (fileService *FileService) UpdateAppTableFile(ctx *domain.Context, cmd *command.UpdateAppTableFileCommand) (interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
fileRepository, file, _ := factory.FastPgFile(transactionContext, 0)
|
|
|
file, err = fileRepository.FindOne(map[string]interface{}{"appKey": cmd.AppKey, "fileName": cmd.Name, "fileType": domain.SourceFile})
|
|
|
if err == domain.ErrorNotFound {
|
|
|
return nil, factory.FastError(errors.New("文件不存在"))
|
|
|
}
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
if len(cmd.AddFields) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
tableRepository, table, _ := factory.FastPgTable(transactionContext, file.FileInfo.TableId)
|
|
|
if err == domain.ErrorNotFound {
|
|
|
return nil, factory.FastError(errors.New("文件表不存在"))
|
|
|
}
|
|
|
builder := domainService.NewDataFieldsBuilder()
|
|
|
for i, _ := range cmd.AddFields {
|
|
|
if _, ok := table.MatchField(cmd.AddFields[i]); ok {
|
|
|
return nil, factory.FastError(errors.New("字段已存在"))
|
|
|
}
|
|
|
}
|
|
|
for _, f := range cmd.AddFields {
|
|
|
dataField := builder.NewDataField(f.Name, f.SQLType, domain.MainTableField)
|
|
|
table.DataFields = append(table.DataFields, dataField)
|
|
|
if err = starrocks.AddTableColumn(starrocks.DB, table.SQLName, dataField); err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if table, err = tableRepository.Save(table); err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
} |
...
|
...
|
|