fast_domain_repository.go 3.8 KB
package factory

import (
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
)

// FastPgFile  快速返回文件对象
//
// transactionContext 事务
// id  对象唯一标识
func FastPgFile(transactionContext application.TransactionContext, id int) (domain.FileRepository, *domain.File, error) {
	var rep domain.FileRepository
	var mod *domain.File
	var err error
	if value, err := CreateFileRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if id > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"fileId": id}); err != nil {
			if err == domain.ErrorNotFound {
				return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该文件不存在")
			}
			return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
		}
	}
	//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
	//	return nil, nil, err
	//}
	return rep, mod, err
}

// FastPgTable  快速返回表格对象
//
// transactionContext 事务
// id  对象唯一标识
func FastPgTable(transactionContext application.TransactionContext, id int) (domain.TableRepository, *domain.Table, error) {
	var rep domain.TableRepository
	var mod *domain.Table
	var err error
	if value, err := CreateTableRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if id > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"tableId": id}); err != nil {
			if err == domain.ErrorNotFound {
				return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该表格不存在")
			}
			return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
		}
	}
	return rep, mod, err
}

// FastPgLog  快速返回日志对象
//
// transactionContext 事务
// id  对象唯一标识
func FastPgLog(transactionContext application.TransactionContext, id int) (domain.LogRepository, *domain.Log, error) {
	var rep domain.LogRepository
	var mod *domain.Log
	var err error
	if value, err := CreateLogRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if id > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"logId": id}); err != nil {
			if err == domain.ErrorNotFound {
				return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该日志不存在")
			}
			return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
		}
	}
	return rep, mod, err
}

// FastPgMappingRule  快速返回匹配规则对象
//
// transactionContext 事务
// id  对象唯一标识
func FastPgMappingRule(transactionContext application.TransactionContext, id int) (domain.MappingRuleRepository, *domain.MappingRule, error) {
	var rep domain.MappingRuleRepository
	var mod *domain.MappingRule
	var err error
	if value, err := CreateMappingRuleRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if id > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"mappingRuleId": id}); err != nil {
			if err == domain.ErrorNotFound {
				return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该匹配规则不存在")
			}
			return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
		}
	}
	return rep, mod, err
}