log_opt_service.go 1.2 KB
package log_opt

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/utils/tool_funs"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/log_opt/command"
)

type LogOptService struct {
}

func NewLogOptService() *LogOptService {
	newRoleService := &LogOptService{}
	return newRoleService
}

func (rs *LogOptService) List(in *command.QueryLogCommand) (interface{}, error) {
	transactionContext, err := factory.ValidateStartTransaction(in)
	if err != nil {
		return nil, err
	}
	defer func() {
		transactionContext.RollbackTransaction()
	}()

	ssMap := tool_funs.SimpleStructToMap(in)
	ssMap["companyId"] = in.CompanyId
	ssMap["optTargetId"] = in.TaskId

	logRepository := factory.CreateLogOptRepository(map[string]interface{}{"transactionContext": transactionContext})
	total, logList, err := logRepository.Find(ssMap)
	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 tool_funs.SimpleWrapGridMap(total, logList), nil
}