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.
184 lines
5.1 KiB
184 lines
5.1 KiB
|
3 years ago
|
package administrativeorganization
|
||
|
|
|
||
|
|
import (
|
||
|
|
"hr_server/models"
|
||
|
|
"hr_server/overall"
|
||
|
|
"hr_server/overall/overallhandle"
|
||
|
|
"sort"
|
||
|
|
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-02-24 09:36:28
|
||
|
|
@ 功能: 获取行政组织与岗位树
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (o *OrganizationApi) GetOrgAndPostThree(c *gin.Context) {
|
||
|
|
var requestData OrgAndMAnThreeType
|
||
|
|
c.ShouldBindJSON(&requestData)
|
||
|
|
//获取行政组织
|
||
|
|
var orgList []models.OrgContType
|
||
|
|
gormDb := overall.CONSTANT_DB_HR.Where("`state` = ? ", 1)
|
||
|
|
if requestData.All == 0 {
|
||
|
|
// requestData.Id = "309"
|
||
|
|
gormDb = gormDb.Where("`id` NOT IN ?", []int{312, 293, 305, 306, 307})
|
||
|
|
}
|
||
|
|
if requestData.Level != 0 {
|
||
|
|
gormDb = gormDb.Where("`level` <= ?", requestData.Level)
|
||
|
|
}
|
||
|
|
// departmentId := overallhandle.RecursionOrgLeveEs(282, 282, 3)
|
||
|
|
// overallhandle.Result(2555646, departmentId, c)
|
||
|
|
// return
|
||
|
|
|
||
|
|
err := gormDb.Find(&orgList).Error
|
||
|
|
if err != nil {
|
||
|
|
overallhandle.Result(107, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var total int64
|
||
|
|
totalErr := gormDb.Count(&total).Error
|
||
|
|
if totalErr != nil {
|
||
|
|
total = 0
|
||
|
|
}
|
||
|
|
pageSize := 1
|
||
|
|
//计算分协程数据基数
|
||
|
|
switch {
|
||
|
|
case total > 10 && total <= 10000:
|
||
|
|
pageSize = 100
|
||
|
|
case total > 10000:
|
||
|
|
pageSize = 1000
|
||
|
|
default:
|
||
|
|
pageSize = 1
|
||
|
|
}
|
||
|
|
var contList []OutPutOrgAndPost
|
||
|
|
var syncOrgToPost OrgAndPostSync
|
||
|
|
for i, v := range orgList {
|
||
|
|
var sendCont OutPutOrgAndPost
|
||
|
|
sendCont.Id = strconv.FormatInt(v.Id, 10)
|
||
|
|
sendCont.Number = v.Number
|
||
|
|
sendCont.Name = v.Name
|
||
|
|
sendCont.Superior = v.Superior
|
||
|
|
sendCont.Attribute = 1
|
||
|
|
sendCont.Sort = 1
|
||
|
|
sendCont.OrgId = strconv.FormatInt(v.Id, 10)
|
||
|
|
if (i+1)%pageSize == 0 {
|
||
|
|
contList = append(contList, sendCont)
|
||
|
|
synProes.Add(1)
|
||
|
|
go syncOrgToPost.GetPostInfoList(contList)
|
||
|
|
contList = []OutPutOrgAndPost{}
|
||
|
|
} else {
|
||
|
|
contList = append(contList, sendCont)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(contList) > 0 { //判断盈余分组数据
|
||
|
|
synProes.Add(1)
|
||
|
|
go syncOrgToPost.GetPostInfoList(contList)
|
||
|
|
}
|
||
|
|
synProes.Wait()
|
||
|
|
allOrgAndPostContList := syncOrgToPost.readDataLock()
|
||
|
|
sort.Slice(allOrgAndPostContList, func(i, j int) bool {
|
||
|
|
return allOrgAndPostContList[i].Sort < allOrgAndPostContList[j].Sort
|
||
|
|
})
|
||
|
|
sort.Slice(allOrgAndPostContList, func(i, j int) bool {
|
||
|
|
return allOrgAndPostContList[i].Superior < allOrgAndPostContList[j].Superior
|
||
|
|
})
|
||
|
|
var allNumber []string
|
||
|
|
for _, v := range allOrgAndPostContList {
|
||
|
|
allNumber = append(allNumber, v.Number)
|
||
|
|
}
|
||
|
|
sendList := OrgAndPostThreeList(requestData.Id, allOrgAndPostContList)
|
||
|
|
outputDataAry := overallhandle.MapOut()
|
||
|
|
outputDataAry["count"] = len(allOrgAndPostContList)
|
||
|
|
outputDataAry["list"] = sendList
|
||
|
|
outputDataAry["allnumber"] = allNumber
|
||
|
|
overallhandle.Result(0, outputDataAry, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 合成树形结构
|
||
|
|
func OrgAndPostThreeList(superiorId string, contList []OutPutOrgAndPost) *[]OutPutOrgAndPostLoop {
|
||
|
|
three := []OutPutOrgAndPostLoop{}
|
||
|
|
for _, v := range contList {
|
||
|
|
supIdStr := strconv.FormatInt(v.Superior, 10)
|
||
|
|
if superiorId == supIdStr {
|
||
|
|
child := OrgAndPostThreeList(v.OrgId, contList)
|
||
|
|
var node OutPutOrgAndPostLoop
|
||
|
|
node.Id = v.Id
|
||
|
|
node.Number = v.Number
|
||
|
|
node.Name = v.Name
|
||
|
|
node.Superior = v.Superior
|
||
|
|
node.Attribute = v.Attribute
|
||
|
|
node.Sort = v.Sort
|
||
|
|
node.OrgId = v.OrgId
|
||
|
|
node.OrgName = v.OrgName
|
||
|
|
node.DepartId = v.DepartId
|
||
|
|
node.DepartName = v.DepartName
|
||
|
|
node.Child = child
|
||
|
|
three = append(three, node)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return &three
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取岗位列表
|
||
|
|
func (o *OrgAndPostSync) GetPostInfoList(contList []OutPutOrgAndPost) {
|
||
|
|
o.mutext.Lock()
|
||
|
|
defer o.mutext.Unlock()
|
||
|
|
|
||
|
|
var orgId []string
|
||
|
|
for _, v := range contList {
|
||
|
|
if overallhandle.IsInTrue[string](v.Id, orgId) == false {
|
||
|
|
orgId = append(orgId, v.Id)
|
||
|
|
o.orgAndPostList = append(o.orgAndPostList, v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(orgId) > 0 {
|
||
|
|
var postContList []models.Position
|
||
|
|
err := overall.CONSTANT_DB_HR.Model(&models.Position{}).Select("`id`,`number`,`name`,`administrative_organization`,`superior`").Where("`state` = 1 AND `administrative_organization` IN ?", orgId).Find(&postContList).Error
|
||
|
|
if err == nil {
|
||
|
|
for _, v := range postContList {
|
||
|
|
|
||
|
|
// _, _, departmentId, _, _ := overallhandle.GetOrgStructure(v.AdministrativeOrganization)
|
||
|
|
departmentId := overallhandle.RecursionOrgLeveEs(v.AdministrativeOrganization, v.AdministrativeOrganization, 3)
|
||
|
|
var departCont models.AdministrativeOrganization
|
||
|
|
departCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`name`")
|
||
|
|
|
||
|
|
var sendCont OutPutOrgAndPost
|
||
|
|
sendCont.Id = strconv.FormatInt(v.Id, 10)
|
||
|
|
sendCont.Number = v.Number
|
||
|
|
sendCont.Name = v.Name
|
||
|
|
sendCont.Superior = v.AdministrativeOrganization
|
||
|
|
sendCont.Attribute = 2
|
||
|
|
sendCont.Sort = 2
|
||
|
|
sendCont.OrgId = "-1"
|
||
|
|
sendCont.DepartId = strconv.FormatInt(departmentId, 10)
|
||
|
|
sendCont.DepartName = departCont.Name
|
||
|
|
if departmentId == v.AdministrativeOrganization {
|
||
|
|
sendCont.OrgName = departCont.Name
|
||
|
|
} else {
|
||
|
|
var orgCont models.AdministrativeOrganization
|
||
|
|
orgCont.GetCont(map[string]interface{}{"`id`": v.AdministrativeOrganization}, "`name`")
|
||
|
|
sendCont.OrgName = orgCont.Name
|
||
|
|
}
|
||
|
|
|
||
|
|
o.orgAndPostList = append(o.orgAndPostList, sendCont)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
synProes.Done()
|
||
|
|
}
|