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.
471 lines
12 KiB
471 lines
12 KiB
|
2 years ago
|
package personnelapi
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"hr_server/models"
|
||
|
|
"hr_server/models/hrmodels"
|
||
|
|
"hr_server/overall"
|
||
|
|
"hr_server/overall/overallhandle"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-06-29 15:10:35
|
||
|
|
@ 功能: 离职率
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (s *StaffApi) DimissionRate(c *gin.Context) {
|
||
|
|
var requestData TurnoverRate
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
requestData.Id = 313
|
||
|
|
}
|
||
|
|
if requestData.Id == 0 {
|
||
|
|
requestData.Id = 313
|
||
|
|
}
|
||
|
|
currentTime := time.Now().Unix()
|
||
|
|
statisticalTime := currentTime
|
||
|
|
if requestData.Time != "" {
|
||
|
|
var timeCont overallhandle.DateTimeTotimes
|
||
|
|
timeCont.BaisStrToTime(requestData.Time)
|
||
|
|
statisticalTime = timeCont.AllTime
|
||
|
|
}
|
||
|
|
//行政组织
|
||
|
|
var orgList []models.AdministrativeOrganization
|
||
|
|
err = overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`,`name`").Where("`state` = 1 AND `superior` = ?", requestData.Id).Order("`sort` ASC").Find(&orgList).Error
|
||
|
|
if err != nil {
|
||
|
|
overallhandle.Result(107, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
currentYear := overallhandle.ComputingTime(statisticalTime, 1)
|
||
|
|
currentMonths := overallhandle.ComputingTime(statisticalTime, 3)
|
||
|
|
// var i int64
|
||
|
|
if currentYear != overallhandle.ComputingTime(currentTime, 1) {
|
||
|
|
currentMonths = 12
|
||
|
|
}
|
||
|
|
var calRateCont CalTurRateContBlack
|
||
|
|
calRateCont.CurrentOrgId = requestData.Id
|
||
|
|
for _, v := range orgList { //行政组织
|
||
|
|
calRateCont.Dfg(currentYear, currentMonths, v)
|
||
|
|
}
|
||
|
|
fmt.Printf("行政组织总数----->%v----->%v\n", len(orgList), len(calRateCont.List))
|
||
|
|
overallhandle.Result(0, calRateCont, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *CalTurRateContBlack) Dfg(years, months int64, orgCont models.AdministrativeOrganization) {
|
||
|
|
// defer synPro.Done()
|
||
|
|
var contData SendCalTurRateCont
|
||
|
|
contData.OrgId = orgCont.Id
|
||
|
|
contData.OrgName = orgCont.Name
|
||
|
|
var sunAry overallhandle.AllSunList[int64]
|
||
|
|
sunAry.GetAllSunOrg(orgCont.Id)
|
||
|
|
|
||
|
|
var sumPeople int64
|
||
|
|
overall.CONSTANT_DB_HR.Model(&models.PersonArchives{}).Select("`id`").Where("admin_org IN ? AND emp_type BETWEEN ? AND ?", sunAry.SunList, 1, 10).Count(&sumPeople)
|
||
|
|
|
||
|
|
var i int64
|
||
|
|
for i = 1; i <= months; i++ {
|
||
|
|
var timeCont overallhandle.DateTimeTotimes
|
||
|
|
timeCont.BaisStrToTime(fmt.Sprintf("%v-%v-01 00:00:00", years, i))
|
||
|
|
// fmt.Printf("时间--->%v\n", timeCont.Time)
|
||
|
|
hjsdk := overallhandle.UnixTimeToDay(timeCont.AllTime, 14)
|
||
|
|
startTime, endTime := overallhandle.GetAppointMonthStarAndEndTimeEs(hjsdk)
|
||
|
|
var reatCount int64
|
||
|
|
overall.CONSTANT_DB_HR.Model(&hrmodels.UserEmp{}).Select("`id`").Where("admin_org IN ? AND leave_date BETWEEN ? AND ?", sunAry.SunList, startTime, endTime).Count(&reatCount)
|
||
|
|
beiChuShu := sumPeople + reatCount
|
||
|
|
if beiChuShu == 0 {
|
||
|
|
contData.Odds = append(contData.Odds, 0)
|
||
|
|
} else {
|
||
|
|
|
||
|
|
reatVal := overallhandle.DecimalEs((float64(reatCount)/float64(beiChuShu))*100, 3)
|
||
|
|
contData.Odds = append(contData.Odds, reatVal)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
c.List = append(c.List, contData)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-06-29 16:10:50
|
||
|
|
@ 功能: 根据行政组织计算时间内的离职率
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (c *CalTurRateCont) CalculateTurnoverRate(years, months int64, orgCont models.AdministrativeOrganization) {
|
||
|
|
// defer synPro.Done()
|
||
|
|
var calCont CalculateTurnoverRateCont
|
||
|
|
calCont.OrgId = orgCont.Id
|
||
|
|
calCont.OrgName = orgCont.Name
|
||
|
|
calCont.Months = months
|
||
|
|
calCont.Odds = months
|
||
|
|
c.List = append(c.List, calCont)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-07-01 09:36:07
|
||
|
|
@ 功能: 获取单一行政组织离职率
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (s *StaffApi) GetOenOrgDimRate(c *gin.Context) {
|
||
|
|
userKey := c.Request.Header.Get("user-key")
|
||
|
|
myCont, myErr := overallhandle.GetCreetUserCont(userKey)
|
||
|
|
var requestData TurnoverRate
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
|
||
|
|
if myErr != nil {
|
||
|
|
requestData.Id = 309
|
||
|
|
} else {
|
||
|
|
requestData.Id = myCont.Company
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if requestData.Id == 0 {
|
||
|
|
if myErr != nil {
|
||
|
|
requestData.Id = 309
|
||
|
|
} else {
|
||
|
|
requestData.Id = myCont.Company
|
||
|
|
}
|
||
|
|
}
|
||
|
|
fmt.Printf("获得行政组织--->%v\n--->%v\n--->%v\n", userKey, myCont, requestData)
|
||
|
|
|
||
|
|
currentTime := time.Now().Unix()
|
||
|
|
statisticalTime := currentTime
|
||
|
|
if requestData.Time != "" {
|
||
|
|
var timeCont overallhandle.DateTimeTotimes
|
||
|
|
timeCont.BaisStrToTime(requestData.Time)
|
||
|
|
statisticalTime = timeCont.AllTime
|
||
|
|
}
|
||
|
|
//行政组织
|
||
|
|
var orgList []models.AdministrativeOrganization
|
||
|
|
err = overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`,`name`").Where("`state` = 1 AND `superior` = ?", requestData.Id).Order("`sort` ASC").Find(&orgList).Error
|
||
|
|
if err != nil {
|
||
|
|
overallhandle.Result(107, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
currentYear := overallhandle.ComputingTime(statisticalTime, 1)
|
||
|
|
currentMonths := overallhandle.ComputingTime(statisticalTime, 3)
|
||
|
|
// var i int64
|
||
|
|
if currentYear != overallhandle.ComputingTime(currentTime, 1) {
|
||
|
|
currentMonths = 12
|
||
|
|
}
|
||
|
|
var calRateCont CalTurRateContBlack
|
||
|
|
calRateCont.CurrentOrgId = requestData.Id
|
||
|
|
for _, v := range orgList { //行政组织
|
||
|
|
calRateCont.Dfg(currentYear, currentMonths, v)
|
||
|
|
}
|
||
|
|
fmt.Printf("行政组织总数----->%v----->%v\n", len(orgList), len(calRateCont.List))
|
||
|
|
overallhandle.Result(0, calRateCont, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-07-01 14:08:40
|
||
|
|
@ 功能: 获取公司指定年月的离职率
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (s *StaffApi) GetOrgTimeRate(c *gin.Context) {
|
||
|
|
userKey := c.Request.Header.Get("user-key")
|
||
|
|
myCont, myErr := overallhandle.GetCreetUserCont(userKey)
|
||
|
|
var requestData TurnoverRate
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
if myErr != nil {
|
||
|
|
requestData.Id = 309
|
||
|
|
} else {
|
||
|
|
requestData.Id = myCont.Company
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if requestData.Id == 0 {
|
||
|
|
if myErr != nil {
|
||
|
|
requestData.Id = 309
|
||
|
|
} else {
|
||
|
|
requestData.Id = myCont.Company
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//行政组织
|
||
|
|
var orgList []models.AdministrativeOrganization
|
||
|
|
err = overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`,`name`").Where("`state` = 1 AND `superior` = ?", requestData.Id).Order("`sort` ASC").Find(&orgList).Error
|
||
|
|
if err != nil {
|
||
|
|
overallhandle.Result(107, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
currentTime := time.Now().Unix()
|
||
|
|
hjsdk := overallhandle.UnixTimeToDay(currentTime, 14)
|
||
|
|
startTime, endTime := overallhandle.GetAppointMonthStarAndEndTimeEs(hjsdk)
|
||
|
|
if requestData.Time != "" {
|
||
|
|
var timeCont overallhandle.DateTimeTotimes
|
||
|
|
timeCont.BaisStrToTime(requestData.Time)
|
||
|
|
fmt.Printf("时间--->%v\n--->%v\n", requestData.Time, timeCont.Time)
|
||
|
|
hjsdks := overallhandle.UnixTimeToDay(timeCont.AllTime, 14)
|
||
|
|
fmt.Printf("时间--222->%v\n", hjsdks)
|
||
|
|
startTime, endTime = overallhandle.GetAppointMonthStarAndEndTimeEs(hjsdks)
|
||
|
|
}
|
||
|
|
var calRateCont SendPicRateInfo
|
||
|
|
calRateCont.CurrentOrgId = requestData.Id
|
||
|
|
for _, v := range orgList { //行政组织
|
||
|
|
calRateCont.MonthsRate(startTime, endTime, v)
|
||
|
|
}
|
||
|
|
overallhandle.Result(0, calRateCont, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-07-01 14:17:14
|
||
|
|
@ 功能: 计算指定月份离职率
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (c *SendPicRateInfo) MonthsRate(startTime, endTime int64, orgCont models.AdministrativeOrganization) {
|
||
|
|
var contData SendPicRateCont
|
||
|
|
contData.OrgId = orgCont.Id
|
||
|
|
contData.OrgName = orgCont.Name
|
||
|
|
var sunAry overallhandle.AllSunList[int64]
|
||
|
|
sunAry.GetAllSunOrg(orgCont.Id)
|
||
|
|
|
||
|
|
var sumPeople int64
|
||
|
|
overall.CONSTANT_DB_HR.Model(&models.PersonArchives{}).Select("`id`").Where("admin_org IN ? AND emp_type BETWEEN ? AND ?", sunAry.SunList, 1, 10).Count(&sumPeople)
|
||
|
|
var reatCount int64
|
||
|
|
overall.CONSTANT_DB_HR.Model(&hrmodels.UserEmp{}).Select("`id`").Where("admin_org IN ? AND leave_date BETWEEN ? AND ?", sunAry.SunList, startTime, endTime).Count(&reatCount)
|
||
|
|
beiChuShu := sumPeople + reatCount
|
||
|
|
if beiChuShu == 0 {
|
||
|
|
contData.Odds = 0
|
||
|
|
} else {
|
||
|
|
|
||
|
|
reatVal := overallhandle.DecimalEs((float64(reatCount)/float64(beiChuShu))*100, 3)
|
||
|
|
contData.Odds = reatVal
|
||
|
|
}
|
||
|
|
c.List = append(c.List, contData)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-07-01 15:49:31
|
||
|
|
@ 功能: 获取学历结构
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (s *StaffApi) GetEducationalStructure(c *gin.Context) {
|
||
|
|
userKey := c.Request.Header.Get("user-key")
|
||
|
|
myCont, myErr := overallhandle.GetCreetUserCont(userKey)
|
||
|
|
var requestData overallhandle.PublicId[int64]
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
if myErr != nil {
|
||
|
|
requestData.Id = 309
|
||
|
|
} else {
|
||
|
|
requestData.Id = myCont.Company
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if requestData.Id == 0 {
|
||
|
|
if myErr != nil {
|
||
|
|
requestData.Id = 309
|
||
|
|
} else {
|
||
|
|
requestData.Id = myCont.Company
|
||
|
|
}
|
||
|
|
}
|
||
|
|
var sunAry overallhandle.AllSunList[int64]
|
||
|
|
sunAry.GetAllSunOrg(requestData.Id)
|
||
|
|
//学历列表
|
||
|
|
var eduStruListCont []hrmodels.EducationalStructure
|
||
|
|
err = overall.CONSTANT_DB_HR.Distinct("`number`,MAX(`education`) as educationmax ").Where("admin_org IN ?", sunAry.SunList).Group("`number`").Find(&eduStruListCont).Error
|
||
|
|
if err != nil {
|
||
|
|
overallhandle.Result(0, err, c)
|
||
|
|
}
|
||
|
|
a1 := 0
|
||
|
|
a2 := 0
|
||
|
|
a3 := 0
|
||
|
|
a4 := 0
|
||
|
|
a5 := 0
|
||
|
|
a6 := 0
|
||
|
|
a7 := 0
|
||
|
|
a8 := 0
|
||
|
|
a9 := 0
|
||
|
|
a10 := 0
|
||
|
|
a11 := 0
|
||
|
|
a12 := 0
|
||
|
|
for _, v := range eduStruListCont {
|
||
|
|
switch v.EducationMax {
|
||
|
|
case 1:
|
||
|
|
a1++
|
||
|
|
case 2:
|
||
|
|
a2++
|
||
|
|
case 3:
|
||
|
|
a3++
|
||
|
|
case 4:
|
||
|
|
a4++
|
||
|
|
case 5:
|
||
|
|
a5++
|
||
|
|
case 6:
|
||
|
|
a6++
|
||
|
|
case 7:
|
||
|
|
a7++
|
||
|
|
case 8:
|
||
|
|
a8++
|
||
|
|
case 9:
|
||
|
|
a9++
|
||
|
|
case 10:
|
||
|
|
a10++
|
||
|
|
case 11:
|
||
|
|
a11++
|
||
|
|
case 12:
|
||
|
|
a12++
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
}
|
||
|
|
var sendEducStruCont []EducStruCont
|
||
|
|
sumPie := a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12
|
||
|
|
if a1 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a1)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "初中及以下", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a2 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a2)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "中专", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a3 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a3)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "高中", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a4 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a4)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "中技", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a5 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a5)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "高技", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a6 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a6)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "函数专科", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a7 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a7)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "大学专科", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a8 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a8)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "函数本科", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a9 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a9)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "大学本科", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a10 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a10)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "硕士研究生", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a11 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a11)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "博士研究生", Percentage: proportion})
|
||
|
|
}
|
||
|
|
if a12 != 0 {
|
||
|
|
var proportion float64
|
||
|
|
if sumPie != 0 {
|
||
|
|
proportion = overallhandle.DecimalEs((float64(a12)/float64(sumPie))*100, 3)
|
||
|
|
}
|
||
|
|
sendEducStruCont = append(sendEducStruCont, EducStruCont{Education: "专家、教授", Percentage: proportion})
|
||
|
|
}
|
||
|
|
overallhandle.Result(0, sendEducStruCont, c)
|
||
|
|
}
|