package setupRoule
import (
"appPlatform/models/modelshr"
"appPlatform/models/modelssystempermission"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"fmt"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 0 9 : 25 : 55
@ 功能 : 获取首层子行政组织和本组织下的人员
* /
func ( a * ApiMethod ) GetMyPeopleAndSunOrg ( c * gin . Context ) {
var requestData HaveOrgLeveID
err := c . ShouldBindJSON ( & requestData )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if requestData . Id == "" {
requestData . Id = "0"
}
orgId , _ := strconv . ParseInt ( requestData . Id , 10 , 64 )
var snedList [ ] TopSunOrgAndPeople
if requestData . Level == 0 {
if requestData . Id == "0" {
orgList := GetOrgList ( orgId )
snedList = append ( snedList , orgList ... )
// orgManList := GetOrgPeopleList(orgId)
// snedList = append(snedList, orgManList...)
} else {
var myOrgMyInfo modelshr . AdministrativeOrganization
err = myOrgMyInfo . GetCont ( map [ string ] interface { } { "`id`" : requestData . Id } , "`id`,`name`" )
if err != nil {
publicmethod . Result ( 0 , err , c , "没有此行政组织" )
return
}
var sendMyInfo TopSunOrgAndPeople
sendMyInfo . Id = strconv . FormatInt ( myOrgMyInfo . Id , 10 )
sendMyInfo . Name = myOrgMyInfo . Name
sendMyInfo . Types = 1
sendMyInfo . IsLeaf = false
snedList = append ( snedList , sendMyInfo )
// orgManList := GetOrgPeopleList(orgId)
// snedList = append(snedList, orgManList...)
}
} else {
orgList := GetOrgList ( orgId )
snedList = append ( snedList , orgList ... )
}
publicmethod . Result ( 0 , snedList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 11 : 03 : 47
@ 功能 : 获取行政组织列表
* /
func GetOrgList ( orgId int64 ) ( snedList [ ] TopSunOrgAndPeople ) {
var orgList [ ] modelshr . AdministrativeOrganization
overall . CONSTANT_DB_HR . Model ( & modelshr . AdministrativeOrganization { } ) . Select ( "`id`,`name`" ) . Where ( "`state` = 1 AND `superior` = ?" , orgId ) . Find ( & orgList )
if len ( orgList ) > 0 {
for _ , v := range orgList {
var sendInfo TopSunOrgAndPeople
sendInfo . Id = strconv . FormatInt ( v . Id , 10 )
sendInfo . Name = v . Name
sendInfo . Types = 1
sendInfo . IsLeaf = false
snedList = append ( snedList , sendInfo )
}
}
orgManList := GetOrgPeopleList ( orgId )
snedList = append ( snedList , orgManList ... )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 11 : 03 : 47
@ 功能 : 获取行政组织岗位
* /
func GetOrgPostPeopleList ( postId int64 ) ( snedList [ ] TopSunOrgAndPeople ) {
var orgList [ ] modelshr . Position
overall . CONSTANT_DB_HR . Model ( & modelshr . Position { } ) . Select ( "`id`,`name`,`number`" ) . Where ( "`state` = 1 AND `administrative_organization` = ?" , postId ) . Find ( & orgList )
if len ( orgList ) > 0 {
for _ , v := range orgList {
var sendInfo TopSunOrgAndPeople
sendInfo . Id = strconv . FormatInt ( v . Id , 10 )
sendInfo . Name = v . Name
sendInfo . Types = 2
sendInfo . IsLeaf = false
snedList = append ( snedList , sendInfo )
}
}
// orgManList := GetPostPeopleList(postId)
// snedList = append(snedList, orgManList...)
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 11 : 03 : 47
@ 功能 : 获取行政组织人员
* /
func GetOrgPeopleList ( orgId int64 ) ( snedList [ ] TopSunOrgAndPeople ) {
var peopleList [ ] modelshr . PersonArchives
overall . CONSTANT_DB_HR . Model ( & modelshr . PersonArchives { } ) . Select ( "`id`,`key`,`name`,`number`" ) . Where ( "`state` = 1 AND `emp_type` BETWEEN 1 AND 10 AND `admin_org` = ?" , orgId ) . Find ( & peopleList )
if len ( peopleList ) > 0 {
for _ , v := range peopleList {
var sendInfo TopSunOrgAndPeople
sendInfo . Id = strconv . FormatInt ( v . Key , 10 )
sendInfo . Name = fmt . Sprintf ( "%v(%v)" , v . Name , v . Number )
sendInfo . Types = 3
sendInfo . IsLeaf = true
snedList = append ( snedList , sendInfo )
}
}
orgManList := GetOrgPostPeopleList ( orgId )
snedList = append ( snedList , orgManList ... )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 11 : 03 : 47
@ 功能 : 获取岗位人员
* /
func GetPostPeopleList ( orgId int64 ) ( snedList [ ] TopSunOrgAndPeople ) {
var peopleList [ ] modelshr . PersonArchives
overall . CONSTANT_DB_HR . Model ( & modelshr . PersonArchives { } ) . Select ( "`id`,`key`,`name`,`number`" ) . Where ( "`state` = 1 AND `emp_type` BETWEEN 1 AND 10 AND `position` = ?" , orgId ) . Find ( & peopleList )
if len ( peopleList ) > 0 {
for _ , v := range peopleList {
var sendInfo TopSunOrgAndPeople
sendInfo . Id = strconv . FormatInt ( v . Key , 10 )
sendInfo . Name = fmt . Sprintf ( "%v(%v)" , v . Name , v . Number )
sendInfo . Types = 3
sendInfo . IsLeaf = true
snedList = append ( snedList , sendInfo )
}
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 0 9 : 25 : 55
@ 功能 : 获取首层子行政组织和本组织下的岗位及人员
* /
func ( a * ApiMethod ) GetMyPeopleAndSunOrgPost ( c * gin . Context ) {
var requestData HaveOrgPostLeveID
err := c . ShouldBindJSON ( & requestData )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if requestData . Id == "" {
requestData . Id = "0"
}
if requestData . Types == 0 {
requestData . Types = 1
}
orgId , _ := strconv . ParseInt ( requestData . Id , 10 , 64 )
var snedList [ ] TopSunOrgAndPeople
if requestData . Level == 0 {
if requestData . Id == "0" {
orgList := GetOrgPostList ( orgId )
snedList = append ( snedList , orgList ... )
} else {
if requestData . Types == 1 {
orgList := GetOrgPostList ( orgId )
snedList = append ( snedList , orgList ... )
} else {
orgManList := GetPostPeopleList ( orgId )
snedList = append ( snedList , orgManList ... )
}
}
} else {
if requestData . Types == 1 {
orgList := GetOrgPostList ( orgId )
snedList = append ( snedList , orgList ... )
} else {
orgManList := GetPostPeopleList ( orgId )
snedList = append ( snedList , orgManList ... )
}
}
publicmethod . Result ( 0 , snedList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 11 : 03 : 47
@ 功能 : 获取行政组织列表
* /
func GetOrgPostList ( orgId int64 ) ( snedList [ ] TopSunOrgAndPeople ) {
var orgList [ ] modelshr . AdministrativeOrganization
overall . CONSTANT_DB_HR . Model ( & modelshr . AdministrativeOrganization { } ) . Select ( "`id`,`name`" ) . Where ( "`state` = 1 AND `superior` = ?" , orgId ) . Find ( & orgList )
if len ( orgList ) > 0 {
for _ , v := range orgList {
var sendInfo TopSunOrgAndPeople
sendInfo . Id = strconv . FormatInt ( v . Id , 10 )
sendInfo . Name = v . Name
sendInfo . Types = 1
sendInfo . IsLeaf = false
snedList = append ( snedList , sendInfo )
}
}
if orgId != 0 {
orgManList := GetOrgPostPeopleList ( orgId )
snedList = append ( snedList , orgManList ... )
}
return
}
/ *
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 13 11 : 03 : 47
@ 功能 : 获取行政组织岗位
* /
func GetPostPeopleListAry ( postId int64 ) ( snedList [ ] TopSunOrgAndPeople ) {
var orgList [ ] modelshr . Position
overall . CONSTANT_DB_HR . Model ( & modelshr . Position { } ) . Select ( "`id`,`name`,`number`" ) . Where ( "`state` = 1 AND `superior` = ?" , postId ) . Find ( & orgList )
if len ( orgList ) > 0 {
for _ , v := range orgList {
var sendInfo TopSunOrgAndPeople
sendInfo . Id = strconv . FormatInt ( v . Id , 10 )
sendInfo . Name = v . Name
sendInfo . Types = 2
sendInfo . IsLeaf = false
snedList = append ( snedList , sendInfo )
}
}
orgManList := GetPostPeopleList ( postId )
snedList = append ( snedList , orgManList ... )
return
}
// 获取人员
func ( a * ApiMethod ) GetPowerPageUser ( c * gin . Context ) {
var requestData PowerPageUser
c . ShouldBindJSON ( & requestData )
if requestData . Page == 0 {
requestData . Page = 1
}
if requestData . PageSize == 0 {
requestData . PageSize = 20
}
var peopleList [ ] modelshr . PersonArchives
gormDb := overall . CONSTANT_DB_HR . Model ( & modelshr . PersonArchives { } ) . Select ( "`id`,`key`,`name`,`number`,`icon`,`company`,`maindeparment`,`admin_org`,`icon_photo`" ) . Where ( "`state` = 1 AND `emp_type` BETWEEN 1 AND 10 " )
if requestData . Name != "" {
gormDb = gormDb . Where ( "`name` LIKE ? OR `number` LIKE ?" , "%" + requestData . Name + "%" , "%" + requestData . Name + "%" )
}
if requestData . OrgId != 0 {
var sunOrg publicmethod . GetOrgAllParent
sunOrg . GetOrgSun ( requestData . OrgId )
sunOrg . Id = append ( sunOrg . Id , requestData . OrgId )
gormDb = gormDb . Where ( "`admin_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 . Order ( "`id` DESC" ) . Find ( & peopleList ) . Error
if err != nil {
publicmethod . Result ( 105 , err , c )
return
}
var sendList [ ] SendPowerPage
for _ , v := range peopleList {
var sendCont SendPowerPage
sendCont . Id = strconv . FormatInt ( v . Key , 10 )
sendCont . Name = v . Name
sendCont . Code = v . Number
sendCont . Icon = v . IconPhoto
if v . Icon != "" {
sendCont . Icon = v . Icon
}
orgName := ""
if v . Company != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . Company } , "`name`" )
if orgCont . Name != "" {
orgName = orgCont . Name
}
}
if v . MainDeparment != 0 && v . MainDeparment != v . Company {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . MainDeparment } , "`name`" )
if orgCont . Name != "" {
orgName = fmt . Sprintf ( "%v-%v" , orgName , orgCont . Name )
} else {
orgName = orgCont . Name
}
}
if v . AdminOrg != 0 && v . AdminOrg != v . MainDeparment && v . AdminOrg != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . AdminOrg } , "`name`" )
if orgCont . Name != "" {
orgName = fmt . Sprintf ( "%v-%v" , orgName , orgCont . Name )
} else {
orgName = orgCont . Name
}
}
sendCont . Org = orgName
sendList = append ( sendList , sendCont )
}
publicmethod . ResultList ( 0 , requestData . Page , requestData . PageSize , total , int64 ( len ( sendList ) ) , sendList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 27 0 8 : 42 : 43
@ 功能 : 获取角色使用人
* /
func ( a * ApiMethod ) GetRolePeople ( c * gin . Context ) {
var requestData GetRolePople
c . ShouldBindJSON ( & requestData )
if requestData . RoleId == 0 {
publicmethod . Result ( 3 , requestData , c , "未知赋权项目!请明确!" )
return
}
var roleInfo modelssystempermission . SystemRole
err := overall . CONSTANT_DB_System_Permission . Model ( & roleInfo ) . Where ( "`id` = ?" , requestData . RoleId ) . First ( & roleInfo ) . Error
if err != nil {
publicmethod . Result ( 1 , requestData , c , "未知赋权项目!请明确!" )
return
}
outPut := publicmethod . MapOut [ string ] ( )
var sendList [ ] SendPowerPage
if roleInfo . Roleuser == "" {
outPut [ "userKey" ] = [ ] string { }
outPut [ "list" ] = sendList
publicmethod . Result ( 0 , outPut , c )
return
}
var userKey [ ] string
userKey = strings . Split ( roleInfo . Roleuser , "," )
// json.Unmarshal([]byte(roleInfo.Roleuser), &userKey)
var userList [ ] modelshr . PersonArchives
gormDb := overall . CONSTANT_DB_HR . Model ( & modelshr . PersonArchives { } ) . Select ( "`id`,`key`,`name`,`number`,`icon`,`company`,`maindeparment`,`admin_org`,`icon_photo`" ) . Where ( "`key` IN ?" , userKey ) . Find ( & userList )
if requestData . Name != "" {
gormDb = gormDb . Where ( "`name` LIKE ? OR `number` LIKE ?" , "%" + requestData . Name + "%" , "%" + requestData . Name + "%" )
}
err = gormDb . Find ( & userList ) . Error
if err != nil {
outPut [ "userKey" ] = userKey
outPut [ "list" ] = sendList
publicmethod . Result ( 0 , outPut , c )
return
}
for _ , v := range userList {
var sendCont SendPowerPage
sendCont . Id = strconv . FormatInt ( v . Key , 10 )
sendCont . Name = v . Name
sendCont . Code = v . Number
sendCont . Icon = v . IconPhoto
if v . Icon != "" {
sendCont . Icon = v . Icon
}
orgName := ""
if v . Company != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . Company } , "`name`" )
if orgCont . Name != "" {
orgName = orgCont . Name
}
}
if v . MainDeparment != 0 && v . MainDeparment != v . Company {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . MainDeparment } , "`name`" )
if orgCont . Name != "" {
orgName = fmt . Sprintf ( "%v-%v" , orgName , orgCont . Name )
} else {
orgName = orgCont . Name
}
}
if v . AdminOrg != 0 && v . AdminOrg != v . MainDeparment && v . AdminOrg != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . AdminOrg } , "`name`" )
if orgCont . Name != "" {
orgName = fmt . Sprintf ( "%v-%v" , orgName , orgCont . Name )
} else {
orgName = orgCont . Name
}
}
sendCont . Org = orgName
sendList = append ( sendList , sendCont )
}
outPut [ "userKey" ] = userKey
outPut [ "list" ] = sendList
publicmethod . Result ( 0 , outPut , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 27 10 : 21 : 20
@ 功能 : 保存角色使用人
* /
func ( a * ApiMethod ) SavePickRoleMan ( c * gin . Context ) {
var requestData SetupRoleMan
err := c . ShouldBindJSON ( & requestData )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if requestData . RoleId == 0 {
publicmethod . Result ( 3 , requestData , c , "未知赋权项目!请明确!" )
return
}
var roleInfo modelssystempermission . SystemRole
err = overall . CONSTANT_DB_System_Permission . Model ( & roleInfo ) . Where ( "`id` = ?" , requestData . RoleId ) . First ( & roleInfo ) . Error
if err != nil {
publicmethod . Result ( 1 , requestData , c , "未知赋权项目!请明确!" )
return
}
saveData := publicmethod . MapOut [ string ] ( )
if len ( requestData . UserKey ) > 0 {
// peopleJson, _ := json.Marshal(requestData.UserKey)
// saveData["roleuser"] = string(peopleJson)
saveData [ "roleuser" ] = strings . Join ( requestData . UserKey , "," )
} else {
saveData [ "roleuser" ] = ""
}
saveData [ "`time`" ] = time . Now ( ) . Unix ( )
err = roleInfo . EiteCont ( map [ string ] interface { } { "`id`" : requestData . RoleId } , saveData )
if err != nil {
publicmethod . Result ( 106 , err , c )
return
}
publicmethod . Result ( 0 , err , c )
}