From aba5560cb48950b52879ffbe8c0283a81d77b889 Mon Sep 17 00:00:00 2001
From: wubijie <wubijie@kylinos.cn>
Date: Mon, 15 Apr 2024 14:53:12 +0800
Subject: [PATCH] Modify the logic of deleting the machine

---
 src/app/server/service/internal/dao/batchmanagerdao.go | 5 +++++
 src/app/server/service/machine/machinemanager.go       | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/src/app/server/service/internal/dao/batchmanagerdao.go b/src/app/server/service/internal/dao/batchmanagerdao.go
index e861c509..54d9e007 100644
--- a/src/app/server/service/internal/dao/batchmanagerdao.go
+++ b/src/app/server/service/internal/dao/batchmanagerdao.go
@@ -84,3 +84,8 @@ func GetMachineID(BatchID int) ([]uint, error) {
 	err := mysqlmanager.MySQL().Model(BatchMachines{}).Select("machine_node_id").Where("batch_id=?", BatchID).Find(&machineids).Error
 	return machineids, err
 }
+
+func DeleteMachineBatch(NodeID int) error {
+	var bm BatchMachines
+	return mysqlmanager.MySQL().Where("machine_node_id=?", NodeID).Delete(&bm).Error
+}
diff --git a/src/app/server/service/machine/machinemanager.go b/src/app/server/service/machine/machinemanager.go
index 8a87ba36..2bf2ca35 100644
--- a/src/app/server/service/machine/machinemanager.go
+++ b/src/app/server/service/machine/machinemanager.go
@@ -76,6 +76,11 @@ func DeleteMachine(Deluuid []string) map[string]string {
 			machinelist[machinedeluuid] = err.Error()
 		}
 		if node.ID != 0 {
+			//删除机器批次关系表数据
+			if err := dao.DeleteMachineBatch(node.ID); err != nil {
+				machinelist[machinedeluuid] = err.Error()
+				continue
+			}
 			if err := dao.DeleteMachine(machinedeluuid); err != nil {
 				machinelist[machinedeluuid] = err.Error()
 			}
-- 
Gitee

