Merge branch 'gin-vue-admin_v2_dev' of https://github.com/piexlmax/gin-vue-admin into gin-vue-admin_v2_dev

# Conflicts:
#	server/model/sys_authority.go
#	server/model/sys_authority_menu.go
#	server/model/sys_base_menu.go
This commit is contained in:
rainyan
2020-04-06 00:47:46 +08:00
28 changed files with 259 additions and 315 deletions
+2 -13
View File
@@ -17,7 +17,6 @@ type ExaCustomer struct {
// @title CreateExaCustomer
// @description create a customer, 创建用户
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @return err error
func (e *ExaCustomer) CreateExaCustomer() (err error) {
err = global.GVA_DB.Create(e).Error
@@ -27,9 +26,6 @@ func (e *ExaCustomer) CreateExaCustomer() (err error) {
// @title DeleteFileChunk
// @description delete a customer, 删除用户
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (e *ExaCustomer) DeleteExaCustomer() (err error) {
err = global.GVA_DB.Delete(e).Error
@@ -39,9 +35,6 @@ func (e *ExaCustomer) DeleteExaCustomer() (err error) {
// @title UpdateExaCustomer
// @description update a customer, 更新用户
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (e *ExaCustomer) UpdateExaCustomer() (err error) {
err = global.GVA_DB.Save(e).Error
@@ -51,10 +44,8 @@ func (e *ExaCustomer) UpdateExaCustomer() (err error) {
// @title GetExaCustomer
// @description get the info of a costumer , 获取用户信息
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
// @return customer ExaCustomer
func (e *ExaCustomer) GetExaCustomer() (err error, customer ExaCustomer) {
err = global.GVA_DB.Where("id = ?", e.ID).First(&customer).Error
return
@@ -63,9 +54,7 @@ func (e *ExaCustomer) GetExaCustomer() (err error, customer ExaCustomer) {
// @title GetInfoList
// @description get customer list by pagination, 分页获取用户列表
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param info PageInfo
// @return error
func (e *ExaCustomer) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
limit := info.PageSize
+4 -13
View File
@@ -16,9 +16,6 @@ type ExaFileUploadAndDownload struct {
// @title Upload
// @description 删除文件切片记录
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (f *ExaFileUploadAndDownload) Upload() error {
err := global.GVA_DB.Create(f).Error
@@ -28,9 +25,6 @@ func (f *ExaFileUploadAndDownload) Upload() error {
// @title DeleteFile
// @description 删除文件切片记录
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (f *ExaFileUploadAndDownload) DeleteFile() error {
err := global.GVA_DB.Where("id = ?", f.ID).Unscoped().Delete(f).Error
@@ -40,9 +34,6 @@ func (f *ExaFileUploadAndDownload) DeleteFile() error {
// @title FindFile
// @description 删除文件切片记录
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (f *ExaFileUploadAndDownload) FindFile() (error, ExaFileUploadAndDownload) {
var file ExaFileUploadAndDownload
@@ -53,10 +44,10 @@ func (f *ExaFileUploadAndDownload) FindFile() (error, ExaFileUploadAndDownload)
// @title GetInfoList
// @description 分页获取数据
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
// @param info PageInfo
// @return err error
// @return list error
// @return total error
func (f *ExaFileUploadAndDownload) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
+7 -17
View File
@@ -43,9 +43,6 @@ func (a *SysApi) CreateApi() (err error) {
// @title DeleteApi
// @description delete base apis, 删除基础api
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (a *SysApi) DeleteApi() (err error) {
err = global.GVA_DB.Delete(a).Error
@@ -56,9 +53,6 @@ func (a *SysApi) DeleteApi() (err error) {
// @title UpdateApi
// @description update a base api, update api
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (a *SysApi) UpdateApi() (err error) {
var oldA SysApi
@@ -83,9 +77,7 @@ func (a *SysApi) UpdateApi() (err error) {
// @title GetApiById
// @description get the apis of the selected user, 获取选中角色所拥有的api
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param id float64
// @return error
func (a *SysApi) GetApiById(id float64) (err error, api SysApi) {
err = global.GVA_DB.Where("id = ?", id).First(&api).Error
@@ -95,10 +87,8 @@ func (a *SysApi) GetApiById(id float64) (err error, api SysApi) {
// @title GetAllApis
// @description get all apis, 获取所有的api
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
// @return err error
// @return apis []SysApi
func (a *SysApi) GetAllApis() (err error, apis []SysApi) {
err = global.GVA_DB.Find(&apis).Error
return
@@ -107,10 +97,10 @@ func (a *SysApi) GetAllApis() (err error, apis []SysApi) {
// @title GetInfoList
// @description get apis by pagination, 分页获取数据
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
// @param info PageInfo
// @return err error
// @return list interface{}
// @return total int
func (a *SysApi) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
+1 -1
View File
@@ -43,7 +43,7 @@ func (a *SysAuthority) DeleteAuthority() (err error) {
if err != nil {
err = global.GVA_DB.Where("parent_id = ?", a.AuthorityId).Find(&SysAuthority{}).Error
if err != nil {
err = global.GVA_DB.Where("authority_id = ?", a.AuthorityId).First(a).Unscoped().Delete(a).Error
err = global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", a.AuthorityId).First(a).Unscoped().Delete(a).Association("SysBaseMenus").Delete(a.SysBaseMenus).Error
new(CasbinModel).ClearCasbin(0, a.AuthorityId)
} else {
err = errors.New("此角色存在子角色不允许删除")
+23 -33
View File
@@ -1,13 +1,12 @@
package model
import (
"fmt"
"gin-vue-admin/global"
)
type SysMenu struct {
SysBaseMenu
MenuId string `json:"menuId"`
MenuId string `json:"MenuId"`
AuthorityId string `json:"-"`
Children []SysMenu `json:"children"`
}
@@ -15,51 +14,41 @@ type SysMenu struct {
// @title AddMenuAuthority
// @description 为角色增加menu树
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param menus []SysBaseMenu
// @param authorityId string
// @return error
func (m *SysMenu) AddMenuAuthority(menus []SysBaseMenu, authorityId string) (err error) {
var menu SysMenu
global.GVA_DB.Where("authority_id = ? ", authorityId).Unscoped().Delete(&SysMenu{})
for _, v := range menus {
menu.SysBaseMenu = v
menu.AuthorityId = authorityId
menu.MenuId = fmt.Sprintf("%v", v.ID)
menu.ID = 0
err = global.GVA_DB.Create(&menu).Error
if err != nil {
return err
}
}
var auth SysAuthority
auth.AuthorityId = authorityId
auth.SysBaseMenus = menus
auth.SetMuneAuthority()
return nil
err = auth.SetMuneAuthority()
return err
}
// @title GetMenuAuthority
// @description 查看当前角色树
// @auth (2020/04/05 20:22 )
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
func (m *SysMenu) GetMenuAuthority(authorityId string) (err error, menus []SysMenu) {
err = global.GVA_DB.Where("authority_id = ?", authorityId).Find(&menus).Error
return err, menus
// @param authorityId string
// @return err error
// @return menus []SysBaseMenu
func (m *SysMenu) GetMenuAuthority(authorityId string) (err error, menus []SysBaseMenu) {
var a SysAuthority
err = global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", authorityId).First(&a).Error
return err, a.SysBaseMenus
}
// @title GetMenuTree
// @description 获取动态菜单树
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @param authorityId string
// @return err error
// @return menus []SysMenu
func (m *SysMenu) GetMenuTree(authorityId string) (err error, menus []SysMenu) {
err = global.GVA_DB.Where("authority_id = ? AND parent_id = ?", authorityId, 0).Order("sort", true).Find(&menus).Error
SQLstatement := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? AND authority_menu.parent_id = ?"
err = global.GVA_DB.Raw(SQLstatement, authorityId, 0).Scan(&menus).Error
for i := 0; i < len(menus); i++ {
err = getChildrenList(&menus[i])
err = getChildrenList(&menus[i], SQLstatement)
}
return err, menus
}
@@ -67,12 +56,13 @@ func (m *SysMenu) GetMenuTree(authorityId string) (err error, menus []SysMenu) {
// @title getChildrenList
// @description 获取子菜单
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @param menu *SysMenu
// @param SQLstatement string
// @return err error
func getChildrenList(menu *SysMenu) (err error) {
err = global.GVA_DB.Where("authority_id = ? AND parent_id = ?", menu.AuthorityId, menu.MenuId).Order("sort", true).Find(&menu.Children).Error
func getChildrenList(menu *SysMenu, SQLstatement string) (err error) {
err = global.GVA_DB.Raw(SQLstatement, menu.AuthorityId, menu.MenuId).Scan(&menu.Children).Error
for i := 0; i < len(menu.Children); i++ {
err = getChildrenList(&menu.Children[i])
err = getChildrenList(&menu.Children[i], SQLstatement)
}
return err
}
+1 -2
View File
@@ -24,7 +24,6 @@ type Field struct {
// @title CreateTemp
// @description 函数的详细描述
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @return err error
func (a *AutoCodeStruct) CreateTemp() (err error) {
basePath := "./template"
@@ -133,7 +132,7 @@ func (a *AutoCodeStruct) CreateTemp() (err error) {
// @title createDir
// @description 批量创建文件夹
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @param dirs string
// @return err error
func createDir(dirs ...string) (err error) {
for _, v := range dirs {
+2 -6
View File
@@ -17,7 +17,6 @@ type SysBaseMenu struct {
Component string `json:"component"`
Sort string `json:"sort"`
Meta `json:"meta"`
NickName string `json:"nickName"`
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
Children []SysBaseMenu `json:"children"`
}
@@ -36,7 +35,6 @@ type Meta struct {
func (b *SysBaseMenu) AddBaseMenu() (err error) {
findOne := global.GVA_DB.Where("name = ?", b.Name).Find(&SysBaseMenu{}).Error
if findOne != nil {
b.NickName = b.Title
err = global.GVA_DB.Create(b).Error
} else {
err = errors.New("存在重复name,请修改name")
@@ -52,8 +50,7 @@ func (b *SysBaseMenu) AddBaseMenu() (err error) {
func (b *SysBaseMenu) DeleteBaseMenu(id float64) (err error) {
err = global.GVA_DB.Where("parent_id = ?", id).First(&SysBaseMenu{}).Error
if err != nil {
err = global.GVA_DB.Where("id = ?", id).Delete(&b).Error
err = global.GVA_DB.Where("menu_id = ?", id).Unscoped().Delete(&SysMenu{}).Error
err = global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).Delete(&b).Association("SysAuthoritys").Delete(b.SysAuthoritys).Error
} else {
return errors.New("此菜单存在子菜单不可删除")
}
@@ -75,7 +72,6 @@ func (b *SysBaseMenu) UpdateBaseMenu() (err error) {
upDateMap["title"] = b.Title
upDateMap["icon"] = b.Icon
upDateMap["sort"] = b.Sort
upDateMap["nick_name"] = b.Title
err = global.GVA_DB.Where("id = ?", b.ID).Find(&SysBaseMenu{}).Updates(upDateMap).Error
err1 := global.GVA_DB.Where("menu_id = ?", b.ID).Find(&[]SysMenu{}).Updates(upDateMap).Error
fmt.Printf("菜单修改时候,关联菜单err1:%v,err:%v", err1, err)
@@ -83,7 +79,7 @@ func (b *SysBaseMenu) UpdateBaseMenu() (err error) {
}
// @title GetBaseMenuById
// @description 当前选中角色所拥有的路由
// @description get current menus, 返回当前选中menu
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @return err error
+14 -14
View File
@@ -68,8 +68,8 @@ func (c *CasbinModel) UpdateCasbinApi(oldPath string, newPath string) error {
// @title AddCasbin
// @description add casbin authority, 添加权限
// @auth (2020/04/05 20:22 )
// @param cm CasbinModel
// @return bool
// @param cm CasbinModel
// @return bool
func (c *CasbinModel) AddCasbin(cm CasbinModel) bool {
e := Casbin()
return e.AddPolicy(cm.AuthorityId, cm.Path, cm.Method)
@@ -78,8 +78,8 @@ func (c *CasbinModel) AddCasbin(cm CasbinModel) bool {
// @title GetPolicyPathByAuthorityId
// @description get policy path by authorityId, 获取权限列表
// @auth (2020/04/05 20:22 )
// @param authorityId string
// @return []string
// @param authorityId string
// @return []string
func (c *CasbinModel) GetPolicyPathByAuthorityId(authorityId string) []string {
e := Casbin()
var pathList []string
@@ -93,9 +93,9 @@ func (c *CasbinModel) GetPolicyPathByAuthorityId(authorityId string) []string {
// @title ClearCasbin
// @description 清除匹配的权限
// @auth (2020/04/05 20:22 )
// @param v int
// @param p string
// @return bool
// @param v int
// @param p string
// @return bool
func (c *CasbinModel) ClearCasbin(v int, p string) bool {
e := Casbin()
return e.RemoveFilteredPolicy(v, p)
@@ -105,9 +105,9 @@ func (c *CasbinModel) ClearCasbin(v int, p string) bool {
// @title ParamsMatch
// @description customized rule, 自定义规则函数
// @auth (2020/04/05 20:22 )
// @param fullNameKey1 string
// @param key2 string
// @return bool
// @param fullNameKey1 string
// @param key2 string
// @return bool
func ParamsMatch(fullNameKey1 string, key2 string) bool {
key1 := strings.Split(fullNameKey1, "?")[0]
//剥离路径后再使用casbin的keyMatch2
@@ -117,9 +117,9 @@ func ParamsMatch(fullNameKey1 string, key2 string) bool {
// @title ParamsMatchFunc
// @description customized function, 自定义规则函数
// @auth (2020/04/05 20:22 )
// @param args ...interface{}
// @return interface{}
// @return error
// @param args ...interface{}
// @return interface{}
// @return error
func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
name1 := args[0].(string)
name2 := args[1].(string)
@@ -128,7 +128,7 @@ func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
}
// @title Casbin
// @description 持久化到数据库 引入自定义规则
// @description store to DB, 持久化到数据库 引入自定义规则
// @auth (2020/04/05 20:22 )
func Casbin() *casbin.Enforcer {
a := gormadapter.NewAdapterByDB(global.GVA_DB)
+3 -3
View File
@@ -13,7 +13,7 @@ type JwtBlacklist struct {
// @title JsonInBlacklist
// @description create jwt blacklist
// @auth (2020/04/05 20:22 )
// @return err error
// @return err error
func (j *JwtBlacklist) JsonInBlacklist() (err error) {
err = global.GVA_DB.Create(j).Error
return
@@ -42,8 +42,8 @@ func (j *JwtBlacklist) GetRedisJWT(userName string) (err error, RedisJWT string)
// @title SetRedisJWT
// @description set jwt into the Redis
// @auth (2020/04/05 20:22 )
// @param userName string
// @return err error
// @param userName string
// @return err error
func (j *JwtBlacklist) SetRedisJWT(userName string) (err error) {
err = global.GVA_REDIS.Set(userName, j.Jwt, 1000*1000*1000*60*60*24*7).Err()
return err
+4 -4
View File
@@ -14,16 +14,16 @@ type System struct {
// @title GetSystemConfig
// @description 读取配置文件
// @auth (2020/04/05 20:22 )
// @return err error
// @return conf Server
// @return err error
// @return conf Server
func (s *System) GetSystemConfig() (err error, conf config.Server) {
return nil, global.GVA_CONFIG
}
// @title SetSystemConfig
// @description set system config, 设置配置文件
// @auth (2020/04/05 20:22 )
// @return err error
// @auth (2020/04/05 20:22 )
// @return err error
func (s *System) SetSystemConfig() (err error) {
confs := utils.StructToMap(s.Config)
for k, v := range confs {
+3 -3
View File
@@ -72,9 +72,9 @@ func (u *SysUser) ChangePassword(newPassword string) (err error, userInter *SysU
// @title SetUserAuthority
// @description set the authority of a certain user, 设置一个用户的权限
// @auth (2020/04/05 20:22 )
// @param uuid UUID
// @param authorityId string
// @return err error
// @param uuid UUID
// @param authorityId string
// @return err error
func (u *SysUser) SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
err = global.GVA_DB.Where("uuid = ?", uuid).First(&SysUser{}).Update("authority_id", authorityId).Error
return err
+1 -1
View File
@@ -28,7 +28,7 @@ type SysWorkflowStepInfo struct {
// @title Create
// @description create a workflow, 创建工作流
// @auth (2020/04/05 20:22 )
// @return error
// @return error
func (wk *SysWorkflow) Create() error {
err := global.GVA_DB.Create(&wk).Error
return err