You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
313 lines
9.6 KiB
313 lines
9.6 KiB
package authentication
|
|
|
|
import (
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/models/modelssystempermission"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"fmt"
|
|
"sort"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-10-23 09:07:27
|
|
@ 功能: 获取角色树
|
|
*/
|
|
func (a *RoleApiMethod) GiveRoleTree(c *gin.Context) {
|
|
var roleList []modelssystempermission.SystemRole
|
|
err := overall.CONSTANT_DB_System_Permission.Where("`state` IN (1,2)").Find(&roleList).Error
|
|
var sendRoleList []RolePower
|
|
if err != nil || len(roleList) < 1 {
|
|
publicmethod.Result(0, sendRoleList, c)
|
|
return
|
|
}
|
|
sort.Slice(roleList, func(i, j int) bool {
|
|
return roleList[i].Sort < roleList[j].Sort
|
|
})
|
|
sendRoleList = InfiniteRoleTree(0, roleList)
|
|
publicmethod.Result(0, sendRoleList, c)
|
|
}
|
|
|
|
// 递归无线角色菜单
|
|
func InfiniteRoleTree(parentId int64, threeData []modelssystempermission.SystemRole) []RolePower {
|
|
var roleTree []RolePower
|
|
for _, v := range threeData {
|
|
if v.Superior == parentId {
|
|
var roleInfo RolePower
|
|
roleInfo.Id = strconv.FormatInt(v.Id, 10)
|
|
roleInfo.Label = v.Name
|
|
roleInfo.Types = strconv.Itoa(v.Types)
|
|
if v.State == 1 {
|
|
roleInfo.Status = true
|
|
} else {
|
|
roleInfo.Status = false
|
|
}
|
|
roleInfo.Superior = strconv.FormatInt(v.Superior, 10)
|
|
roleInfo.Sort = v.Sort
|
|
roleInfo.Children = InfiniteRoleTree(v.Id, threeData)
|
|
roleTree = append(roleTree, roleInfo)
|
|
}
|
|
}
|
|
return roleTree
|
|
}
|
|
|
|
// 获取角色分组树
|
|
func (a *RoleApiMethod) GiveRoleGroupTree(c *gin.Context) {
|
|
var roleList []modelssystempermission.SystemRole
|
|
err := overall.CONSTANT_DB_System_Permission.Where("`state` IN (1,2) AND `types` = 2").Find(&roleList).Error
|
|
var sendRoleList []RolePower
|
|
if err != nil || len(roleList) < 1 {
|
|
publicmethod.Result(0, sendRoleList, c)
|
|
return
|
|
}
|
|
sort.Slice(roleList, func(i, j int) bool {
|
|
return roleList[i].Sort < roleList[j].Sort
|
|
})
|
|
sendRoleList = InfiniteRoleTree(0, roleList)
|
|
publicmethod.Result(0, sendRoleList, c)
|
|
}
|
|
|
|
// 编辑角色组
|
|
func (a *RoleApiMethod) EditRoleCont(c *gin.Context) {
|
|
var request EditInfoRole
|
|
err := c.ShouldBindJSON(&request)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
roleType := 2
|
|
if request.Types == "" {
|
|
roleType = 2
|
|
} else {
|
|
roleType, _ = strconv.Atoi(request.Types)
|
|
}
|
|
if request.Id == "" || request.Id == "0" {
|
|
err = AddRoleCont(request)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
} else {
|
|
var roleInfo modelssystempermission.SystemRole
|
|
err = roleInfo.GetCont(map[string]interface{}{"`id`": request.Id})
|
|
if err != nil || roleInfo.Id == 0 {
|
|
err = AddRoleCont(request)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
} else {
|
|
saveData := publicmethod.MapOut[string]()
|
|
if request.Name != "" && request.Name != roleInfo.Name {
|
|
saveData["name"] = request.Name
|
|
}
|
|
if request.Sort != 0 && request.Sort != roleInfo.Sort {
|
|
saveData["sort"] = request.Sort
|
|
}
|
|
var roleSuper int64
|
|
if request.Superior != "" {
|
|
roleSuper, _ = strconv.ParseInt(request.Superior, 10, 64)
|
|
}
|
|
if roleSuper != roleInfo.Superior {
|
|
saveData["superior"] = roleSuper
|
|
}
|
|
if roleType != roleInfo.Types {
|
|
saveData["types"] = roleType
|
|
}
|
|
if len(saveData) > 0 {
|
|
saveData["`time`"] = time.Now().Unix()
|
|
var saveRoleInfo modelssystempermission.SystemRole
|
|
err = saveRoleInfo.EiteCont(map[string]interface{}{"`id`": roleInfo.Id}, saveData)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-10-23 15:06:53
|
|
@ 功能: 新增角色
|
|
*/
|
|
func AddRoleCont(saveData EditInfoRole) (err error) {
|
|
roleType := 2
|
|
if saveData.Types == "" {
|
|
roleType = 2
|
|
} else {
|
|
roleType, _ = strconv.Atoi(saveData.Types)
|
|
}
|
|
var saveRoleInfo modelssystempermission.SystemRole
|
|
saveRoleInfo.Name = saveData.Name //系统名称"`
|
|
saveRoleInfo.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
saveRoleInfo.Time = time.Now().Unix() //创建时间"`
|
|
saveRoleInfo.Sort = saveData.Sort //排序"`
|
|
saveRoleInfo.Types = roleType //类型"`
|
|
saveRoleInfo.Superior, _ = strconv.ParseInt(saveData.Superior, 10, 64) //上级"`
|
|
err = overall.CONSTANT_DB_System_Permission.Create(&saveRoleInfo).Error
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-10-23 16:52:54
|
|
@ 功能: 修改角色状态
|
|
*/
|
|
func (a *RoleApiMethod) EditRoleStatus(c *gin.Context) {
|
|
var request EditRoleState
|
|
err := c.ShouldBindJSON(&request)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
if request.Id == "" {
|
|
publicmethod.Result(1, err, c, "未知角色!")
|
|
return
|
|
}
|
|
var roleInfo modelssystempermission.SystemRole
|
|
err = roleInfo.GetCont(map[string]interface{}{"`id`": request.Id})
|
|
if err != nil || roleInfo.Id == 0 {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
var allSunId GetAllSunId
|
|
allSunId.GaveMySunAll(roleInfo.Id)
|
|
allSunId.Id = append(allSunId.Id, roleInfo.Id)
|
|
if request.Status == 0 {
|
|
request.Status = 1
|
|
}
|
|
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["`state`"] = request.Status
|
|
saveData["`time`"] = time.Now().Unix()
|
|
var saveRoleInfo modelssystempermission.SystemRole
|
|
// err = saveRoleInfo.EiteCont(map[string]interface{}{"`id`": request.Id}, saveData)
|
|
err = overall.CONSTANT_DB_System_Permission.Model(&saveRoleInfo).Where("`id` IN ?", allSunId.Id).Updates(saveData).Error
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
// 获取所有子集
|
|
func (g *GetAllSunId) GaveMySunAll(parentId int64) {
|
|
var id []int64
|
|
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Select("`id`").Where("`superior` = ?", parentId).Find(&id)
|
|
if len(id) > 0 {
|
|
for _, v := range id {
|
|
if v != 0 {
|
|
if !publicmethod.IsInTrue[int64](v, g.Id) {
|
|
g.Id = append(g.Id, v)
|
|
}
|
|
g.GaveMySunAll(v)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 获取行政组织加岗位树
|
|
func (a *RoleApiMethod) GetOrgPostTree(c *gin.Context) {
|
|
var request publicmethod.PublicId
|
|
c.ShouldBindJSON(&request)
|
|
var orgId int64
|
|
var sunOrgList publicmethod.GetOrgAllParent
|
|
if request.Id != "" {
|
|
orgId, _ = strconv.ParseInt(request.Id, 10, 64)
|
|
if orgId != 0 {
|
|
sunOrgList.GetOrgSun(orgId)
|
|
}
|
|
if len(sunOrgList.Id) > 0 {
|
|
sunOrgList.Id = append(sunOrgList.Id, orgId)
|
|
}
|
|
} else {
|
|
orgId = 0
|
|
}
|
|
var list []modelshr.OrgCont
|
|
var postList []modelshr.Position
|
|
if len(sunOrgList.Id) > 0 {
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.OrgCont{}).Where("`state` = 1 AND `id` IN ?", sunOrgList.Id).Find(&list)
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Where("`state` = 1 AND `administrative_organization` IN ?", sunOrgList.Id).Find(&postList)
|
|
} else {
|
|
if orgId > 0 {
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.OrgCont{}).Where("`state` = 1 AND `id` = ?", orgId).Find(&list)
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Where("`state` = 1 and `administrative_organization` = ?", orgId).Find(&postList)
|
|
} else {
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.OrgCont{}).Where("`state` = 1").Find(&list)
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Where("`state` = 1").Find(&postList)
|
|
}
|
|
|
|
}
|
|
|
|
var allList []OrgPostPower
|
|
for _, v := range list {
|
|
var orgInfo OrgPostPower
|
|
orgInfo.Id = strconv.FormatInt(v.Id, 10) //string `json:"id"`
|
|
orgInfo.Label = v.Name //string `json:"label"`
|
|
orgInfo.Types = strconv.FormatInt(v.Level, 10) // string `json:"types"`
|
|
orgInfo.TypeName = v.TypeName
|
|
orgInfo.Status = false //bool `json:"status"`
|
|
orgInfo.Superior = strconv.FormatInt(v.Superior, 10) //string `json:"superior"`
|
|
orgInfo.Key = fmt.Sprintf("o_%v", v.Id)
|
|
orgInfo.Sort = v.Sort //int `json:"sort"`
|
|
allList = append(allList, orgInfo)
|
|
}
|
|
|
|
for i, v := range postList {
|
|
var positInfo OrgPostPower
|
|
positInfo.Id = strconv.FormatInt(v.Id, 10) //string `json:"id"`
|
|
positInfo.Label = v.Name //string `json:"label"`
|
|
positInfo.Types = "9"
|
|
positInfo.TypeName = "岗位" // string `json:"types"`
|
|
positInfo.Status = true //bool `json:"status"`
|
|
positInfo.Superior = strconv.FormatInt(v.AdministrativeOrganization, 10) //string `json:"superior"`
|
|
positInfo.Key = fmt.Sprintf("p_%v", v.Id)
|
|
positInfo.Sort = i //int `json:"sort"`
|
|
allList = append(allList, positInfo)
|
|
}
|
|
|
|
sort.Slice(allList, func(i, j int) bool {
|
|
return allList[i].Types < allList[j].Types
|
|
})
|
|
// publicmethod.Result(0, allList, c)
|
|
orgIdStr := strconv.FormatInt(orgId, 10)
|
|
var orgPostTree []OrgPostisTree
|
|
orgPostTree = InfiniteOrgPostTree(orgIdStr, allList)
|
|
publicmethod.Result(0, orgPostTree, c)
|
|
}
|
|
|
|
// 递归无线行政组织与岗位菜单
|
|
func InfiniteOrgPostTree(parentId string, threeData []OrgPostPower) []OrgPostisTree {
|
|
var roleTree []OrgPostisTree
|
|
for _, v := range threeData {
|
|
if v.Superior == parentId {
|
|
var roleInfo OrgPostisTree
|
|
roleInfo.Id = v.Id //string `json:"id"`
|
|
roleInfo.Label = v.Label //string `json:"label"`
|
|
roleInfo.Types = v.Types // string `json:"types"`
|
|
roleInfo.TypeName = v.TypeName
|
|
roleInfo.Status = v.Status //bool `json:"status"`
|
|
roleInfo.Superior = v.Superior //string `json:"superior"`
|
|
roleInfo.Key = v.Key
|
|
roleInfo.Sort = v.Sort //int `json:"sort"`
|
|
if v.Types != "9" {
|
|
roleInfo.Children = InfiniteOrgPostTree(v.Id, threeData)
|
|
}
|
|
roleTree = append(roleTree, roleInfo)
|
|
}
|
|
}
|
|
return roleTree
|
|
}
|
|
|