fast_domain_repository.go 7.6 KB
package factory

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

// FastPgUser  快速返回领域用户
//
// transactionContext 事务
// userId  用户ID
func FastPgUser(transactionContext application.TransactionContext, userId int64) (domain.UserRepository, *domain.User, error) {
	var rep domain.UserRepository
	var mod *domain.User
	var err error
	if value, err := CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if userId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"userId": userId}); 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
}

// FastPgUser  快速返回领域用户基础
//
// transactionContext 事务
// userBaseId  用户基础ID
func FastPgUserBase(transactionContext application.TransactionContext, userBaseId int64) (domain.UserBaseRepository, *domain.UserBase, error) {
	var rep domain.UserBaseRepository
	var mod *domain.UserBase
	var err error
	if value, err := CreateUserBaseRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if userBaseId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"userBaseId": userBaseId}); 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
}

// FastPgRole  快速返回领域角色
//
// transactionContext 事务
// roleId  角色Id
func FastPgRole(transactionContext application.TransactionContext, roleId int64) (domain.RoleRepository, *domain.Role, error) {
	var rep domain.RoleRepository
	var mod *domain.Role
	var err error
	if value, err := CreateRoleRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if roleId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"roleId": roleId}); 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
}

// FastPgRole  快速返回领域组织
//
// transactionContext 事务
// orgId  组织Id
func FastPgOrg(transactionContext application.TransactionContext, orgId int64) (domain.OrgRepository, *domain.Org, error) {
	var rep domain.OrgRepository
	var mod *domain.Org
	var err error
	if value, err := CreateOrgRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if orgId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"orgId": orgId}); 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
}

// FastPgCompany  快速返回领域公司
//
// transactionContext 事务
// companyId  公司Id
func FastPgCompany(transactionContext application.TransactionContext, companyId int64) (domain.CompanyRepository, *domain.Company, error) {
	var rep domain.CompanyRepository
	var mod *domain.Company
	var err error
	if value, err := CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if companyId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"companyId": companyId}); 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
}

// FastPgMenu  快速返回领域菜单
//
// transactionContext 事务
// menuId  菜单Id
func FastPgMenu(transactionContext application.TransactionContext, menuId int64) (domain.MenuRepository, *domain.Menu, error) {
	var rep domain.MenuRepository
	var mod *domain.Menu
	var err error
	if value, err := CreateMenuRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if menuId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"menuId": menuId}); 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
}

// FastPgCustomizeMenu  快速返回领域自定义菜单
//
// transactionContext 事务
// customizeMenuId  自定义菜单Id
func FastPgCustomizeMenu(transactionContext application.TransactionContext, customizeMenuId int64) (domain.CustomizeMenuRepository, *domain.CustomizeMenu, error) {
	var rep domain.CustomizeMenuRepository
	var mod *domain.CustomizeMenu
	var err error
	if value, err := CreateCustomizeMenuRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if customizeMenuId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"customizeMenuId": customizeMenuId}); 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
}

// FastPgAccountDestroyRecord  快速返回领域账号注销记录
//
// transactionContext 事务
// accountDestroyRecordId  账号注销记录Id
func FastPgAccountDestroyRecord(transactionContext application.TransactionContext, accountDestroyRecordId int64) (domain.AccountDestroyRecordRepository, *domain.AccountDestroyRecord, error) {
	var rep domain.AccountDestroyRecordRepository
	var mod *domain.AccountDestroyRecord
	var err error
	if value, err := CreateAccountDestroyRecordRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		rep = value
	}
	if accountDestroyRecordId > 0 {
		if mod, err = rep.FindOne(map[string]interface{}{"accountDestroyRecord": accountDestroyRecordId}); 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
}

func FastPgDataAuth(transactionContext application.TransactionContext, operateInfo *domain.OperateInfo) error {
	return nil
}