作者 yangfu

fix: row data edit

... ... @@ -28,6 +28,21 @@ func (cmd *RowEditCommandV2) Valid(validation *validation.Validation) {
}
}
func (cmd *RowEditCommandV2) IdList() []interface{} {
ids := make([]interface{}, 0)
for _, m := range cmd.UpdateList {
if v, ok := m[domain.DefaultPkField]; ok {
ids = append(ids, v)
}
}
for _, m := range cmd.RemoveList {
if v, ok := m[domain.DefaultPkField]; ok {
ids = append(ids, v)
}
}
return ids
}
func (cmd *RowEditCommandV2) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
)
... ... @@ -56,10 +57,23 @@ func (tableService *TableService) RowEditV2(ctx *domain.Context, cmd *command.Ro
var options = starrocks.QueryOptions{
TableName: table.SQLName,
Select: table.Fields(true),
Where: []starrocks.Condition{},
}
options.SetCondition(cmd.Where.Conditions).SetDefaultOrder()
options.SetOffsetLimit(cmd.Where.PageNumber, cmd.Where.PageSize)
var dataTable *domain.DataTable
var idList = cmd.IdList()
if len(idList) > 0 {
options.Where = append(options.Where, starrocks.Condition{
Condition: domain.Condition{
Field: domainService.PK(),
In: cmd.IdList(),
},
})
options.SetCondition(cmd.Where.Conditions).SetDefaultOrder()
options.SetOffsetLimit(0, 2000)
} else {
options.SetOffsetLimit(0, 1)
}
dataTable, err = factory.FastDataTable(options)
if err != nil {
return nil, factory.FastError(err)
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
)
type TableEditDataService struct {
... ... @@ -38,7 +39,9 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi
}
for _, l := range request.AddList {
ptr.add(ctx, table, l, request.Where)
if addErr := ptr.add(ctx, table, l, request.Where); addErr != nil {
log.Logger.Error(addErr.Error())
}
}
if len(request.RemoveList) > 0 {
// 日志
... ... @@ -49,11 +52,15 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi
return nil, err
}
for _, l := range request.RemoveList {
ptr.remove(ctx, table, l, request.Where)
if e := ptr.remove(ctx, table, l, request.Where); e != nil {
log.Logger.Error(e.Error())
}
}
}
for _, l := range request.UpdateList {
ptr.update(ctx, table, l, request.Where)
if e := ptr.update(ctx, table, l, request.Where); e != nil {
log.Logger.Error(e.Error())
}
}
return nil, nil
... ...