file_table_edit_data_table_service.go 2.0 KB
package domainService

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/repository"
)

type EditDataTableService struct {
	transactionContext *pgTransaction.TransactionContext
}

// Edit 表结构编辑  【data-table】
func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableRequest) (interface{}, error) {
	fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
	file, err := fileRepository.FindOne(map[string]interface{}{"fileId": req.FileId})
	if err != nil {
		return nil, fmt.Errorf("文件不存在")
	}
	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),
		ProcessFields: req.ProcessFields,
		OperateName:   operateName,
	}); err != nil {
		return nil, err
	}
	// 通知底层进行文件表编辑

	response, err := ByteCore.EditTable(domain.ReqEditDataTable{
		FileId:        file.FileId,
		PageNumber:    req.Where.PageNumber,
		PageSize:      req.Where.PageSize,
		Fields:        domain.ToFields(req.Fields),
		ProcessFields: domain.ToFields(req.ProcessFields),
		Action:        req.Action,
		Params:        req.Params,
	})
	if err != nil {
		return nil, err
	}

	return response, nil
}

func NewEditDataTableService(transactionContext *pgTransaction.TransactionContext) (*EditDataTableService, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &EditDataTableService{
			transactionContext: transactionContext,
		}, nil
	}
}