diff --git a/api/version1/dict/dictionary.go b/api/version1/dict/dictionary.go index 013493a..cda72f6 100644 --- a/api/version1/dict/dictionary.go +++ b/api/version1/dict/dictionary.go @@ -306,7 +306,7 @@ func (a *ApiMethod) GetDictionary(c *gin.Context) { var dictionaryContList []modelAppPlatform.Dictionary gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Dictionary{}).Where("`status` BETWEEN ? AND ?", 1, 2) if requestData.KeyWords != "" { - gormDb.Where("`name` like ?", "%"+requestData.KeyWords+"%") + gormDb = gormDb.Where("`name` like ?", "%"+requestData.KeyWords+"%") } var total int64 totalErr := gormDb.Count(&total).Error diff --git a/api/version1/entry.go b/api/version1/entry.go index edec64f..50a45e3 100644 --- a/api/version1/entry.go +++ b/api/version1/entry.go @@ -3,6 +3,7 @@ package version1 import ( "appPlatform/api/version1/dict" "appPlatform/api/version1/grantpowers" + matrixapi "appPlatform/api/version1/matrixApi" "appPlatform/api/version1/menus" "appPlatform/api/version1/user" ) @@ -12,6 +13,7 @@ type ApiEntry struct { MenusApi menus.ApiMethod //菜单路由 DictApi dict.ApiMethod //字典 GranSystemPowerApi grantpowers.ApiMethod //系统授权 + MatrixApi matrixapi.ApiMethod //权限矩阵 } var AppApiEntry = new(ApiEntry) diff --git a/api/version1/matrixApi/api.go b/api/version1/matrixApi/api.go new file mode 100644 index 0000000..37e9eff --- /dev/null +++ b/api/version1/matrixApi/api.go @@ -0,0 +1,75 @@ +package matrixapi + +import ( + "appPlatform/models/modelAppPlatform" + "appPlatform/models/modelshr" + "appPlatform/overall" + "appPlatform/overall/publicmethod" + + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-04 13:05:25 +@ 功能: 获取矩阵列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) MatrixList(c *gin.Context) { + var requestData SearchMatrix + c.ShouldBindJSON(&requestData) + if requestData.Page == 0 { + requestData.Page = 1 + } + if requestData.PageSize == 0 { + requestData.PageSize = 15 + } + var matrixInfoList []modelAppPlatform.MatrixContent + gormDb := overall.CONSTANT_DB_AppPlatform.Where("`state` = 1") + if requestData.KeyWords != "" { + gormDb = gormDb.Where("`name` like ?", "%"+requestData.KeyWords+"%") + } + if requestData.AdminOrg != 0 { + var sunOrg publicmethod.GetOrgAllParent + sunOrg.GetOrgSonAllId(requestData.AdminOrg) + sunOrg.Id = append(sunOrg.Id, requestData.AdminOrg) + gormDb = gormDb.Where("`org` IN ?", sunOrg.Id) + } + var total int64 + totalErr := gormDb.Count(&total).Error + if totalErr != nil { + total = 0 + } + gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) + err := gormDb.Find(&matrixInfoList).Error + if err != nil { + publicmethod.Result(105, err, c) + return + } + var sendList []SendMatrix + for _, v := range matrixInfoList { + var sendCont SendMatrix + sendCont.Id = v.Id + sendCont.Name = v.Name + sendCont.Center = v.Center + sendCont.Org = v.Org + var orgCont modelshr.AdministrativeOrganization + orgCont.GetCont(map[string]interface{}{"`id`": v.Org}, "`name`") + sendCont.OrgName = orgCont.Name + sendCont.State = v.State + sendCont.Time = v.Time + sendList = append(sendList, sendCont) + } + publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendList)), sendList, c) +} diff --git a/api/version1/matrixApi/type.go b/api/version1/matrixApi/type.go new file mode 100644 index 0000000..bdea5bd --- /dev/null +++ b/api/version1/matrixApi/type.go @@ -0,0 +1,34 @@ +package matrixapi + +import ( + "appPlatform/overall/publicmethod" + + "github.com/gin-gonic/gin" +) + +type ApiMethod struct{} + +// 权限矩阵入口 +func (a *ApiMethod) Index(c *gin.Context) { + outputCont := publicmethod.MapOut[string]() + outputCont["index"] = "权限矩阵入口" + publicmethod.Result(0, outputCont, c) +} + +// 获取矩阵列表参数 +type SearchMatrix struct { + publicmethod.PagesTurn + KeyWords string `json:"keywords"` + AdminOrg int64 `json:"adminorg"` +} + +// 输出权限矩阵列表 +type SendMatrix struct { + Id int `json:"id"` + Name string `json:"name"` + Center string `json:"center"` + Org int64 `json:"org"` + OrgName string `json:"orgname"` + State int `json:"status"` + Time int64 `json:"time"` +} diff --git a/api/version1/menus/menus.go b/api/version1/menus/menus.go index a9ef10e..dc68bf7 100644 --- a/api/version1/menus/menus.go +++ b/api/version1/menus/menus.go @@ -5,6 +5,7 @@ import ( "appPlatform/overall" "appPlatform/overall/publicmethod" "fmt" + "sort" "time" "github.com/gin-gonic/gin" @@ -29,11 +30,14 @@ import ( */ func (a *ApiMethod) GetMenusThree(c *gin.Context) { var menusList []modelAppPlatform.Menus - err := overall.CONSTANT_DB_AppPlatform.Where("`type` IN ? AND `visible` IN ?", []int{1, 2, 3}, []int{1, 2}).Find(&menusList).Error + err := overall.CONSTANT_DB_AppPlatform.Where("`type` IN ? AND `visible` IN ? AND `outside` IN ?", []int{1, 2, 3}, []int{1, 2}, []int{1, 3}).Order("sort ASC").Find(&menusList).Error if err != nil && len(menusList) < 1 { publicmethod.Result(1, err, c, "没有路由!") return } + // sort.Slice(menusList, func(i, j int) bool { + // return menusList[i].Sort > menusList[j].Sort + // }) routerThree := publicmethod.GetMenuRouterThree(0, menusList) publicmethod.Result(0, routerThree, c) } @@ -72,6 +76,9 @@ func (a *ApiMethod) GetMenusListTree(c *gin.Context) { publicmethod.Result(1, err, c, "没有路由!") return } + sort.Slice(menusList, func(i, j int) bool { + return menusList[i].Sort < menusList[j].Sort + }) routerThree := publicmethod.GetAppMenuThree(0, menusList) publicmethod.Result(0, routerThree, c) } @@ -134,6 +141,9 @@ func (a *ApiMethod) AddNewMenu(c *gin.Context) { if requestData.Sort == 0 { requestData.Sort = 50 } + if requestData.Outside == 0 { + requestData.Sort = 1 + } types := publicmethod.MenuTypeToInt(requestData.Types) var menuCont modelAppPlatform.Menus menuCont.Name = requestData.Name //菜单名称"` @@ -157,6 +167,7 @@ func (a *ApiMethod) AddNewMenu(c *gin.Context) { menuCont.Redirect = requestData.Redirect //跳转路径"` menuCont.ParentId = requestData.ParentId //父菜单ID"` menuCont.Time = time.Now().Unix() //创建时间"` + menuCont.Outside = requestData.Outside //1:内部使用;2:外部使用;3:内外使用"` err := overall.CONSTANT_DB_AppPlatform.Create(&menuCont).Error if err != nil { publicmethod.Result(104, err, c) @@ -210,6 +221,7 @@ func (a *ApiMethod) GetOneMenuCont(c *gin.Context) { sendCont.Path = menuCont.Path //路由路径 sendCont.Redirect = menuCont.Redirect //跳转路由路径 sendCont.Types = publicmethod.MenuType(menuCont.Types) //菜单类型 + sendCont.Outside = menuCont.Outside publicmethod.Result(0, sendCont, c) } @@ -247,6 +259,9 @@ func (a *ApiMethod) EditMenusCont(c *gin.Context) { if requestData.Sort == 0 { requestData.Sort = 50 } + if requestData.Outside == 0 { + requestData.Outside = 1 + } whe := publicmethod.MapOut[string]() whe["`id`"] = requestData.Id var menuCont modelAppPlatform.Menus @@ -302,6 +317,9 @@ func (a *ApiMethod) EditMenusCont(c *gin.Context) { if len(editCont) > 0 { editCont["time"] = time.Now().Unix() } + if requestData.Outside != menuCont.Outside { + editCont["outside"] = requestData.Outside + } err = menuCont.EiteCont(whe, editCont) if err != nil { publicmethod.Result(106, err, c) diff --git a/api/version1/menus/type.go b/api/version1/menus/type.go index 08ea5c3..112750c 100644 --- a/api/version1/menus/type.go +++ b/api/version1/menus/type.go @@ -52,6 +52,7 @@ type AddNewMenuCont struct { Path string `json:"path"` //路由路径 Redirect string `json:"redirect"` //跳转路由路径 Types string `json:"type"` //菜单类型 + Outside int `json:"outside"` //排序 } // 边界菜单 diff --git a/api/version1/user/userCont.go b/api/version1/user/userCont.go index 931d8ce..b4e9bf4 100644 --- a/api/version1/user/userCont.go +++ b/api/version1/user/userCont.go @@ -6,7 +6,6 @@ import ( "appPlatform/overall" "appPlatform/overall/publicmethod" "encoding/json" - "fmt" "strconv" "strings" @@ -57,11 +56,12 @@ func (a *ApiMethod) GetUserCont(c *gin.Context) { sendData.OrganizationName = orgCont.Name //行政组织名称 sendData.Avatar = myContInfo.Icon roleList := strings.Split(myContInfo.Role, ",") - roleList = append(roleList, "ROOT") + // roleList = append(roleList, "ROOT") sendData.Roles = roleList //获取权限 - menuPoint, opeart, orgList := GetUserPower("app", myContInfo.Position, roleList) - fmt.Printf("menuPoint======>%v\nopeart======>%v\norgList======>%v\n", menuPoint, opeart, orgList) + menuPoint, _, _ := GetUserPower("appsystem", myContInfo.Position, roleList) + // menuPoint, opeart, orgList := GetUserPower("appsystem", myContInfo.Position, roleList) + // fmt.Printf("menuPoint======>%v\nopeart======>%v\norgList======>%v\n", menuPoint, opeart, orgList) sendData.Perms = menuPoint publicmethod.Result(0, sendData, c) } diff --git a/apirouter/entry.go b/apirouter/entry.go index 1e2ec95..589b740 100644 --- a/apirouter/entry.go +++ b/apirouter/entry.go @@ -4,6 +4,7 @@ import ( "appPlatform/apirouter/apishiyan" dictrouters "appPlatform/apirouter/v1/dict_routers" "appPlatform/apirouter/v1/grantsystempower" + matrixrouters "appPlatform/apirouter/v1/matrixRouters" menusrouters "appPlatform/apirouter/v1/menusRouters" userrouters "appPlatform/apirouter/v1/userRouters" ) @@ -15,6 +16,7 @@ type RouterGroup struct { MenusRouter menusrouters.ApiRouter DictRouter dictrouters.ApiRouter GrantPowerRouter grantsystempower.ApiRouter + MatrixApiRouter matrixrouters.ApiRouter } var RouterGroupEntry = new(RouterGroup) diff --git a/apirouter/v1/matrixRouters/pc.go b/apirouter/v1/matrixRouters/pc.go new file mode 100644 index 0000000..41b1746 --- /dev/null +++ b/apirouter/v1/matrixRouters/pc.go @@ -0,0 +1,19 @@ +package matrixrouters + +import ( + "appPlatform/api/version1" + + "github.com/gin-gonic/gin" +) + +// 权限矩阵PC端 +func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { + apiRouter := router.Group("matrix") + + var methodBinding = version1.AppApiEntry.MatrixApi + { + apiRouter.GET("", methodBinding.Index) //入口 + apiRouter.POST("", methodBinding.Index) //入口 + apiRouter.POST("matrixlist", methodBinding.MatrixList) //矩阵列表 + } +} diff --git a/apirouter/v1/matrixRouters/types.go b/apirouter/v1/matrixRouters/types.go new file mode 100644 index 0000000..ddc4097 --- /dev/null +++ b/apirouter/v1/matrixRouters/types.go @@ -0,0 +1,4 @@ +package matrixrouters + +//权限矩阵路由 +type ApiRouter struct{} diff --git a/initialization/route/initRoute.go b/initialization/route/initRoute.go index 6ffcee7..9058fbf 100644 --- a/initialization/route/initRoute.go +++ b/initialization/route/initRoute.go @@ -51,7 +51,9 @@ func InitialRouter() *gin.Engine { //配置权限路由 trantPowersRouterApi := apirouter.RouterGroupEntry.GrantPowerRouter trantPowersRouterApi.RouterGroupPc(VerifyIdentity) - + //权限矩阵 + matrixRouterApi := apirouter.RouterGroupEntry.MatrixApiRouter + matrixRouterApi.RouterGroupPc(VerifyIdentity) } //验证身份接口 无需鉴权Url(主要web端使用) VerifyIdentityWeb := router.Group("") diff --git a/models/modelAppPlatform/matrix_content.go b/models/modelAppPlatform/matrix_content.go new file mode 100644 index 0000000..806d4ad --- /dev/null +++ b/models/modelAppPlatform/matrix_content.go @@ -0,0 +1,61 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 权限矩阵基础信息表 +type MatrixContent struct { + Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:名称"` + Center string `json:"center" gorm:"column:center;type:mediumtext;default:'';comment:描述"` + Org int64 `json:"org" gorm:"column:org;type:bigint(20) unsigned;default:0;not null;comment:归属行政组织"` + State int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` + Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` +} + +func (MatrixContent *MatrixContent) TableName() string { + return "matrix_content" +} + +// 编辑内容 +func (cont *MatrixContent) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *MatrixContent) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *MatrixContent) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *MatrixContent) ContMap(whereMap interface{}, field ...string) (countAry []MatrixContent, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *MatrixContent) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelAppPlatform/matrix_frame.go b/models/modelAppPlatform/matrix_frame.go new file mode 100644 index 0000000..8a8535b --- /dev/null +++ b/models/modelAppPlatform/matrix_frame.go @@ -0,0 +1,61 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 权限矩阵基础字段框架表 +type MatrixFrame struct { + Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:名称"` + Types int `json:"type" gorm:"column:type;type:int(1);default:1;not null;comment:骨架类型(1:人力资源;2:行政组织;2:分部;)"` + Condition int `json:"condition" gorm:"column:condition;type:int(1) unsigned;default:2;not null;comment:骨架取值类型(1:作为条件使用;2:作为取值使用)"` + State int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` + Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` +} + +func (MatrixFrame *MatrixFrame) TableName() string { + return "matrix_frame" +} + +// 编辑内容 +func (cont *MatrixFrame) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *MatrixFrame) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *MatrixFrame) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *MatrixFrame) ContMap(whereMap interface{}, field ...string) (countAry []MatrixFrame, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *MatrixFrame) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelAppPlatform/matrix_handler.go b/models/modelAppPlatform/matrix_handler.go new file mode 100644 index 0000000..fb4e2d8 --- /dev/null +++ b/models/modelAppPlatform/matrix_handler.go @@ -0,0 +1,63 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 权限矩阵基础字段框架表 +type MatrixHandler struct { + Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + Number int64 `json:"number" gorm:"column:number;type:bigint(20) unsigned;default:0;not null;comment:批号"` + Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:使用者名称"` + HandId int64 `json:"handid" gorm:"column:hand_id;type:bigint(20) unsigned;default:0;not null;comment:使用者标识符"` + Types int `json:"types" gorm:"column:types;type:int(1);default:1;not null;comment:骨架类型(1:人力资源;2:行政组织;2:分部;)"` + McId int64 `json:"mcid" gorm:"column:mc_id;type:bigint(20) unsigned;default:0;not null;comment:矩阵ID"` + MhId int64 `json:"mhid" gorm:"column:mh_id;type:bigint(20) unsigned;default:0;not null;comment:骨架ID"` + Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` +} + +func (MatrixHandler *MatrixHandler) TableName() string { + return "matrix_handler" +} + +// 编辑内容 +func (cont *MatrixHandler) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *MatrixHandler) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *MatrixHandler) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *MatrixHandler) ContMap(whereMap interface{}, field ...string) (countAry []MatrixHandler, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *MatrixHandler) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelAppPlatform/menus.go b/models/modelAppPlatform/menus.go index baff404..91e5b51 100644 --- a/models/modelAppPlatform/menus.go +++ b/models/modelAppPlatform/menus.go @@ -19,6 +19,7 @@ type Menus struct { Redirect string `json:"redirect" gorm:"column:redirect;type:varchar(255) ;default:'';comment:跳转路径"` ParentId int `json:"parentId" gorm:"column:parentId;type:int(5) unsigned;default:0;not null;comment:父菜单ID"` Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` + Outside int `json:"outside" gorm:"column:outside;type:int(1) unsigned;default:0;not null;comment:1:内部使用;2:外部使用;3:内外使用"` } func (menus *Menus) TableName() string { diff --git a/overall/publicmethod/technique.go b/overall/publicmethod/technique.go index d2fb028..52824df 100644 --- a/overall/publicmethod/technique.go +++ b/overall/publicmethod/technique.go @@ -2149,6 +2149,7 @@ func GetMenuRouterThree(parentId int, threeData []modelAppPlatform.Menus) []Menu node.Redirect = v.Redirect //跳转链接 node.Name = v.Name //路由名称 var metaCont MenusRouterThreeMet + metaCont.Perm = strconv.FormatInt(v.Perm, 10) metaCont.Title = v.Name //路由title metaCont.Icon = v.Icon //ICON if v.Visible == 1 { diff --git a/overall/publicmethod/type.go b/overall/publicmethod/type.go index 46c0e4e..6fed436 100644 --- a/overall/publicmethod/type.go +++ b/overall/publicmethod/type.go @@ -308,6 +308,7 @@ type MenusRouterThree struct { // 路由属性类型 type MenusRouterThreeMet struct { + Perm string `json:"perm"` Title string `json:"title"` //路由title Icon string `json:"icon"` //ICON Hidden bool `json:"hidden"` //否隐藏