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.
231 lines
6.2 KiB
231 lines
6.2 KiB
package statistics
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"key_performance_indicators/models/modelshr"
|
|
"key_performance_indicators/overall"
|
|
"key_performance_indicators/overall/publicmethod"
|
|
"sort"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-08 11:22:10
|
|
@ 功能: 行政组织年度成绩单
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) OrgTargetAnnualStatistics(c *gin.Context) {
|
|
//获取登录人信息
|
|
context, _ := publicmethod.LoginMyCont(c)
|
|
var requestData OrgAnnualStatistics
|
|
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.OrgId != "" {
|
|
gromDb = gromDb.Where("superior = ?", requestData.OrgId)
|
|
} else {
|
|
gromDb = gromDb.Where("superior = ?", context.Company)
|
|
}
|
|
err := gromDb.Find(&orgList).Error
|
|
if err != nil && len(orgList) < 1 {
|
|
response.Result(102, 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.Years != "" {
|
|
yearInt64, _ := strconv.ParseInt(requestData.Years, 10, 64)
|
|
currentYear = yearInt64
|
|
}
|
|
//计算月
|
|
var monthTody []int64
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
//保证月份不为负数
|
|
if len(monthTody) < 1 {
|
|
monthTody = append(monthTody, 1)
|
|
}
|
|
var sendList SendOrgAnnualStatistics
|
|
var orgTranscriptList OrgTranscript
|
|
for _, v := range monthTody {
|
|
sendList.XAxis = append(sendList.XAxis, fmt.Sprintf("%v月", v))
|
|
}
|
|
for _, v := range orgAry {
|
|
sendList.Legend = append(sendList.Legend, v.Name)
|
|
syncProcess.Add(1)
|
|
go orgTranscriptList.CalculateGrades(v, currentYear, monthTody)
|
|
}
|
|
syncProcess.Wait()
|
|
readStatisticsData := orgTranscriptList.readTranscriptData() //读取通道数据
|
|
if len(readStatisticsData) > 0 {
|
|
sendList.MaxScore = readStatisticsData[0].MaxScore
|
|
sendList.MinScore = readStatisticsData[0].MinScore
|
|
}
|
|
//根据维度序号排序
|
|
sort.Slice(readStatisticsData, func(i, j int) bool {
|
|
return readStatisticsData[i].Scort < readStatisticsData[j].Scort
|
|
})
|
|
for _, v := range readStatisticsData {
|
|
if sendList.MaxScore <= v.MaxScore {
|
|
sendList.MaxScore = v.MaxScore
|
|
}
|
|
if sendList.MinScore >= v.MinScore {
|
|
sendList.MinScore = v.MinScore
|
|
}
|
|
}
|
|
if sendList.MaxScore > 0 {
|
|
if sendList.MaxScore > 1 {
|
|
sendList.MaxScore = sendList.MaxScore + 1
|
|
} else {
|
|
sendList.MaxScore = sendList.MaxScore + 0.1
|
|
}
|
|
} else {
|
|
if sendList.MaxScore < -1 {
|
|
sendList.MaxScore = sendList.MaxScore + 1
|
|
} else {
|
|
sendList.MaxScore = sendList.MaxScore + 0.1
|
|
}
|
|
}
|
|
if sendList.MinScore > 0 {
|
|
if sendList.MinScore > 1 {
|
|
sendList.MinScore = sendList.MinScore - 1
|
|
} else {
|
|
sendList.MinScore = sendList.MinScore - 0.1
|
|
}
|
|
} else {
|
|
if sendList.MinScore < -1 {
|
|
sendList.MinScore = sendList.MinScore - 1
|
|
} else {
|
|
sendList.MinScore = sendList.MinScore - 0.1
|
|
}
|
|
}
|
|
sendList.Series = readStatisticsData
|
|
|
|
publicmethod.Result(0, sendList, c)
|
|
}
|
|
func (o *OrgTranscript) CalculateGrades(orgInfo modelshr.AdministrativeOrganization, currentYear int64, months []int64) {
|
|
//锁操作
|
|
o.mutext.Lock()
|
|
defer o.mutext.Unlock()
|
|
|
|
var orgSictesCont SeriesList
|
|
orgSictesCont.Name = orgInfo.Name
|
|
orgSictesCont.Scort = orgInfo.Sort
|
|
// var monthOrgScore OrgTranscriptScore
|
|
|
|
var everyMonthScore countEveryDepartmentMonthScore
|
|
|
|
for _, v := range months {
|
|
planCont, err := publicmethod.GetPlanVresion(orgInfo.Id, currentYear, v)
|
|
// fmt.Printf("planCont:%v\n%v\n", planCont, err)
|
|
if err == nil {
|
|
var planVersioInfo []AddDutyNewCont
|
|
jsonErr := json.Unmarshal([]byte(planCont.Content), &planVersioInfo)
|
|
if jsonErr == nil {
|
|
syncProcessDepartTarget.Add(1)
|
|
//按月份计算
|
|
go everyMonthScore.everyMonthCalculateNew(orgInfo.Id, currentYear, v, planVersioInfo)
|
|
}
|
|
}
|
|
}
|
|
syncProcessDepartTarget.Wait()
|
|
everyMonthScoreList := everyMonthScore.readMyDayData()
|
|
if len(everyMonthScoreList) > 0 {
|
|
orgSictesCont.MaxScore = everyMonthScoreList[0].Score
|
|
orgSictesCont.MinScore = everyMonthScoreList[0].Score
|
|
}
|
|
sort.Slice(everyMonthScoreList, func(i, j int) bool {
|
|
return everyMonthScoreList[i].MonthVal < everyMonthScoreList[j].MonthVal
|
|
})
|
|
// fmt.Printf("层级:%v\n", everyMonthScoreList)
|
|
|
|
for _, v := range everyMonthScoreList {
|
|
|
|
if orgSictesCont.MaxScore <= v.Score {
|
|
orgSictesCont.MaxScore = v.Score
|
|
}
|
|
if orgSictesCont.MinScore > v.Score {
|
|
orgSictesCont.MinScore = v.Score
|
|
}
|
|
orgSictesCont.DataList = append(orgSictesCont.DataList, v.Score)
|
|
}
|
|
o.ScoreStatistics = append(o.ScoreStatistics, orgSictesCont)
|
|
syncProcess.Done()
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-08 13:09:27
|
|
@ 功能: 计算行政组织每月成绩
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
// func (o *OrgTranscriptScore) CalculateGrades(orgId, years, months int64) {
|
|
// o.mutext.Lock()
|
|
// defer o.mutext.Unlock()
|
|
// var scoreInfo MonthOrgScore
|
|
// scoreInfo.Months = months
|
|
// planCont, err := publicmethod.GetPlanVresion(orgId, years, months)
|
|
// if err == nil {
|
|
// var planVersioInfo []AddDutyNewCont
|
|
// jsonErr := json.Unmarshal([]byte(planCont.Content), &planVersioInfo)
|
|
// }
|
|
|
|
// o.ScoreList = append(o.ScoreList, scoreInfo)
|
|
// syncProcessDepartTarget.Done()
|
|
// }
|
|
|