Skip to content

Commit 85d7966

Browse files
authored
✨ feat: support delete all menu and it's children (#151)
1 parent d53e70a commit 85d7966

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

.github/PULL_REQUEST_TEMPLATE.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
assignees:
3-
- 'lwnmengjing'
4-
---
51
## Description
62

73
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/gorilla/websocket v1.5.3
2323
github.com/grafana/pyroscope-go v1.1.1
2424
github.com/larksuite/oapi-sdk-go/v3 v3.3.1
25-
github.com/mss-boot-io/mss-boot v0.2.6
25+
github.com/mss-boot-io/mss-boot v0.2.7-0.20240810123304-2ea7f0e578e3
2626
github.com/mss-boot-io/redisqueue/v2 v2.0.0-20240222064111-d36e396df7f9
2727
github.com/nsqio/go-nsq v1.1.0
2828
github.com/redis/go-redis/v9 v9.6.1
@@ -223,7 +223,7 @@ require (
223223
github.com/prometheus/common v0.55.0 // indirect
224224
github.com/prometheus/exporter-toolkit v0.11.0 // indirect
225225
github.com/prometheus/procfs v0.15.1 // indirect
226-
github.com/prometheus/prometheus v0.53.1 // indirect
226+
github.com/prometheus/prometheus v0.54.0 // indirect
227227
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
228228
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
229229
github.com/russross/blackfriday/v2 v2.1.0 // indirect

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJ
573573
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
574574
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
575575
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
576-
github.com/mss-boot-io/mss-boot v0.2.6 h1:HDlFz/L9S/ohJB2e9rOrqjWoEmy5oKdNAAiMswq1WYU=
577-
github.com/mss-boot-io/mss-boot v0.2.6/go.mod h1:MhRsjv61e0HXlZ9ZnnRrMQB96mn6w9uz4f2BYWJU76E=
576+
github.com/mss-boot-io/mss-boot v0.2.7-0.20240810123304-2ea7f0e578e3 h1:RByHxfjbP7p4aGTBJpQWNVOuSKajQCmDsr2Ly6hrs58=
577+
github.com/mss-boot-io/mss-boot v0.2.7-0.20240810123304-2ea7f0e578e3/go.mod h1:MhRsjv61e0HXlZ9ZnnRrMQB96mn6w9uz4f2BYWJU76E=
578578
github.com/mss-boot-io/redisqueue/v2 v2.0.0-20240222064111-d36e396df7f9 h1:/YgpHiqgrxz/0+mKoETXu21c6/fyDt7/j9bdD3UkbdU=
579579
github.com/mss-boot-io/redisqueue/v2 v2.0.0-20240222064111-d36e396df7f9/go.mod h1:f/sISkwvecPq37zygQzWNj5ntJoP/jcoK0kPIjFTWFI=
580580
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
@@ -653,8 +653,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
653653
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
654654
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
655655
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
656-
github.com/prometheus/prometheus v0.53.1 h1:B0xu4VuVTKYrIuBMn/4YSUoIPYxs956qsOfcS4rqCuA=
657-
github.com/prometheus/prometheus v0.53.1/go.mod h1:RZDkzs+ShMBDkAPQkLEaLBXpjmDcjhNxU2drUVPgKUU=
656+
github.com/prometheus/prometheus v0.54.0 h1:6+VmEkohHcofl3W5LyRlhw1Lfm575w/aX6ZFyVAmzM0=
657+
github.com/prometheus/prometheus v0.54.0/go.mod h1:xlLByHhk2g3ycakQGrMaU8K7OySZx98BzeCR99991NY=
658658
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
659659
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
660660
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=

models/menu.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package models
22

33
import (
4+
"fmt"
45
"sort"
56

6-
"github.com/mss-boot-io/mss-boot-admin/pkg"
7+
"github.com/gin-gonic/gin"
78
"github.com/mss-boot-io/mss-boot/pkg/enum"
89
"gorm.io/gorm"
10+
11+
"github.com/mss-boot-io/mss-boot-admin/pkg"
912
)
1013

1114
/*
@@ -113,6 +116,31 @@ func (e *Menu) BeforeSave(_ *gorm.DB) error {
113116
return nil
114117
}
115118

119+
func (e *Menu) AfterDelete(tx *gorm.DB) error {
120+
ctx := tx.Statement.Context.(*gin.Context)
121+
idsInterface, ok := ctx.Get("ids")
122+
if !ok {
123+
return nil
124+
}
125+
ids, ok := idsInterface.([]string)
126+
if !ok {
127+
return nil
128+
}
129+
sqlTemp := fmt.Sprintf(`WITH RECURSIVE MenuHierarchy AS (
130+
SELECT id
131+
FROM %s
132+
WHERE id IN ?
133+
UNION ALL
134+
SELECT m.id
135+
FROM %s m
136+
INNER JOIN MenuHierarchy mh ON m.parent_id = mh.id
137+
)
138+
UPDATE %s
139+
SET deleted_at = datetime('now')
140+
WHERE id IN (SELECT id FROM MenuHierarchy)`, e.TableName(), e.TableName(), e.TableName())
141+
return tx.Exec(sqlTemp, ids).Error
142+
}
143+
116144
func (e *Menu) GetIndex() string {
117145
return e.ID
118146
}

0 commit comments

Comments
 (0)