Skip to content

Commit 0076c7c

Browse files
奇淼(piexlmaxzeromakencghost1pnckmasonFEI
authored
增加插件安装功能并提升其他功能稳定性 (flipped-aurora#1155)
* 增加安装插件demo * 前端上传demo * 插件安装初版 * 调整菜单结构 * fix: 修改密码校验 jwt 中的用户 id * router.go:fix logger的中间件是默认的,这边日志可以删除;cors的日志打印应当在上面两行启用的时候再进行注释 * 登陆==>登录 * 抽离插件安装方法 * 调整插件功能 提升灵活度 Co-authored-by: zeromake <a390720046@gmail.com> Co-authored-by: Lu JJ <275955589@qq.com> Co-authored-by: pnck <hio131@gmail.com> Co-authored-by: feixuanyu <994085848@qq.com>
1 parent 6d5dc43 commit 0076c7c

File tree

27 files changed

+290
-61
lines changed

27 files changed

+290
-61
lines changed

server/api/v1/system/sys_auto_code.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ package system
33
import (
44
"errors"
55
"fmt"
6+
"github.com/flipped-aurora/gin-vue-admin/server/global"
7+
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
8+
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
9+
"github.com/flipped-aurora/gin-vue-admin/server/utils"
610
"golang.org/x/text/cases"
711
"golang.org/x/text/language"
812
"net/url"
913
"os"
1014
"strings"
1115

12-
"github.com/flipped-aurora/gin-vue-admin/server/global"
13-
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
14-
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
15-
"github.com/flipped-aurora/gin-vue-admin/server/utils"
16-
1716
"github.com/gin-gonic/gin"
1817
"go.uber.org/zap"
1918
)
@@ -240,3 +239,18 @@ func (autoApi *AutoCodeApi) AutoPlug(c *gin.Context) {
240239
response.Ok(c)
241240
}
242241
}
242+
243+
func (autoApi *AutoCodeApi) InstallPlugin(c *gin.Context) {
244+
header, err := c.FormFile("plug")
245+
if err != nil {
246+
response.FailWithMessage(err.Error(), c)
247+
return
248+
}
249+
err = autoCodeService.InstallPlugin(header)
250+
if err != nil {
251+
response.FailWithMessage(err.Error(), c)
252+
return
253+
} else {
254+
response.OkWithMessage("插件安装成功,请按照说明配置使用", c)
255+
}
256+
}

server/api/v1/system/sys_user.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,19 @@ func (b *BaseApi) Register(c *gin.Context) {
138138
// @Summary 用户修改密码
139139
// @Security ApiKeyAuth
140140
// @Produce application/json
141-
// @Param data body systemReq.ChangePasswordStruct true "用户名, 原密码, 新密码"
141+
// @Param data body systemReq.ChangePasswordReq true "用户名, 原密码, 新密码"
142142
// @Success 200 {object} response.Response{msg=string} "用户修改密码"
143143
// @Router /user/changePassword [post]
144144
func (b *BaseApi) ChangePassword(c *gin.Context) {
145-
var user systemReq.ChangePasswordStruct
146-
_ = c.ShouldBindJSON(&user)
147-
if err := utils.Verify(user, utils.ChangePasswordVerify); err != nil {
145+
var req systemReq.ChangePasswordReq
146+
_ = c.ShouldBindJSON(&req)
147+
if err := utils.Verify(req, utils.ChangePasswordVerify); err != nil {
148148
response.FailWithMessage(err.Error(), c)
149149
return
150150
}
151-
u := &system.SysUser{Username: user.Username, Password: user.Password}
152-
if _, err := userService.ChangePassword(u, user.NewPassword); err != nil {
151+
uid := utils.GetUserID(c)
152+
u := &system.SysUser{GVA_MODEL: global.GVA_MODEL{ID: uid}, Password: req.Password}
153+
if _, err := userService.ChangePassword(u, req.NewPassword); err != nil {
153154
global.GVA_LOG.Error("修改失败!", zap.Error(err))
154155
response.FailWithMessage("修改失败,原密码与当前账户不符", c)
155156
} else {
@@ -201,8 +202,7 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
201202
return
202203
}
203204
userID := utils.GetUserID(c)
204-
uuid := utils.GetUserUuid(c)
205-
if err := userService.SetUserAuthority(userID, uuid, sua.AuthorityId); err != nil {
205+
if err := userService.SetUserAuthority(userID, sua.AuthorityId); err != nil {
206206
global.GVA_LOG.Error("修改失败!", zap.Error(err))
207207
response.FailWithMessage(err.Error(), c)
208208
} else {

server/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/mailru/easyjson v0.7.7 // indirect
3030
github.com/mitchellh/mapstructure v1.2.2 // indirect
3131
github.com/mojocn/base64Captcha v1.3.1
32+
github.com/otiai10/copy v1.7.0
3233
github.com/pelletier/go-toml v1.6.0 // indirect
3334
github.com/pkg/errors v0.9.1
3435
github.com/qiniu/api.v7/v7 v7.4.1

server/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
424424
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
425425
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
426426
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
427+
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
428+
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
429+
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
430+
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
431+
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
432+
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
433+
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
427434
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
428435
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
429436
github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4=

server/initialize/plugin.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package initialize
22

33
import (
4+
"fmt"
45
"github.com/flipped-aurora/gin-vue-admin/server/global"
6+
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
57
"github.com/flipped-aurora/gin-vue-admin/server/plugin/email"
68
"github.com/flipped-aurora/gin-vue-admin/server/utils/plugin"
79
"github.com/gin-gonic/gin"
@@ -14,7 +16,12 @@ func PluginInit(group *gin.RouterGroup, Plugin ...plugin.Plugin) {
1416
}
1517
}
1618

17-
func InstallPlugin(PublicGroup *gin.RouterGroup, PrivateGroup *gin.RouterGroup) {
19+
func InstallPlugin(Router *gin.Engine) {
20+
PublicGroup := Router.Group("")
21+
fmt.Println("无鉴权插件安装==》", PublicGroup)
22+
PrivateGroup := Router.Group("")
23+
fmt.Println("鉴权插件安装==》", PrivateGroup)
24+
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
1825
// 添加跟角色挂钩权限的插件 示例 本地示例模式于在线仓库模式注意上方的import 可以自行切换 效果相同
1926
PluginInit(PrivateGroup, email.CreateEmailPlug(
2027
global.GVA_CONFIG.Email.To,

server/initialize/router.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ func Routers() *gin.Engine {
2929

3030
Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.StorePath)) // 为用户头像和文件提供静态地址
3131
// Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
32-
global.GVA_LOG.Info("use middleware logger")
3332
// 跨域,如需跨域可以打开下面的注释
3433
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
3534
//Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
36-
global.GVA_LOG.Info("use middleware cors")
35+
//global.GVA_LOG.Info("use middleware cors")
3736
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
3837
global.GVA_LOG.Info("register swagger handler")
3938
// 方便统一添加路由组前缀 多服务器上线使用
@@ -75,7 +74,7 @@ func Routers() *gin.Engine {
7574
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
7675
}
7776

78-
InstallPlugin(PublicGroup, PrivateGroup) // 安装插件
77+
InstallPlugin(Router) // 安装插件
7978

8079
global.GVA_LOG.Info("router register success")
8180
return Router

server/model/system/request/sys_user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type Login struct {
2222
}
2323

2424
// Modify password structure
25-
type ChangePasswordStruct struct {
26-
Username string `json:"username"` // 用户名
25+
type ChangePasswordReq struct {
26+
ID uint `json:"-"` // 从 JWT 中提取 user id,避免越权
2727
Password string `json:"password"` // 密码
2828
NewPassword string `json:"newPassword"` // 新密码
2929
}
@@ -42,7 +42,7 @@ type SetUserAuthorities struct {
4242
type ChangeUserInfo struct {
4343
ID uint `gorm:"primarykey"` // 主键ID
4444
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
45-
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户角色ID
45+
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
4646
AuthorityIds []uint `json:"authorityIds" gorm:"-"` // 角色ID
4747
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
4848
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package system
22

3-
type SysUseAuthority struct {
3+
// SysUserAuthority 是 sysUser 和 sysAuthority 的连接表
4+
type SysUserAuthority struct {
45
SysUserId uint `gorm:"column:sys_user_id"`
56
SysAuthorityAuthorityId uint `gorm:"column:sys_authority_authority_id"`
67
}
78

8-
func (s *SysUseAuthority) TableName() string {
9+
func (s *SysUserAuthority) TableName() string {
910
return "sys_user_authority"
1011
}

server/router/system/sys_auto_code.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ func (s *AutoCodeRouter) InitAutoCodeRouter(Router *gin.RouterGroup) {
2020
autoCodeRouter.POST("getPackage", autoCodeApi.GetPackage) // 获取package包
2121
autoCodeRouter.POST("delPackage", autoCodeApi.DelPackage) // 删除package包
2222
autoCodeRouter.POST("createPlug", autoCodeApi.AutoPlug) // 自动插件包模板
23+
autoCodeRouter.POST("installPlugin", autoCodeApi.InstallPlugin) // 自动安装插件
2324
}
2425
}

server/service/system/sys_authority.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthor
131131
return
132132
}
133133
}
134-
err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_authority_authority_id = ?", auth.AuthorityId).Error
134+
err = global.GVA_DB.Delete(&[]system.SysUserAuthority{}, "sys_authority_authority_id = ?", auth.AuthorityId).Error
135135
err = global.GVA_DB.Delete(&[]system.SysAuthorityBtn{}, "authority_id = ?", auth.AuthorityId).Error
136136
authorityId := strconv.Itoa(int(auth.AuthorityId))
137137
CasbinServiceApp.ClearCasbin(0, authorityId)

server/service/system/sys_auto_code.go

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
cp "github.com/otiai10/copy"
89
"go.uber.org/zap"
910
"go/ast"
1011
"go/format"
1112
"go/parser"
1213
"go/token"
1314
"golang.org/x/text/cases"
1415
"golang.org/x/text/language"
16+
"io"
1517
"io/ioutil"
1618
"log"
19+
"mime/multipart"
1720
"os"
1821
"path/filepath"
1922
"strconv"
@@ -681,7 +684,7 @@ func (vi *Visitor) addStruct(genDecl *ast.GenDecl) ast.Visitor {
681684
case *ast.StructType:
682685
f := &ast.Field{
683686
Names: []*ast.Ident{
684-
&ast.Ident{
687+
{
685688
Name: vi.StructName,
686689
Obj: &ast.Object{
687690
Kind: ast.Var,
@@ -834,3 +837,81 @@ func (autoCodeService *AutoCodeService) CreatePlug(plug system.AutoPlugReq) erro
834837
}
835838
return nil
836839
}
840+
841+
func (autoCodeService *AutoCodeService) InstallPlugin(file *multipart.FileHeader) (err error) {
842+
const GVAPLUGPATH = "./gva-plug-temp/"
843+
defer os.RemoveAll(GVAPLUGPATH)
844+
_, err = os.Stat(GVAPLUGPATH)
845+
if os.IsNotExist(err) {
846+
os.Mkdir(GVAPLUGPATH, os.ModePerm)
847+
}
848+
849+
src, err := file.Open()
850+
if err != nil {
851+
return err
852+
}
853+
defer src.Close()
854+
855+
out, err := os.Create(GVAPLUGPATH + file.Filename)
856+
if err != nil {
857+
return err
858+
}
859+
defer out.Close()
860+
861+
_, err = io.Copy(out, src)
862+
863+
paths, err := utils.Unzip(GVAPLUGPATH+file.Filename, GVAPLUGPATH)
864+
var webIndex = 0
865+
var serverIndex = 0
866+
for i := range paths {
867+
paths[i] = filepath.ToSlash(paths[i])
868+
pathArr := strings.Split(paths[i], "/")
869+
if pathArr[len(pathArr)-2] == "server" && pathArr[len(pathArr)-1] == "plugin" {
870+
serverIndex = i + 1
871+
}
872+
if pathArr[len(pathArr)-2] == "web" && pathArr[len(pathArr)-1] == "plugin" {
873+
webIndex = i + 1
874+
}
875+
}
876+
if webIndex == 0 && serverIndex == 0 {
877+
fmt.Println("非标准插件,请按照文档自动迁移使用")
878+
return errors.New("非标准插件,请按照文档自动迁移使用")
879+
}
880+
881+
if webIndex != 0 {
882+
webNameArr := strings.Split(filepath.ToSlash(paths[webIndex]), "/")
883+
webName := webNameArr[len(webNameArr)-1]
884+
var form = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Server + "/" + paths[webIndex])
885+
var to = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Web + "/plugin/" + webName)
886+
_, err := os.Stat(to)
887+
if err == nil {
888+
fmt.Println("web 已存在同名插件,请自行手动安装")
889+
return errors.New("web 已存在同名插件,请自行手动安装")
890+
}
891+
err = cp.Copy(form, to)
892+
if err != nil {
893+
return err
894+
}
895+
}
896+
897+
if serverIndex != 0 {
898+
serverNameArr := strings.Split(filepath.ToSlash(paths[serverIndex]), "/")
899+
serverName := serverNameArr[len(serverNameArr)-1]
900+
var form = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Server + "/" + paths[serverIndex])
901+
var to = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Server + "/plugin/" + serverName)
902+
_, err := os.Stat(to)
903+
if err == nil {
904+
fmt.Println("server 已存在同名插件,请自行手动安装")
905+
return errors.New("server 已存在同名插件,请自行手动安装")
906+
}
907+
err = cp.Copy(form, to)
908+
if err != nil {
909+
return err
910+
}
911+
}
912+
if err != nil {
913+
return err
914+
} else {
915+
return nil
916+
}
917+
}

server/service/system/sys_user.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ func (userService *UserService) Login(u *system.SysUser) (userInter *system.SysU
7979

8080
func (userService *UserService) ChangePassword(u *system.SysUser, newPassword string) (userInter *system.SysUser, err error) {
8181
var user system.SysUser
82-
err = global.GVA_DB.Where("username = ?", u.Username).First(&user).Error
83-
if err != nil {
82+
if err = global.GVA_DB.Where("id = ?", u.ID).First(&user).Error; err != nil {
8483
return nil, err
8584
}
8685
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
@@ -117,12 +116,12 @@ func (userService *UserService) GetUserInfoList(info request.PageInfo) (list int
117116
//@param: uuid uuid.UUID, authorityId string
118117
//@return: err error
119118

120-
func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, authorityId uint) (err error) {
121-
assignErr := global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", id, authorityId).First(&system.SysUseAuthority{}).Error
119+
func (userService *UserService) SetUserAuthority(id uint, authorityId uint) (err error) {
120+
assignErr := global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", id, authorityId).First(&system.SysUserAuthority{}).Error
122121
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
123122
return errors.New("该用户无此角色")
124123
}
125-
err = global.GVA_DB.Where("uuid = ?", uuid).First(&system.SysUser{}).Update("authority_id", authorityId).Error
124+
err = global.GVA_DB.Where("id = ?", id).First(&system.SysUser{}).Update("authority_id", authorityId).Error
126125
return err
127126
}
128127

@@ -134,13 +133,13 @@ func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, author
134133

135134
func (userService *UserService) SetUserAuthorities(id uint, authorityIds []uint) (err error) {
136135
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
137-
TxErr := tx.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error
136+
TxErr := tx.Delete(&[]system.SysUserAuthority{}, "sys_user_id = ?", id).Error
138137
if TxErr != nil {
139138
return TxErr
140139
}
141-
var useAuthority []system.SysUseAuthority
140+
var useAuthority []system.SysUserAuthority
142141
for _, v := range authorityIds {
143-
useAuthority = append(useAuthority, system.SysUseAuthority{
142+
useAuthority = append(useAuthority, system.SysUserAuthority{
144143
SysUserId: id, SysAuthorityAuthorityId: v,
145144
})
146145
}
@@ -169,7 +168,7 @@ func (userService *UserService) DeleteUser(id int) (err error) {
169168
if err != nil {
170169
return err
171170
}
172-
err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error
171+
err = global.GVA_DB.Delete(&[]system.SysUserAuthority{}, "sys_user_id = ?", id).Error
173172
return err
174173
}
175174

server/source/system/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
111111
{ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/createTemp", Description: "自动化代码"},
112112
{ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/preview", Description: "预览自动化代码"},
113113
{ApiGroup: "代码生成器", Method: "GET", Path: "/autoCode/getColumn", Description: "获取所选table的所有字段"},
114-
{ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/createPlug", Description: "自从创建插件包"},
114+
{ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/createPlug", Description: "自动创建插件包"},
115+
{ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/installPlug", Description: "安装插件"},
115116

116117
{ApiGroup: "包(pkg)生成器", Method: "POST", Path: "/autoCode/createPackage", Description: "生成包(package)"},
117118
{ApiGroup: "包(pkg)生成器", Method: "POST", Path: "/autoCode/getPackage", Description: "获取所有包(package)"},

server/source/system/authorities_menus.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package system
22

33
import (
44
"context"
5+
56
sysModel "github.com/flipped-aurora/gin-vue-admin/server/model/system"
67
"github.com/flipped-aurora/gin-vue-admin/server/service/system"
78
"github.com/pkg/errors"
@@ -73,10 +74,13 @@ func (i *initMenuAuthority) DataInserted(ctx context.Context) bool {
7374
if !ok {
7475
return false
7576
}
76-
var count int64
77-
if err := db.Model(&sysModel.SysAuthority{}).
78-
Where("authority_id = ?", "9528").Preload("SysBaseMenus").Count(&count); err != nil {
79-
return count == 16
77+
auth := &sysModel.SysAuthority{}
78+
if ret := db.Model(auth).
79+
Where("authority_id = ?", 9528).Preload("SysBaseMenus").Find(auth); ret != nil {
80+
if ret.Error != nil {
81+
return false
82+
}
83+
return len(auth.SysBaseMenus) > 0
8084
}
8185
return false
8286
}

0 commit comments

Comments
 (0)