...
|
...
|
@@ -4,6 +4,7 @@ import ( |
|
|
"fmt"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -12,7 +13,7 @@ type EditDataTableService struct { |
|
|
}
|
|
|
|
|
|
// Edit 表结构编辑 【data-table】
|
|
|
func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableRequest) (interface{}, error) {
|
|
|
func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableRequest) (*domain.DataEditDataTable, error) {
|
|
|
fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
|
|
|
file, err := fileRepository.FindOne(map[string]interface{}{"fileId": req.FileId})
|
|
|
if err != nil {
|
...
|
...
|
@@ -21,20 +22,7 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR |
|
|
if file.FileType != domain.TemporaryFile.ToString() {
|
|
|
return nil, fmt.Errorf("文件未校验")
|
|
|
}
|
|
|
// TODO:操作名映射
|
|
|
var operateName string = req.Action
|
|
|
// 日志
|
|
|
if err = FastLog(ptr.transactionContext, domain.VerifiedStepLog, file.FileId, &ExcelTableEditLog{
|
|
|
LogEntry: domain.NewLogEntry(file.FileInfo.Name, domain.VerifiedFile.ToString(), domain.FileVerify,
|
|
|
ctx.WithValue(domain.ContextWithLogLevel, domain.LevelInfo).
|
|
|
WithValue(domain.ContextWithLogMsg, "")),
|
|
|
ProcessFields: req.ProcessFields,
|
|
|
OperateName: operateName,
|
|
|
}); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 通知底层进行文件表编辑
|
|
|
|
|
|
response, err := ByteCore.EditTable(domain.ReqEditDataTable{
|
|
|
FileId: file.FileId,
|
|
|
PageNumber: req.Where.PageNumber,
|
...
|
...
|
@@ -46,13 +34,77 @@ func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableR |
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
//log.Logger.Error(err.Error())
|
|
|
}
|
|
|
// 处理错误
|
|
|
level := domain.LevelInfo
|
|
|
errMsg := ""
|
|
|
if len(response.InValidCells) > 0 {
|
|
|
level = domain.LevelError
|
|
|
errMsg = response.InValidCells[0].Err
|
|
|
}
|
|
|
|
|
|
// 日志
|
|
|
var operateName string = actionName(req.Action, req.Params)
|
|
|
if err = FastLog(ptr.transactionContext, domain.VerifiedStepLog, file.FileId, &ExcelTableEditLog{
|
|
|
LogEntry: domain.NewLogEntry(file.FileInfo.Name, domain.VerifiedFile.ToString(), domain.FileVerify,
|
|
|
ctx.WithValue(domain.ContextWithLogLevel, level).
|
|
|
WithValue(domain.ContextWithLogMsg, errMsg)),
|
|
|
ProcessFields: req.ProcessFields,
|
|
|
OperateName: operateName,
|
|
|
}); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 1.有修改表类型的,更新缓存数据列类型
|
|
|
if response != nil && len(response.Fields) > 0 {
|
|
|
// 特殊处理修改类型错误
|
|
|
options := make([]redis.FileCacheOptionsFunc, 0)
|
|
|
if req.Action == "convert-column-type" {
|
|
|
var toType = req.Params["convertType"].(string)
|
|
|
var fieldName = req.ProcessFieldNames[0]
|
|
|
if level == domain.LevelError {
|
|
|
options = append(options, redis.WithAddConvertTypeErrors([]redis.ConvertTypeError{{FieldName: fieldName, ErrMsg: errMsg, ToType: toType}}))
|
|
|
} else {
|
|
|
options = append(options, redis.WithRemoveConvertTypeErrors([]redis.ConvertTypeError{{FieldName: fieldName, ErrMsg: errMsg, ToType: toType}}))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cacheService := redis.NewFileCacheService()
|
|
|
if _, err := cacheService.Update(redis.KeyTemporaryFileInfo(file.FileId), file, response.Fields, response.Total, options...); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
return response, nil
|
|
|
}
|
|
|
|
|
|
func actionName(action string, params map[string]interface{}) string {
|
|
|
if v, ok := domain.MapActionCommon[action]; ok {
|
|
|
return v.Desc
|
|
|
}
|
|
|
if params != nil {
|
|
|
switch action {
|
|
|
case domain.FormatColumn:
|
|
|
if v, ok := domain.MapActionFormat[params["formatMethod"].(string)]; ok {
|
|
|
return v.Desc
|
|
|
}
|
|
|
case domain.SplitColumn:
|
|
|
if v, ok := domain.MapActionSplitColumn[params["splitMethod"].(string)]; ok {
|
|
|
return v.Desc
|
|
|
}
|
|
|
case domain.ExtractColumn:
|
|
|
if v, ok := domain.MapActionExtractColumn[params["extractMethod"].(string)]; ok {
|
|
|
return v.Desc
|
|
|
}
|
|
|
case domain.ReplaceColumn:
|
|
|
if v, ok := domain.MapActionReplaceColumn[params["replaceMethod"].(string)]; ok {
|
|
|
return v.Desc
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return action
|
|
|
}
|
|
|
|
|
|
func NewEditDataTableService(transactionContext *pgTransaction.TransactionContext) (*EditDataTableService, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
...
|
...
|
|