mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-16 04:36:35 +08:00
简单基于DDD重构,并实现机器文件及脚本管理
This commit is contained in:
63
devops/application/machine_app.go
Normal file
63
devops/application/machine_app.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/devops/domain/entity"
|
||||
"mayfly-go/devops/domain/repository"
|
||||
"mayfly-go/devops/infrastructure/machine"
|
||||
"mayfly-go/devops/infrastructure/persistence"
|
||||
)
|
||||
|
||||
type IMachine interface {
|
||||
// 根据条件获取账号信息
|
||||
GetMachine(condition *entity.Machine, cols ...string) error
|
||||
|
||||
Save(entity *entity.Machine)
|
||||
|
||||
// 根据id获取
|
||||
GetById(id uint64, cols ...string) *entity.Machine
|
||||
|
||||
// 分页获取机器信息列表
|
||||
GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) model.PageResult
|
||||
|
||||
// 获取机器连接
|
||||
GetCli(id uint64) *machine.Cli
|
||||
}
|
||||
|
||||
type machineApp struct {
|
||||
machineRepo repository.Machine
|
||||
}
|
||||
|
||||
var Machine IMachine = &machineApp{machineRepo: persistence.MachineDao}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineApp) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) model.PageResult {
|
||||
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
// 根据条件获取机器信息
|
||||
func (m *machineApp) Save(entity *entity.Machine) {
|
||||
if entity.Id != 0 {
|
||||
m.machineRepo.UpdateById(entity)
|
||||
} else {
|
||||
m.machineRepo.Create(entity)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据条件获取机器信息
|
||||
func (m *machineApp) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
return m.machineRepo.GetMachine(condition, cols...)
|
||||
}
|
||||
|
||||
func (m *machineApp) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
return m.machineRepo.GetById(id, cols...)
|
||||
}
|
||||
|
||||
func (m *machineApp) GetCli(id uint64) *machine.Cli {
|
||||
cli, err := machine.GetCli(id, func(machineId uint64) *entity.Machine {
|
||||
return m.GetById(machineId)
|
||||
})
|
||||
biz.ErrIsNil(err, "获取客户端错误")
|
||||
return cli
|
||||
}
|
||||
Reference in New Issue
Block a user