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.
141 lines
3.3 KiB
141 lines
3.3 KiB
|
2 years ago
|
package statistics
|
||
|
|
|
||
|
|
import (
|
||
|
|
"key_performance_indicators/models/modelshr"
|
||
|
|
"key_performance_indicators/overall"
|
||
|
|
"key_performance_indicators/overall/publicmethod"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-08-17 16:44:24
|
||
|
|
@ 功能: 行政组织成绩单(新版)
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (a *ApiMethod) OrgTranscriptNew(c *gin.Context) {
|
||
|
|
//获取登录人信息
|
||
|
|
context, err := publicmethod.LoginMyCont(c)
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(1, err, c, "您无权进行此操作!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var requestData TranscriptTable
|
||
|
|
c.ShouldBindJSON(&requestData)
|
||
|
|
//获取当前访问人的公司组织架构
|
||
|
|
var orgList []modelshr.AdministrativeOrganization
|
||
|
|
gromDb := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`,`sort`").Where("ispower = 1 AND state = 1 AND organization_type > 2")
|
||
|
|
if requestData.Group != "" {
|
||
|
|
gromDb = gromDb.Where("superior = ?", requestData.Group)
|
||
|
|
} else {
|
||
|
|
gromDb = gromDb.Where("superior = ?", context.Company)
|
||
|
|
}
|
||
|
|
if requestData.Department != "" {
|
||
|
|
gromDb = gromDb.Where("`id` = ?", requestData.Department)
|
||
|
|
}
|
||
|
|
err = gromDb.Find(&orgList).Error
|
||
|
|
if err != nil {
|
||
|
|
response.Result(102, err, "没有查询到数据", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(orgList) <= 0 {
|
||
|
|
response.Result(103, err, "没有查询到数据", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var orgAry []modelshr.AdministrativeOrganization //行政组织列表
|
||
|
|
for _, ov := range orgList {
|
||
|
|
if ov.Id != 163 && ov.Id != 281 {
|
||
|
|
sunOrgList, orgSunErr := getSunOrgList(ov.Id, "`id`", "`name`", "`sort`")
|
||
|
|
if orgSunErr == nil && len(sunOrgList) > 0 {
|
||
|
|
orgAry = append(orgAry, sunOrgList...)
|
||
|
|
} else {
|
||
|
|
orgAry = append(orgAry, ov)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
//计算要查询的年份
|
||
|
|
currentYear := publicmethod.ComputingTime(time.Now().Unix(), 1) //当前年
|
||
|
|
todayYear := currentYear //今年
|
||
|
|
if requestData.Year != "" {
|
||
|
|
yearInt64, _ := strconv.ParseInt(requestData.Year, 10, 64)
|
||
|
|
currentYear = yearInt64
|
||
|
|
}
|
||
|
|
//计算月
|
||
|
|
var monthTody []int64
|
||
|
|
if len(requestData.Month) < 1 {
|
||
|
|
if currentYear == todayYear {
|
||
|
|
monthTodyIng := publicmethod.ComputingTime(time.Now().Unix(), 3)
|
||
|
|
var montInt64 int64
|
||
|
|
for montInt64 = 1; montInt64 <= monthTodyIng; montInt64++ {
|
||
|
|
monthTody = append(monthTody, montInt64)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
var montInt64All int64
|
||
|
|
for montInt64All = 1; montInt64All <= 12; montInt64All++ {
|
||
|
|
monthTody = append(monthTody, montInt64All)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
for _, mmv := range requestData.Month {
|
||
|
|
monthTody = append(monthTody, int64(mmv))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//保证月份不为负数
|
||
|
|
if len(monthTody) < 1 {
|
||
|
|
monthTody = append(monthTody, 1)
|
||
|
|
}
|
||
|
|
/*
|
||
|
|
设定协程
|
||
|
|
遍历行政组织,并发计算
|
||
|
|
*/
|
||
|
|
var orgTranscript TranscriptTableData
|
||
|
|
for _, v := range orgAry {
|
||
|
|
// if v.Id == 362 {
|
||
|
|
syncProcess.Add(1)
|
||
|
|
go orgTranscript.StaticticsOrgTimeResult(v, currentYear, monthTody)
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
syncProcess.Wait()
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2023-08-18 08:16:52
|
||
|
|
@ 功能: 计算每个行政组织得分
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (t *TranscriptTableData) EveryOrgCensusResult(orgCont modelshr.AdministrativeOrganization, year int64, month []int64) {
|
||
|
|
//锁操作
|
||
|
|
t.mutext.Lock()
|
||
|
|
defer t.mutext.Unlock()
|
||
|
|
|
||
|
|
syncProcess.Done() //结束本协程
|
||
|
|
}
|