From a6de631a64ceecd9b6836e7dab6eaf74dbb45e33 Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Sat, 19 Nov 2022 15:43:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=92=E8=89=B2=E8=A1=8C?= =?UTF-8?q?=E6=94=BF=E7=BB=84=E7=BB=87=E4=B8=8E=E4=BA=BA=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../administrativeorganization/govcont.go | 350 ++++++++++++++++++ .../administrativeorganization/type.go | 41 ++ apirouter/organization/organization_group.go | 6 + config/configDatabase/database.go | 3 + config_server/configDatabase/database.go | 3 + models/org_cont_type.go | 6 +- overall/overallhandle/overall_handle.go | 2 +- overall/overallhandle/type.go | 1 + 8 files changed, 408 insertions(+), 4 deletions(-) diff --git a/api/version1/administrativeorganization/govcont.go b/api/version1/administrativeorganization/govcont.go index 82a41d6..f562daf 100644 --- a/api/version1/administrativeorganization/govcont.go +++ b/api/version1/administrativeorganization/govcont.go @@ -1,9 +1,11 @@ package administrativeorganization import ( + "fmt" "hr_server/models" "hr_server/overall" "hr_server/overall/overallhandle" + "sort" "strconv" "time" @@ -275,6 +277,7 @@ func (o *OrganizationApi) GovThree(c *gin.Context) { idInt64, _ := strconv.ParseInt(requestData.IdStr, 10, 64) requestData.Id = idInt64 } + fmt.Printf("requestData---------------->%v\n", requestData) var govMap overallhandle.MenuList // gormDb := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("administrative_organization.*,aot.name as classname,aot.level").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type").Where("administrative_organization.`state` IN ?", []int{1, 2}).Where("administrative_organization.id NOT IN ?", []int{312, 293, 305, 306, 307}) gormDb := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("administrative_organization.*,aot.name as classname,aot.level").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type").Where("administrative_organization.`state` = ?", 1) @@ -292,6 +295,7 @@ func (o *OrganizationApi) GovThree(c *gin.Context) { } // fmt.Printf("id==========>%v", govMap) // govMap.GovRecursion(requestData.Id, 0) + fmt.Printf("govAry---------------->%v\n", requestData.Id) govMapThree := overallhandle.GovThreeList(requestData.Id, govMap) overallhandle.Result(0, govMapThree, c) } @@ -377,3 +381,349 @@ func getOrgIdList(orgId int64) (orgIdList []int64) { } return } + +/* +* +@ 作者: 秦东 +@ 时间: 2022-11-16 14:04:17 +@ 功能: +@ 参数 + + # + +@ 返回值 + + # +*/ +func (o *OrganizationApi) GovThreeAboutMan(c *gin.Context) { + var requestData OrgAndMAnThreeType + c.ShouldBindJSON(&requestData) + // if requestData.Id == "" { + // overallhandle.Result(101, requestData, c, "行政类别Id不能为空!") + // return + // } + + //获取行政组织 + var orgList []models.OrgContType + gormDb := overall.CONSTANT_DB_HR.Where("`state` = ? ", 1) + if requestData.All == 0 { + requestData.Id = "312" + gormDb = gormDb.Where("`id` NOT IN ?", []int{312, 293, 305, 306, 307}) + } + if requestData.Level != 0 { + gormDb = gormDb.Where("`level` <= ?", requestData.Level) + } + + 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 + } + // overallhandle.Result(0, pageSize, c) + // return + var sendDataList []OrgAndPeople //组装分组信息 + var allOrgAndPeople synProReadData + for i, v := range orgList { + var sendDataCont OrgAndPeople + sendDataCont.Id = strconv.FormatInt(v.Id, 10) //行政组织Id或人员Key + sendDataCont.Name = v.Name //行政组织名称或人员名称 + sendDataCont.Number = v.Number //行政组织编号或人员编号 + sendDataCont.OrgId = strconv.FormatInt(v.Id, 10) //行政组织ID + // sendDataCont.Icon = "" //行政组织头像或人员头像 + sendDataCont.ParentId = strconv.FormatInt(v.Superior, 10) //上级 + sendDataCont.IsMan = 1 //是部门还是个人(1:行政组织;2:人员) + sendDataCont.Sort = 2 + if (i+1)%pageSize == 0 { + sendDataList = append(sendDataList, sendDataCont) + synPro.Add(1) + go allOrgAndPeople.GetOrgAboutPeople(sendDataList) //协程处理行政组织下的人员信息 + sendDataList = []OrgAndPeople{} + // fmt.Printf("执行一次---------->%v\n", i) + } else { + sendDataList = append(sendDataList, sendDataCont) + } + allOrgAndPeople.OrgAndPeopleList = append(allOrgAndPeople.OrgAndPeopleList, sendDataCont) + } + if len(sendDataList) > 0 { //判断盈余分组数据 + synPro.Add(1) + go allOrgAndPeople.GetOrgAboutPeople(sendDataList) + } + synPro.Wait() + // fmt.Printf("%v\n", len(allOrgAndPeople.OrgAndPeopleList)) + for oi, _ := range allOrgAndPeople.OrgAndPeopleList { + allOrgAndPeople.OrgAndPeopleList[oi].Identify = oi + 1 + } + + idInt, _ := strconv.ParseInt(requestData.Id, 10, 64) + sort.Slice(allOrgAndPeople.OrgAndPeopleList, func(i, j int) bool { + return allOrgAndPeople.OrgAndPeopleList[i].Sort < allOrgAndPeople.OrgAndPeopleList[j].Sort + }) + // var outputDataList []OrgAndPeople + fmt.Printf("idInt------------------>%v\n", idInt) + govMapThree := OrgAndMAnThree(idInt, allOrgAndPeople.OrgAndPeopleList) + outputDataAry := overallhandle.MapOut() + outputDataAry["three"] = govMapThree + outputDataAry["list"] = allOrgAndPeople.OrgAndPeopleList + overallhandle.Result(0, outputDataAry, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2022-11-16 15:23:41 +@ 功能: 递归人员行政树 +@ 参数 + + # + +@ 返回值 + + # +*/ +func OrgAndMAnThree(parentId int64, govAry []OrgAndPeople) []OrgAndPeopleThree { + orgAndMAnMap := []OrgAndPeopleThree{} + for _, v := range govAry { + // var zhucont govThree + parentIdInt, _ := strconv.ParseInt(v.ParentId, 10, 64) + + if parentIdInt == parentId { + orgIdInt, _ := strconv.ParseInt(v.OrgId, 10, 64) + child := OrgAndMAnThree(orgIdInt, govAry) + + var node OrgAndPeopleThree + node.Id = v.Id //行政组织Id或人员Key + node.Name = v.Name //行政组织名称或人员名称 + node.Number = v.Number //行政组织编号或人员编号 + node.Icon = v.Icon //行政组织头像或人员头像 + node.ParentId = v.ParentId //上级 + node.OrgId = v.OrgId //所属行政组织 + node.IsMan = v.IsMan //是部门还是个人(1:行政组织;2:人员) + node.Child = child + node.Sort = v.Sort + node.Identify = v.Identify + orgAndMAnMap = append(orgAndMAnMap, node) + + } + + } + return orgAndMAnMap +} + +/* +* +@ 作者: 秦东 +@ 时间: 2022-11-16 14:41:26 +@ 功能: 获取行政组织相关人员 +@ 参数 + + # + +@ 返回值 + + # +*/ +func (s *synProReadData) GetOrgAboutPeople(orgList []OrgAndPeople) { + defer synPro.Done() + countList := len(orgList) + if countList > 0 { + var orgId []string + for i := 0; i < countList; i++ { + if overallhandle.IsInTrue[string](orgList[i].Id, orgId) == false { + orgId = append(orgId, orgList[i].Id) + } + } + var peopleList []models.PersonArchives + err := overall.CONSTANT_DB_HR.Model(&models.PersonArchives{}).Select("`key`,`number`,`name`,`icon`,`admin_org`").Where("`state` = ? AND `admin_org` IN ? AND `emp_type` BETWEEN ? AND ? ", 1, orgId, 1, 10).Find(&peopleList).Error + if err == nil { + if len(peopleList) > 0 { + for _, v := range peopleList { + s.MakePeopleToOrg(v, orgList) + } + } + } + } +} + +/* +* +@ 作者: 秦东 +@ 时间: 2022-11-16 15:05:40 +@ 功能: 组装人员与行政组织的关联信息 +@ 参数 + + # + +@ 返回值 + + # +*/ +func (s *synProReadData) MakePeopleToOrg(manCont models.PersonArchives, orgList []OrgAndPeople) { + for _, v := range orgList { + orgIdStr := strconv.FormatInt(manCont.AdminOrg, 10) + if v.Id == orgIdStr { + var sendDataCont OrgAndPeople + sendDataCont.Id = strconv.FormatInt(manCont.Key, 10) //行政组织Id或人员Key + sendDataCont.Name = manCont.Name //行政组织名称或人员名称 + sendDataCont.Number = manCont.Number //行政组织编号或人员编号 + sendDataCont.OrgId = "-1" //行政组织ID + sendDataCont.Icon = manCont.Icon //行政组织头像或人员头像 + sendDataCont.ParentId = v.Id //上级 + sendDataCont.IsMan = 2 //是部门还是个人(1:行政组织;2:人员) + sendDataCont.Sort = 1 + sendDataCont.AllName = fmt.Sprintf("%v(%v)", manCont.Name, manCont.Number) + s.OrgAndPeopleList = append(s.OrgAndPeopleList, sendDataCont) + } + } +} + +/* +* +@ 作者: 秦东 +@ 时间: 2022-11-18 14:28:19 +@ 功能: 角色组织与人员搜索列表 +@ 参数 + + # + +@ 返回值 + + # +*/ +func (o *OrganizationApi) SearchOrgAndPeople(c *gin.Context) { + var requestData NameVal + err := c.ShouldBindJSON(&requestData) + if err != nil { + overallhandle.Result(107, err, c) + return + } + if requestData.Name == "" { + overallhandle.Result(107, err, c) + return + } + var sendPeopleContList []OrgAndPeople + var sendOrgContList []OrgAndPeople + //搜索人 + var peopleList []models.PersonArchives + gormDbMan := overall.CONSTANT_DB_HR.Model(&models.PersonArchives{}).Select("`key`,`number`,`name`,`icon`,`admin_org`").Where("`state` = ? AND `emp_type` BETWEEN ? AND ? ", 1, 1, 10) + if requestData.Name != "" { + gormDbMan = gormDbMan.Where("`name` LIKE ?", "%"+requestData.Name+"%") + } + Identify := 1 + err = gormDbMan.Find(&peopleList).Error + if err == nil { + for _, v := range peopleList { + var sendDataCont OrgAndPeople + sendDataCont.Id = strconv.FormatInt(v.Key, 10) //行政组织Id或人员Key + sendDataCont.Name = v.Name //行政组织名称或人员名称 + sendDataCont.Number = v.Number //行政组织编号或人员编号 + sendDataCont.OrgId = "-1" //行政组织ID + sendDataCont.Icon = v.Icon //行政组织头像或人员头像 + sendDataCont.ParentId = strconv.FormatInt(v.AdminOrg, 10) //上级 + sendDataCont.IsMan = 2 //是部门还是个人(1:行政组织;2:人员) + sendDataCont.Sort = 1 + sendDataCont.Identify = Identify + sendDataCont.AllName = fmt.Sprintf("%v(%v)", v.Name, v.Number) + sendPeopleContList = append(sendPeopleContList, sendDataCont) + Identify++ + } + } + //搜索行政组织 + var orgList []models.OrgContType + gormDbOrg := overall.CONSTANT_DB_HR.Model(&models.OrgContType{}).Select("`id`,`numbe`,`name`,`superior`,`level`").Where("`state` = ?", 1) + if requestData.Name != "" { + gormDbOrg = gormDbOrg.Where("`name` LIKE ?", "%"+requestData.Name+"%") + } + err = gormDbOrg.Find(&orgList).Error + if err == nil { + for _, v := range orgList { + sendName := GetAllOrgName(v.Id, v.Level, v.Name) + + var sendDataOrgCont OrgAndPeople + sendDataOrgCont.Id = strconv.FormatInt(v.Id, 10) //行政组织Id或人员Key + sendDataOrgCont.Name = v.Name //行政组织名称或人员名称 + sendDataOrgCont.Number = v.Number //行政组织编号或人员编号 + sendDataOrgCont.OrgId = strconv.FormatInt(v.Id, 10) //行政组织ID + // sendDataOrgCont.Icon = "" //行政组织头像或人员头像 + sendDataOrgCont.ParentId = strconv.FormatInt(v.Superior, 10) //上级 + sendDataOrgCont.IsMan = 1 //是部门还是个人(1:行政组织;2:人员) + sendDataOrgCont.Sort = 2 + sendDataOrgCont.AllName = sendName + sendDataOrgCont.Identify = Identify + sendOrgContList = append(sendOrgContList, sendDataOrgCont) + Identify++ + } + } + outPutData := overallhandle.MapOut() + outPutData["people"] = sendPeopleContList + outPutData["org"] = sendOrgContList + overallhandle.Result(0, outPutData, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2022-11-18 15:07:18 +@ 功能: 获取名称 +@ 参数 + + #id 行政组织ID + #level 等级 + #name 名称 + +@ 返回值 + + # +*/ +func GetAllOrgName(id, level int64, name string) (allName string) { + if level <= 3 { + allName = name + } else { + _, companyId, departmentId, sunDepartId, _ := overallhandle.GetOrgStructure(id) + var comCont models.AdministrativeOrganization + comCont.GetCont(map[string]interface{}{"`id`": companyId}, "`name`") + switch level { + case 4: + allName = fmt.Sprintf("%v / %v", name, comCont.Name) + case 5: + var mainDepartCont models.AdministrativeOrganization + mainDepartCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`name`") + allName = fmt.Sprintf("%v / %v / %v", name, mainDepartCont.Name, comCont.Name) + case 6: + if departmentId != sunDepartId { + var mainDepartCont models.AdministrativeOrganization + mainDepartCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`name`") + var sunDepartCont models.AdministrativeOrganization + sunDepartCont.GetCont(map[string]interface{}{"`id`": sunDepartId}, "`name`") + allName = fmt.Sprintf("%v / %v / %v / %v", name, sunDepartCont.Name, mainDepartCont.Name, comCont.Name) + } else { + if departmentId != companyId { + var mainDepartCont models.AdministrativeOrganization + mainDepartCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`name`") + allName = fmt.Sprintf("%v / %v / %v", name, mainDepartCont.Name, comCont.Name) + } else { + allName = fmt.Sprintf("%v / %v", name, comCont.Name) + } + + } + + default: + allName = name + } + } + return +} diff --git a/api/version1/administrativeorganization/type.go b/api/version1/administrativeorganization/type.go index 0e6d655..0cc32f2 100644 --- a/api/version1/administrativeorganization/type.go +++ b/api/version1/administrativeorganization/type.go @@ -3,12 +3,16 @@ package administrativeorganization import ( "hr_server/models" "hr_server/overall/overallhandle" + "sync" "github.com/gin-gonic/gin" ) type OrganizationApi struct{} +// 协程 +var synPro = sync.WaitGroup{} + // 入口 func (o *OrganizationApi) Index(c *gin.Context) { outputCont := overallhandle.MapOut() @@ -203,3 +207,40 @@ type eidtTeamCont struct { Id string `json:"id"` Name string `json:"name"` } + +// 协程获取数据 +type synProReadData struct { + OrgAndPeopleList []OrgAndPeople `json:"organdpeopleList"` +} + +// 输出行政组织加人员 +type OrgAndPeople struct { + Id string `json:"id"` //行政组织Id或人员Key + Name string `json:"name"` //行政组织名称或人员名称 + Number string `json:"number"` //行政组织编号或人员编号 + Icon string `json:"icon"` //行政组织头像或人员头像 + ParentId string `json:"parentId"` //上级 + OrgId string `json:"orgId"` //所属行政组织 + IsMan int `json:"isman"` //是部门还是个人(1:行政组织;2:人员) + Sort int `json:"sort"` //排序 + Identify int `json:"identify"` //身份识别 + AllName string `json:"all_name"` //全部名 + // Child []OrgAndPeople `json:"child"` //子栏目 +} + +type OrgAndPeopleThree struct { + OrgAndPeople + Child []OrgAndPeopleThree `json:"child"` //子栏目 +} + +// 行政组织树查询 +type OrgAndMAnThreeType struct { + Id string `json:"id"` + Level int `json:"level"` + All int `json:"all"` +} + +type OrgAndPeopleThreeZZ struct { + *OrgAndPeople + Child []*OrgAndPeopleThreeZZ `json:"child"` //子栏目 +} diff --git a/apirouter/organization/organization_group.go b/apirouter/organization/organization_group.go index c7e1d91..b3a3e62 100644 --- a/apirouter/organization/organization_group.go +++ b/apirouter/organization/organization_group.go @@ -41,6 +41,9 @@ func (o *OrganizationRoute) InitRouterGroup(route *gin.RouterGroup) { apiRouter.POST("govthree", apiHandle.GovThree) //行政组织树 apiRouter.POST("getorgallsun", apiHandle.GetOrgAllSun) //获取当前行政组织的所有子类 + apiRouter.POST("govthreeaboutman", apiHandle.GovThreeAboutMan) //行政组织树及相关人员 + apiRouter.POST("search_org_people", apiHandle.SearchOrgAndPeople) //角色组织与人员搜索列表 + apiRouter.POST("getcompanydeparment", apiHandle.GetCompanyDeparment) //获取当前行政组织的所有主行政部门 //职位(岗位) apiRouter.POST("positionlist", apiHandle.PositionList) //职位(岗位)列表 @@ -95,6 +98,9 @@ func (o *OrganizationRouteOpen) InitRouterGroup(route *gin.RouterGroup) { apiRouter.POST("govthree", apiHandle.GovThree) //行政组织树 apiRouter.POST("getorgallsun", apiHandle.GetOrgAllSun) //获取当前行政组织的所有子类 + apiRouter.POST("govthreeaboutman", apiHandle.GovThreeAboutMan) //行政组织树及相关人员 + apiRouter.POST("search_org_people", apiHandle.SearchOrgAndPeople) //角色组织与人员搜索列表 + apiRouter.POST("getcompanydeparment", apiHandle.GetCompanyDeparment) //获取当前行政组织的所有主行政部门 //职位(岗位) apiRouter.POST("positionlist", apiHandle.PositionList) //职位(岗位)列表 diff --git a/config/configDatabase/database.go b/config/configDatabase/database.go index de3ac57..2e5f0a3 100644 --- a/config/configDatabase/database.go +++ b/config/configDatabase/database.go @@ -2,6 +2,7 @@ package configDatabase import ( "fmt" + "time" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -56,6 +57,7 @@ func (m *MasterMysqlSetUp) OpenSql() *gorm.DB { sqlDb, _ := opDb.DB() sqlDb.SetMaxIdleConns(m.MaxIdleConns) sqlDb.SetMaxOpenConns(m.MaxOpenConns) + sqlDb.SetConnMaxLifetime(time.Hour) return opDb } } else { @@ -65,6 +67,7 @@ func (m *MasterMysqlSetUp) OpenSql() *gorm.DB { sqlDb, _ := opDb.DB() sqlDb.SetMaxIdleConns(m.MaxIdleConns) sqlDb.SetMaxOpenConns(m.MaxOpenConns) + sqlDb.SetConnMaxLifetime(time.Hour) return opDb } } diff --git a/config_server/configDatabase/database.go b/config_server/configDatabase/database.go index de3ac57..3bbeb5f 100644 --- a/config_server/configDatabase/database.go +++ b/config_server/configDatabase/database.go @@ -2,6 +2,7 @@ package configDatabase import ( "fmt" + "time" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -56,6 +57,7 @@ func (m *MasterMysqlSetUp) OpenSql() *gorm.DB { sqlDb, _ := opDb.DB() sqlDb.SetMaxIdleConns(m.MaxIdleConns) sqlDb.SetMaxOpenConns(m.MaxOpenConns) + sqlDb.SetConnMaxLifetime(5 * time.Minute) return opDb } } else { @@ -65,6 +67,7 @@ func (m *MasterMysqlSetUp) OpenSql() *gorm.DB { sqlDb, _ := opDb.DB() sqlDb.SetMaxIdleConns(m.MaxIdleConns) sqlDb.SetMaxOpenConns(m.MaxOpenConns) + sqlDb.SetConnMaxLifetime(5 * time.Minute) return opDb } } diff --git a/models/org_cont_type.go b/models/org_cont_type.go index 5029334..ea7e853 100644 --- a/models/org_cont_type.go +++ b/models/org_cont_type.go @@ -5,10 +5,10 @@ import ( "strings" ) -//职务信息及类别、等级视图 +// 职务信息及类别、等级视图 type OrgContType struct { Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` - Number string `json:"number" gorm:"column:number;type:varchar(50) unsigned;default:'';not null;comment:行政编码"` + Number string `json:"number" gorm:"column:numbe;type:varchar(50) unsigned;default:'';not null;comment:行政编码"` Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:组织名称"` Superior int64 `json:"superior" gorm:"column:superior;type:bigint(20) unsigned;default:0;not null;comment:上级ID"` State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` @@ -21,7 +21,7 @@ func (OrgContType *OrgContType) TableName() string { return "org_cont_type" } -//获取详细内容 +// 获取详细内容 func (cont *OrgContType) GetCont(whereMap interface{}, field ...string) (err error) { gormDb := overall.CONSTANT_DB_HR.Model(&cont) if len(field) > 0 { diff --git a/overall/overallhandle/overall_handle.go b/overall/overallhandle/overall_handle.go index 5c5a62f..37f8edd 100644 --- a/overall/overallhandle/overall_handle.go +++ b/overall/overallhandle/overall_handle.go @@ -347,7 +347,7 @@ func GovThreeList(parentId int64, govAry []OutGovCont) []govThree { // fmt.Printf("govAry---------------->%v\n", govAry) for _, v := range govAry { // var zhucont govThree - // fmt.Printf("govAry---------------->%v\n", v.Superior) + if v.Superior == parentId { child := GovThreeList(v.Id, govAry) diff --git a/overall/overallhandle/type.go b/overall/overallhandle/type.go index b7581fc..b01495a 100644 --- a/overall/overallhandle/type.go +++ b/overall/overallhandle/type.go @@ -43,6 +43,7 @@ type OutGovCont struct { models.AdministrativeOrganization ClassName string `json:"classname" gorm:"column:classname;type:varchar(255) unsigned;default:'';not null;comment:行政组织分类名称"` Level int64 `json:"level" gorm:"column:level;type:int(5) unsigned;default:1;not null;comment:级别"` + IsMan int `json:"isman"` //1:行政组织;2:人 } //组织架构树