2021-05-08 18:00:33 +08:00
|
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"mayfly-go/base/biz"
|
|
|
|
|
|
"mayfly-go/base/model"
|
2021-06-07 17:22:07 +08:00
|
|
|
|
"mayfly-go/server/devops/domain/entity"
|
|
|
|
|
|
"mayfly-go/server/devops/domain/repository"
|
|
|
|
|
|
"mayfly-go/server/devops/infrastructure/persistence"
|
2021-05-08 18:00:33 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
type MachineScript interface {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
// 分页获取机器脚本信息列表
|
2021-07-28 18:03:19 +08:00
|
|
|
|
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
2021-05-08 18:00:33 +08:00
|
|
|
|
|
|
|
|
|
|
// 根据条件获取
|
|
|
|
|
|
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
|
|
|
|
|
|
|
|
|
|
|
// 根据id获取
|
|
|
|
|
|
GetById(id uint64, cols ...string) *entity.MachineScript
|
|
|
|
|
|
|
|
|
|
|
|
Save(entity *entity.MachineScript)
|
|
|
|
|
|
|
|
|
|
|
|
Delete(id uint64)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
type machineScriptAppImpl struct {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
machineScriptRepo repository.MachineScript
|
|
|
|
|
|
machineRepo repository.Machine
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Common_Script_Machine_Id = 9999999
|
|
|
|
|
|
|
|
|
|
|
|
// 实现类单例
|
2021-07-28 18:03:19 +08:00
|
|
|
|
var MachineScriptApp MachineScript = &machineScriptAppImpl{
|
2021-05-08 18:00:33 +08:00
|
|
|
|
machineRepo: persistence.MachineDao,
|
|
|
|
|
|
machineScriptRepo: persistence.MachineScriptDao}
|
|
|
|
|
|
|
|
|
|
|
|
// 分页获取机器脚本信息列表
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
return m.machineScriptRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据条件获取
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *machineScriptAppImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
return m.machineScriptRepo.GetMachineScript(condition, cols...)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据id获取
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *machineScriptAppImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
return m.machineScriptRepo.GetById(id, cols...)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 保存机器脚本
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *machineScriptAppImpl) Save(entity *entity.MachineScript) {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
// 如果机器id不为公共脚本id,则校验机器是否存在
|
|
|
|
|
|
if machineId := entity.MachineId; machineId != Common_Script_Machine_Id {
|
|
|
|
|
|
biz.NotNil(m.machineRepo.GetById(machineId, "Name"), "该机器不存在")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if entity.Id != 0 {
|
|
|
|
|
|
model.UpdateById(entity)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
model.Insert(entity)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据id删除
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *machineScriptAppImpl) Delete(id uint64) {
|
2021-05-08 18:00:33 +08:00
|
|
|
|
m.machineScriptRepo.Delete(id)
|
|
|
|
|
|
}
|