mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 00:10:25 +08:00 
			
		
		
		
	refactor: 组件升级、代码优化
This commit is contained in:
		
							
								
								
									
										64
									
								
								server/internal/machine/application/auth_cert.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								server/internal/machine/application/auth_cert.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/domain/entity"
 | 
			
		||||
	"mayfly-go/internal/machine/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/model"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type AuthCert interface {
 | 
			
		||||
	GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
			
		||||
 | 
			
		||||
	Save(ac *entity.AuthCert)
 | 
			
		||||
 | 
			
		||||
	GetById(id uint64) *entity.AuthCert
 | 
			
		||||
 | 
			
		||||
	GetByIds(ids ...uint64) []*entity.AuthCert
 | 
			
		||||
 | 
			
		||||
	DeleteById(id uint64)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newAuthCertApp(authCertRepo repository.AuthCert) AuthCert {
 | 
			
		||||
	return &authCertAppImpl{
 | 
			
		||||
		authCertRepo: authCertRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type authCertAppImpl struct {
 | 
			
		||||
	authCertRepo repository.AuthCert
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
			
		||||
	return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *authCertAppImpl) Save(ac *entity.AuthCert) {
 | 
			
		||||
	oldAc := &entity.AuthCert{Name: ac.Name}
 | 
			
		||||
	err := a.authCertRepo.GetByCondition(oldAc, "Id", "Name")
 | 
			
		||||
 | 
			
		||||
	ac.PwdEncrypt()
 | 
			
		||||
	if ac.Id == 0 {
 | 
			
		||||
		biz.IsTrue(err != nil, "该凭证名已存在")
 | 
			
		||||
		a.authCertRepo.Insert(ac)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 如果存在该库,则校验修改的库是否为该库
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		biz.IsTrue(oldAc.Id == ac.Id, "该凭证名已存在")
 | 
			
		||||
	}
 | 
			
		||||
	a.authCertRepo.Update(ac)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *authCertAppImpl) GetById(id uint64) *entity.AuthCert {
 | 
			
		||||
	return a.authCertRepo.GetById(id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *authCertAppImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
 | 
			
		||||
	return a.authCertRepo.GetByIds(ids...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *authCertAppImpl) DeleteById(id uint64) {
 | 
			
		||||
	a.authCertRepo.DeleteById(id)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user