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.
498 lines
15 KiB
498 lines
15 KiB
package authentication
|
|
|
|
import (
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/models/modelssystempermission"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"fmt"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"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
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2026-01-09 10:14:27
|
|
@ 功能: 校队角色人员信息
|
|
*/
|
|
func (a *RoleApiMethod) VerifyInformationRolePersonnel(c *gin.Context) {
|
|
var manList []modelshr.PersonArchives
|
|
// overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`key`,`number`,`role`").Where("`role` <> ?", "").Find(&manList)
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`key`,`number`,`role`").Find(&manList)
|
|
var newManAry []modelshr.PersonArchives
|
|
var userAry []JiaoDuiRole
|
|
var roleListAry JdsjRoel
|
|
for _, v := range manList {
|
|
if v.Role != "" && v.Role != "null" {
|
|
newManAry = append(newManAry, v)
|
|
roleAry := strings.Split(v.Role, ",")
|
|
// NewWriteRole(v.Key, roleAry)
|
|
|
|
var userCont JiaoDuiRole
|
|
userCont.UserKey = strconv.FormatInt(v.Key, 10)
|
|
userCont.RoleAry = roleAry
|
|
// if len(userAry) < 199 {
|
|
// userAry = append(userAry, userCont)
|
|
// } else {
|
|
// userAry = append(userAry, userCont)
|
|
// syncSeting.Add(1)
|
|
// // go XieChengRoleXd(userAry)
|
|
// go roleListAry.XieChengRoleAry(userAry)
|
|
// userAry = []JiaoDuiRole{}
|
|
// }
|
|
userAry = append(userAry, userCont)
|
|
syncSeting.Add(1)
|
|
// go XieChengRoleXd(userAry)
|
|
go roleListAry.XieChengRoleAry(userAry)
|
|
// break
|
|
}
|
|
}
|
|
if len(userAry) > 0 {
|
|
syncSeting.Add(1)
|
|
// go XieChengRoleXd(userAry)
|
|
go roleListAry.XieChengRoleAry(userAry)
|
|
userAry = []JiaoDuiRole{}
|
|
}
|
|
syncSeting.Wait()
|
|
|
|
fmt.Printf("总共%v人员赋权\n\n%v", len(newManAry), len(manList))
|
|
publicmethod.Result(0, roleListAry, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2026-01-09 11:45:38
|
|
@ 功能: 协程处理数据
|
|
*/
|
|
func (j *JdsjRoel) XieChengRoleAry(userAry []JiaoDuiRole) {
|
|
syncSeting.Done()
|
|
for _, v := range userAry {
|
|
fmt.Printf("协程处理数据--->%v\n\n", v.UserKey)
|
|
for _, rv := range v.RoleAry {
|
|
fmt.Printf("协程处理数据--1->%v\n\n", rv)
|
|
j.RoleAddUserKey(v.UserKey, rv)
|
|
// if len(j.RoleList) > 0 {
|
|
// isNew := true
|
|
// for ji, jv := range j.RoleList {
|
|
// if jv.RoleId == rv {
|
|
// isNew = false
|
|
// // fmt.Printf("%v--------------->%v\n\n\n", jv.RoleId, !publicmethod.IsInTrue[string](v.UserKey, jv.UserList))
|
|
// if !publicmethod.IsInTrue[string](v.UserKey, jv.UserList) {
|
|
|
|
// jv.UserList = append(jv.UserList, v.UserKey)
|
|
// }
|
|
// }
|
|
// j.RoleList[ji] = jv
|
|
// }
|
|
// if isNew {
|
|
// var kj RoleUserArt
|
|
// kj.RoleId = rv
|
|
// kj.UserList = append(kj.UserList, v.UserKey)
|
|
// j.RoleList = append(j.RoleList, kj)
|
|
// }
|
|
// } else {
|
|
// var kj RoleUserArt
|
|
// kj.RoleId = rv
|
|
// kj.UserList = append(kj.UserList, v.UserKey)
|
|
// j.RoleList = append(j.RoleList, kj)
|
|
// }
|
|
|
|
}
|
|
}
|
|
}
|
|
func (j *JdsjRoel) RoleAddUserKey(userKey, roleId string) {
|
|
isNewAdd := true
|
|
for i, v := range j.RoleList {
|
|
if v.RoleId == roleId {
|
|
if !publicmethod.IsInTrue[string](userKey, v.UserList) {
|
|
j.RoleList[i].UserList = append(j.RoleList[i].UserList, userKey)
|
|
isNewAdd = false
|
|
}
|
|
}
|
|
}
|
|
if isNewAdd {
|
|
var newRoleUs RoleUserArt
|
|
newRoleUs.RoleId = roleId
|
|
newRoleUs.UserList = append(newRoleUs.UserList, userKey)
|
|
j.RoleList = append(j.RoleList, newRoleUs)
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2026-01-09 11:23:59
|
|
@ 功能: 协程处理角色问题
|
|
*/
|
|
func XieChengRoleXd(userAry []JiaoDuiRole) {
|
|
syncSeting.Done()
|
|
fmt.Printf("协程处理角色问题--->%v\n\n", len(userAry))
|
|
for _, v := range userAry {
|
|
for _, rv := range v.RoleAry {
|
|
var roleCont modelssystempermission.SystemRole
|
|
roleCont.GetCont(map[string]interface{}{"`id`": rv}, "`id`", "`roleuser`")
|
|
if roleCont.Id != 0 {
|
|
if roleCont.Roleuser != "" && roleCont.Roleuser != "null" {
|
|
roleAry := strings.Split(roleCont.Roleuser, ",") //原角色已有的人员
|
|
if !publicmethod.IsInTrue[string](v.UserKey, roleAry) { //当原角色不存在此人员时加载
|
|
roleAry = append(roleAry, v.UserKey)
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["`roleuser`"] = strings.Join(roleAry, ",")
|
|
saveData["`time`"] = time.Now().Unix()
|
|
var roleContSave modelssystempermission.SystemRole
|
|
roleContSave.EiteCont(map[string]interface{}{"`id`": roleCont.Id}, saveData)
|
|
}
|
|
} else {
|
|
var newRoleMan []string
|
|
newRoleMan = append(newRoleMan, v.UserKey)
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["`roleuser`"] = strings.Join(newRoleMan, ",")
|
|
saveData["`time`"] = time.Now().Unix()
|
|
var roleContSave modelssystempermission.SystemRole
|
|
roleContSave.EiteCont(map[string]interface{}{"`id`": roleCont.Id}, saveData)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2026-01-09 10:39:43
|
|
@ 功能: 写入新角色系统
|
|
*/
|
|
func NewWriteRole(userKey int64, roleAry []string) {
|
|
fmt.Printf("%v人员有赋权----------》%v\n\n", userKey, len(roleAry))
|
|
for _, v := range roleAry {
|
|
var roleCont modelssystempermission.SystemRole
|
|
roleCont.GetCont(map[string]interface{}{"`id`": v}, "`id`", "`roleuser`")
|
|
if roleCont.Id != 0 {
|
|
userKeyVal := strconv.FormatInt(userKey, 10)
|
|
if roleCont.Roleuser != "" && roleCont.Roleuser != "null" {
|
|
roleAry := strings.Split(roleCont.Roleuser, ",")
|
|
if !publicmethod.IsInTrue[string](userKeyVal, roleAry) {
|
|
roleAry = append(roleAry, userKeyVal)
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["`roleuser`"] = strings.Join(roleAry, ",")
|
|
saveData["`time`"] = time.Now().Unix()
|
|
var roleContSave modelssystempermission.SystemRole
|
|
roleContSave.EiteCont(map[string]interface{}{"`id`": roleCont.Id}, saveData)
|
|
}
|
|
} else {
|
|
var newRoleMan []string
|
|
newRoleMan = append(newRoleMan, userKeyVal)
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["`roleuser`"] = strings.Join(newRoleMan, ",")
|
|
saveData["`time`"] = time.Now().Unix()
|
|
var roleContSave modelssystempermission.SystemRole
|
|
roleContSave.EiteCont(map[string]interface{}{"`id`": roleCont.Id}, saveData)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|