permission.go 1.7 KB
package service

import (
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)

//AdminUserService 管理员相关服务
type AdminPermissionService struct {
}

func NewAdminPermissionService(option map[string]interface{}) *AdminPermissionService {
	newAdminPermissionService := new(AdminPermissionService)
	return newAdminPermissionService
}

func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption query.ListAdminPermissionQuery) ([]domain.AdminPermission, error) {
	//实际业务
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		transactionContext.RollbackTransaction()
	}()
	var (
		permissionRepository domain.AdminPermissionRepository
		permissions          []domain.AdminPermission
	)
	if value, err := factory.CreateAdminPermissionRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
	} else {
		permissionRepository = value
	}
	permissions, err = permissionRepository.Find(domain.AdminPermissionFindQuery{
		NotCode:  queryOption.NotCode,
		ParentId: queryOption.ParentId,
	})
	if err != nil {
		return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
	}
	return permissions, nil
}