@ -1,6 +1,7 @@
package administrativeorganization
package administrativeorganization
import (
import (
"encoding/json"
"fmt"
"fmt"
"hr_server/models"
"hr_server/models"
"hr_server/overall"
"hr_server/overall"
@ -404,14 +405,18 @@ func (o *OrganizationApi) GetOrgAllSun(c *gin.Context) {
* /
* /
func ( o * OrganizationApi ) GetCompanyDeparment ( c * gin . Context ) {
func ( o * OrganizationApi ) GetCompanyDeparment ( c * gin . Context ) {
var requestData overallhandle . GetId
var requestData overallhandle . GetId
c . ShouldBindJSON ( & requestData )
errddd := c . ShouldBindJSON ( & requestData )
sdfgg , _ := json . Marshal ( requestData )
fmt . Printf ( "获取值------1----->%v----->%v----->%v\n" , requestData , string ( sdfgg ) , errddd )
if requestData . Id == 0 && requestData . IdStr == "" {
if requestData . Id == 0 && requestData . IdStr == "" {
requestData . Id = 0
requestData . Id = 0
}
}
fmt . Printf ( "获取值----2------->%v\n" , requestData )
if requestData . IdStr != "" {
if requestData . IdStr != "" {
idInt64 , _ := strconv . ParseInt ( requestData . IdStr , 10 , 64 )
idInt64 , _ := strconv . ParseInt ( requestData . IdStr , 10 , 64 )
requestData . Id = idInt64
requestData . Id = idInt64
}
}
fmt . Printf ( "获取值----3------->%v\n" , requestData )
orgId := getOrgIdList ( requestData . Id )
orgId := getOrgIdList ( requestData . Id )
if len ( orgId ) < 1 {
if len ( orgId ) < 1 {
overallhandle . Result ( 101 , orgId , c , "没有查询到信息!" )
overallhandle . Result ( 101 , orgId , c , "没有查询到信息!" )
@ -560,7 +565,7 @@ func OrgAndMAnThree(parentId int64, govAry []OrgAndPeople) []OrgAndPeopleThree {
for _ , v := range govAry {
for _ , v := range govAry {
// var zhucont govThree
// var zhucont govThree
parentIdInt , _ := strconv . ParseInt ( v . ParentId , 10 , 64 )
parentIdInt , _ := strconv . ParseInt ( v . ParentId , 10 , 64 )
// fmt.Printf("------------->%v---->%v\n", parentIdInt, parentId)
if parentIdInt == parentId {
if parentIdInt == parentId {
orgIdInt , _ := strconv . ParseInt ( v . OrgId , 10 , 64 )
orgIdInt , _ := strconv . ParseInt ( v . OrgId , 10 , 64 )
child := OrgAndMAnThree ( orgIdInt , govAry )
child := OrgAndMAnThree ( orgIdInt , govAry )
@ -787,3 +792,479 @@ func GetAllOrgName(id, level int64, name string) (allName string) {
}
}
return
return
}
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 19 10 : 41 : 34
@ 功能 : 获取行政组织及相关人员
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( o * OrganizationApi ) GetOrgAndEveryOnePeople ( c * gin . Context ) {
var requestData OrgAndMAnThreeType
c . ShouldBindJSON ( & requestData )
//获取行政组织
var sunAry overallhandle . AllSunList [ int64 ]
var orgIdList [ ] int64
var origin int64
isNotIn := 0
if requestData . All == 0 {
if requestData . Id == "" {
origin = 0
isNotIn = 1
orgIdList = [ ] int64 { 312 , 293 , 305 , 306 , 307 }
} else {
idInt64 , _ := strconv . ParseInt ( requestData . Id , 10 , 64 )
origin = idInt64
sunAry . GetAllSunOrg ( idInt64 )
orgIdList = sunAry . SunList
}
} else {
if requestData . Id != "" {
idInt64 , _ := strconv . ParseInt ( requestData . Id , 10 , 64 )
origin = idInt64
sunAry . GetAllSunOrg ( idInt64 )
orgIdList = sunAry . SunList
}
}
var orgAndPeopleListCont empowerSync //启用协程结构体
synPro . Add ( 1 )
go orgAndPeopleListCont . GetOrgList ( isNotIn , orgIdList , requestData . Level ) //获取行政组织
synPro . Add ( 1 )
go orgAndPeopleListCont . GetPeopleList ( isNotIn , orgIdList ) //获取人员
synPro . Wait ( )
orgAndManList := orgAndPeopleListCont . readDataLock ( )
sendList := OrgAndManNewThree ( origin , orgAndManList )
overallhandle . Result ( 0 , sendList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 19 11 : 18 : 39
@ 功能 : 获取行政组织 ( 协程 )
@ 参数
# orgId 行政组织ID
# level 获取等级
@ 返回值
#
@ 方法原型
# func ( e * empowerSync ) GetOrgList ( orgId [ ] int64 , level int )
* /
func ( e * empowerSync ) GetOrgList ( isNotIn int , orgId [ ] int64 , level int ) {
e . mutext . Lock ( )
defer e . mutext . Unlock ( )
var orgList [ ] models . AdministrativeOrganization
gormDb := overall . CONSTANT_DB_HR . Model ( & models . AdministrativeOrganization { } ) . Select ( "`id`,`number`,`name`,`superior`" ) . Where ( "`state` = ? " , 1 )
if len ( orgId ) > 0 {
if isNotIn == 1 {
gormDb = gormDb . Where ( "`id` NOT IN ?" , orgId )
} else {
gormDb = gormDb . Where ( "`id` IN ?" , orgId )
}
}
if level != 0 {
gormDb = gormDb . Where ( "`level` <= ?" , level )
}
err := gormDb . Find ( & orgList ) . Error
if err == nil && len ( orgList ) > 0 {
for _ , v := range orgList {
var orgCont OrgAndEveryOnePeople
orgCont . Id = strconv . FormatInt ( v . Id , 10 ) //识别符
orgCont . OrgId = v . Id
orgCont . Number = v . Number //编号
orgCont . Name = v . Name //姓名
orgCont . Superior = strconv . FormatInt ( v . Superior , 10 ) //上级
orgCont . Type = 1
orgCont . Key = fmt . Sprintf ( "A%v" , v . Id )
e . orgAndPeopleList = append ( e . orgAndPeopleList , orgCont )
}
}
synPro . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 19 11 : 24 : 44
@ 功能 : 获取人员 ( 协程 )
@ 参数
# orgId 行政组织ID
@ 返回值
#
@ 方法原型
#
* /
func ( e * empowerSync ) GetPeopleList ( isNotIn int , orgId [ ] int64 ) {
e . mutext . Lock ( )
defer e . mutext . Unlock ( )
var peopleList [ ] models . PersonArchives
gormDnMan := overall . CONSTANT_DB_HR . Model ( & models . PersonArchives { } ) . Select ( "`key`,`number`,`name`,`icon`,`icon_photo`,`admin_org`" ) . Where ( "`state` = 1 AND `emp_type` BETWEEN ? AND ?" , 1 , 10 )
if len ( orgId ) > 0 {
if isNotIn == 1 {
gormDnMan = gormDnMan . Where ( "`admin_org` NOT IN ?" , orgId )
} else {
gormDnMan = gormDnMan . Where ( "`admin_org` IN ?" , orgId )
}
}
err := gormDnMan . Find ( & peopleList ) . Error
if err == nil && len ( peopleList ) > 0 {
for _ , v := range peopleList {
var peopleCont OrgAndEveryOnePeople
peopleCont . Id = strconv . FormatInt ( v . Key , 10 ) //识别符
peopleCont . OrgId = - 1
peopleCont . Number = v . Number //编号
peopleCont . Name = v . Name //姓名
peopleCont . Superior = strconv . FormatInt ( v . AdminOrg , 10 ) //上级
peopleCont . Icon = v . Icon
peopleCont . IconPhoto = v . IconPhoto
peopleCont . Type = 2
peopleCont . Key = fmt . Sprintf ( "U%v" , v . Key )
e . orgAndPeopleList = append ( e . orgAndPeopleList , peopleCont )
}
}
synPro . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 19 14 : 28 : 48
@ 功能 : 新版人员与行政组织树
@ 参数
# parentId 上级ID
# govAry 数据
@ 返回值
#
@ 方法原型
# func OrgAndManNewThree ( parentId int64 , govAry [ ] OrgAndEveryOnePeople ) [ ] OrgAndManThree
* /
func OrgAndManNewThree ( parentId int64 , govAry [ ] OrgAndEveryOnePeople ) [ ] OrgAndManThree {
orgAndMAnMap := [ ] OrgAndManThree { }
for _ , v := range govAry {
// var zhucont govThree
parentIdInt , _ := strconv . ParseInt ( v . Superior , 10 , 64 )
// fmt.Printf("------------->%v---->%v\n", parentIdInt, parentId)
if parentIdInt == parentId {
child := OrgAndManNewThree ( v . OrgId , govAry )
var node OrgAndManThree
node . Id = v . Id //识别符
node . OrgId = v . OrgId
node . Number = v . Number //编号
node . Name = v . Name //姓名
node . Superior = v . Superior //上级
node . Icon = v . Icon
node . IconPhoto = v . IconPhoto
node . Type = v . Type
node . Key = v . Key
node . Child = child
orgAndMAnMap = append ( orgAndMAnMap , node )
}
}
return orgAndMAnMap
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 29 0 9 : 26 : 04
@ 功能 : 根据行政组织编号获取组织及人员
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( o * OrganizationApi ) BasisOrgObtainSonOrgAndMan ( c * gin . Context ) {
var requestData overallhandle . ConstId
err := c . ShouldBindJSON ( & requestData )
if err != nil {
overallhandle . Result ( 100 , err , c )
return
}
//获取当前行政组织信息
var orgCont models . AdministrativeOrganization
isNotIn := 0
var idList [ ] int64
var parenAry overallhandle . AllSunList [ int64 ]
if requestData . Id != "" {
idInt , _ := strconv . ParseInt ( requestData . Id , 10 , 64 )
idList = [ ] int64 { idInt }
if idInt != 309 {
err = orgCont . GetCont ( map [ string ] interface { } { "id" : idInt } )
parenAry . SunList = append ( parenAry . SunList , idInt )
parenAry . GetAllParentOrg ( idInt , 3 )
} else {
}
} else {
isNotIn = 1
idList = [ ] int64 { 312 , 293 , 305 , 306 , 307 }
err = fmt . Errorf ( "获取全部内容" )
}
var sendData ShenPiXuanRen
// fmt.Printf("组织id列表------------》%v\n", parenAry.SunList)
if len ( parenAry . SunList ) > 0 {
var orgAndPeopleListTitleCont empowerSynces //启用协程结构体
synProes . Add ( 1 )
go orgAndPeopleListTitleCont . BasisOrgDirectOrgIng ( parenAry . SunList ) //获取行政组织
synProes . Wait ( )
orgTitleList := orgAndPeopleListTitleCont . readDataLock ( )
sort . SliceStable ( orgTitleList , func ( i , j int ) bool {
return orgTitleList [ i ] . Sort < orgTitleList [ j ] . Sort
} )
for _ , ov := range orgTitleList {
var titleDepartCont TitleDepartmentsCont
titleDepartCont . DepartmentId = ov . Id //行政组织ID
titleDepartCont . Id = ov . Id //行政组织ID
titleDepartCont . DepartmentKey = ov . Number //行政组织编码
titleDepartCont . DepartmentName = ov . Name //行政组织名称
titleDepartCont . ParentId = ov . Superior //上级ID
titleDepartCont . DepartmentNames = ov . Name //行政组织别名
sendData . TitleDepartments = append ( sendData . TitleDepartments , titleDepartCont )
}
}
var orgAndPeopleListCont empowerSyncDepartMan //启用协程结构体
synPro . Add ( 1 )
go orgAndPeopleListCont . BasisOrgDirectOrg ( isNotIn , idList , 3 ) //获取行政组织
synPro . Add ( 1 )
go orgAndPeopleListCont . GetPeopleListIng ( isNotIn , idList ) //获取人员
synPro . Wait ( )
orgList , manList := orgAndPeopleListCont . readDataLock ( )
if len ( orgList ) > 0 {
for _ , org := range orgList {
var orgShenPi ChildDepartmentsCont
orgShenPi . Id = org . Id //行政组织ID
orgShenPi . DepartmentKey = org . Number //行政组织编码
orgShenPi . DepartmentName = org . Name //行政组织名称
orgShenPi . ParentId = org . Superior //上级ID
orgShenPi . DepartmentNames = org . Name //行政组织别名
sendData . ChildDepartments = append ( sendData . ChildDepartments , orgShenPi )
}
}
if len ( manList ) > 0 {
for _ , man := range manList {
var employess EmployeesCont
employess . Id = man . Id
employess . EmployeeName = man . Name //人员名称
employess . IsLeave = "0" //行政组织名称
employess . Open = "false" //上级ID
employess . Icon = man . Icon
employess . IconToBase64 = man . IconPhoto
sendData . Employees = append ( sendData . Employees , employess )
}
}
// outMap := overallhandle.MapOut()
// outMap["sendData"] = sendData
// outMap["orgList"] = orgList
// outMap["manList"] = manList
overallhandle . Result ( 0 , sendData , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 19 11 : 24 : 44
@ 功能 : 获取人员 ( 协程 )
@ 参数
# orgId 行政组织ID
@ 返回值
#
@ 方法原型
#
* /
func ( e * empowerSyncDepartMan ) GetPeopleListIng ( isNotIn int , orgId [ ] int64 ) {
e . mutext . Lock ( )
defer e . mutext . Unlock ( )
var peopleList [ ] models . PersonArchives
gormDnMan := overall . CONSTANT_DB_HR . Model ( & models . PersonArchives { } ) . Select ( "`key`,`number`,`name`,`icon`,`icon_photo`,`admin_org`" ) . Where ( "`state` = 1 AND `emp_type` BETWEEN ? AND ?" , 1 , 10 )
if len ( orgId ) > 0 {
if isNotIn == 1 {
gormDnMan = gormDnMan . Where ( "`admin_org` NOT IN ?" , orgId )
} else {
gormDnMan = gormDnMan . Where ( "`admin_org` IN ?" , orgId )
}
}
err := gormDnMan . Find ( & peopleList ) . Error
if err == nil && len ( peopleList ) > 0 {
for _ , v := range peopleList {
var peopleCont OrgAndEveryOnePeople
peopleCont . Id = strconv . FormatInt ( v . Key , 10 ) //识别符
peopleCont . OrgId = - 1
peopleCont . Number = v . Number //编号
peopleCont . Name = v . Name //姓名
peopleCont . Superior = strconv . FormatInt ( v . AdminOrg , 10 ) //上级
peopleCont . Icon = v . Icon
peopleCont . IconPhoto = v . IconPhoto
peopleCont . Type = 2
peopleCont . Key = fmt . Sprintf ( "U%v" , v . Key )
e . peopleList = append ( e . peopleList , peopleCont )
}
}
synPro . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 29 0 9 : 54 : 05
@ 功能 : 根据行政组织ID获取直接下级
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( e * empowerSyncDepartMan ) BasisOrgDirectOrg ( isNotIn int , orgId [ ] int64 , level int ) {
e . mutext . Lock ( )
defer e . mutext . Unlock ( )
var orgList [ ] models . OrgContType
gormDb := overall . CONSTANT_DB_HR . Model ( & models . OrgContType { } ) . Select ( "`id`,`numbe`,`name`,`superior`" ) . Where ( "`state` = ? " , 1 )
if len ( orgId ) > 0 {
if isNotIn == 1 {
gormDb = gormDb . Where ( "`id` NOT IN ?" , orgId )
} else {
gormDb = gormDb . Where ( "`superior` IN ?" , orgId )
}
}
if level != 0 {
gormDb = gormDb . Where ( "`level` > ?" , level )
}
err := gormDb . Find ( & orgList ) . Error
listCount := len ( orgList )
if err == nil && listCount > 0 {
for i , v := range orgList {
var orgCont OrgAndEveryOnePeople
orgCont . Id = strconv . FormatInt ( v . Id , 10 ) //识别符
orgCont . OrgId = v . Id
orgCont . Number = v . Number //编号
orgCont . Name = v . Name //行政组织名称
orgCont . Superior = strconv . FormatInt ( v . Superior , 10 ) //上级
orgCont . Type = 1
orgCont . Key = fmt . Sprintf ( "A%v" , v . Id )
orgCont . Sort = listCount - i
e . orgList = append ( e . orgList , orgCont )
}
}
synPro . Done ( )
}
func ( e * empowerSynces ) BasisOrgDirectOrgIng ( orgId [ ] int64 ) {
e . mutext . Lock ( )
defer e . mutext . Unlock ( )
listCount := len ( orgId )
if listCount > 0 {
for i , v := range orgId {
var orgContOld models . AdministrativeOrganization
err := overall . CONSTANT_DB_HR . Model ( & models . AdministrativeOrganization { } ) . Select ( "`id`,`number`,`name`,`superior`" ) . Where ( "`id` = ? " , v ) . First ( & orgContOld ) . Error
if err == nil {
var orgCont OrgAndEveryOnePeople
orgCont . Id = strconv . FormatInt ( orgContOld . Id , 10 ) //识别符
orgCont . OrgId = orgContOld . Id
orgCont . Number = orgContOld . Number //编号
orgCont . Name = orgContOld . Name //行政组织名称
orgCont . Superior = strconv . FormatInt ( orgContOld . Superior , 10 ) //上级
orgCont . Type = 1
orgCont . Key = fmt . Sprintf ( "A%v" , orgContOld . Id )
orgCont . Sort = listCount - i
e . orgAndPeopleList = append ( e . orgAndPeopleList , orgCont )
}
}
}
synProes . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 02 - 15 10 : 46 : 22
@ 功能 : 获取指定行政组织列表
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( o * OrganizationApi ) GetAppointOrg ( c * gin . Context ) {
var requestData OrgIdList
err := c . ShouldBindJSON ( & requestData )
if err != nil {
overallhandle . Result ( 100 , err , c )
return
}
if len ( requestData . OrgId ) < 1 {
overallhandle . Result ( 1 , err , c , "请选择行政组织!" )
return
}
var orgList [ ] models . AdministrativeOrganization
err = overall . CONSTANT_DB_HR . Where ( "`id` IN ?" , requestData . OrgId ) . Find ( & orgList ) . Error
if err != nil || len ( orgList ) < 1 {
overallhandle . Result ( 107 , err , c )
return
}
overallhandle . Result ( 0 , orgList , c )
}