From a760f8207a2a6e0fba71bc6f9ca5aab1852e9352 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 29 Aug 2025 17:24:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BD=AF=E4=BB=B6=E5=8C=85=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=9B=B4=E6=96=B0=E6=9B=BF=E6=8D=A2=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8D=E5=88=A0=E9=99=A4=E6=97=A7=E8=BD=AF?= =?UTF-8?q?=E4=BB=B6=E5=8C=85=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network_element/controller/ne_software.go | 4 ++-- .../network_element/service/ne_software.go | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/modules/network_element/controller/ne_software.go b/src/modules/network_element/controller/ne_software.go index a13708a2..21a3aa0f 100644 --- a/src/modules/network_element/controller/ne_software.go +++ b/src/modules/network_element/controller/ne_software.go @@ -101,7 +101,7 @@ func (s NeSoftwareController) Add(c *gin.Context) { }) if len(neSoftwares) > 0 { neSoftware := neSoftwares[0] - s.neSoftwareService.DeleteByIds([]int64{neSoftware.ID}) + s.neSoftwareService.DeleteByIds([]int64{neSoftware.ID}, false) } // 检查属性值唯一 @@ -183,7 +183,7 @@ func (s NeSoftwareController) Remove(c *gin.Context) { ids = append(ids, parse.Number(v)) } - rows, err := s.neSoftwareService.DeleteByIds(ids) + rows, err := s.neSoftwareService.DeleteByIds(ids, true) if err != nil { c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error()))) return diff --git a/src/modules/network_element/service/ne_software.go b/src/modules/network_element/service/ne_software.go index 39b9aa5f..7df5c2af 100644 --- a/src/modules/network_element/service/ne_software.go +++ b/src/modules/network_element/service/ne_software.go @@ -87,7 +87,7 @@ func (r NeSoftware) Update(neSoftware model.NeSoftware) int64 { } // DeleteByIds 批量删除信息 -func (r NeSoftware) DeleteByIds(ids []int64) (int64, error) { +func (r NeSoftware) DeleteByIds(ids []int64, delFile bool) (int64, error) { // 检查是否存在 rows := r.neSoftwareRepository.SelectByIds(ids) if len(rows) <= 0 { @@ -95,15 +95,18 @@ func (r NeSoftware) DeleteByIds(ids []int64) (int64, error) { } if len(rows) == len(ids) { - // 遍历软件包列表进行文件删除 - for _, row := range rows { - // 检查文件是否存在 - filePath := file.ParseUploadFileAbsPath(row.Path) - if _, err := os.Stat(filePath); err != nil { - continue + if delFile { + // 遍历软件包列表进行文件删除 + for _, row := range rows { + // 检查文件是否存在 + filePath := file.ParseUploadFileAbsPath(row.Path) + if _, err := os.Stat(filePath); err != nil { + continue + } + os.Remove(filePath) } - os.Remove(filePath) } + rows := r.neSoftwareRepository.DeleteByIds(ids) return rows, nil }