mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	feat: 新增简易版ioc
This commit is contained in:
		@@ -20,16 +20,15 @@ type MachineScript interface {
 | 
			
		||||
	Delete(ctx context.Context, id uint64)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineScriptApp(machineScriptRepo repository.MachineScript, machineApp Machine) MachineScript {
 | 
			
		||||
	app := &machineScriptAppImpl{machineApp: machineApp}
 | 
			
		||||
	app.Repo = machineScriptRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type machineScriptAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.MachineScript, repository.MachineScript]
 | 
			
		||||
 | 
			
		||||
	machineApp Machine
 | 
			
		||||
	MachineApp Machine `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入MachineScriptRepo
 | 
			
		||||
func (m *machineScriptAppImpl) InjectMachineScriptRepo(repo repository.MachineScript) {
 | 
			
		||||
	m.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const Common_Script_Machine_Id = 9999999
 | 
			
		||||
@@ -43,7 +42,7 @@ func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, page
 | 
			
		||||
func (m *machineScriptAppImpl) Save(ctx context.Context, ms *entity.MachineScript) error {
 | 
			
		||||
	// 如果机器id不为公共脚本id,则校验机器是否存在
 | 
			
		||||
	if machineId := ms.MachineId; machineId != Common_Script_Machine_Id {
 | 
			
		||||
		_, err := m.machineApp.GetById(new(entity.Machine), machineId, "Name")
 | 
			
		||||
		_, err := m.MachineApp.GetById(new(entity.Machine), machineId, "Name")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return errorx.NewBiz("该机器不存在")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user