package statistics
import (
"encoding/json"
"fmt"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"sort"
"strconv"
"strings"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/gin-gonic/gin"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 10 : 44 : 25
@ 功能 : 行政组织成绩单
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) OrgTranscript ( 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 )
}
}
}
// fmt.Printf("orgAry---------------------->%v\n", orgAry)
//计算要查询的年份
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 ( )
readStatisticsData := orgTranscript . readTranscriptData ( ) //读取通道数据
// response.Result(0, readStatisticsData, "查询完成", c)
// return
//根据维度序号排序
sort . Slice ( readStatisticsData , func ( i , j int ) bool {
return readStatisticsData [ i ] . Sort < readStatisticsData [ j ] . Sort
} )
var AScore float64 = 0
var BScore float64 = 0
var CScore float64 = 0
var DScore float64 = 0
var EScore float64 = 0
var FScore float64 = 0
var GScore float64 = 0
var HScore float64 = 0
var IScore float64 = 0
var JScore float64 = 0
var KScore float64 = 0
var LScore float64 = 0
jiBuQi := 0
var echarsList TranscriptTableDateListChars
var echarsListOrg TranscriptTableDateListChars
if len ( requestData . Month ) > 0 {
var monthAry [ ] int
for i := 1 ; i <= 12 ; i ++ {
if publicmethod . IsInTrue [ int ] ( i , requestData . Month ) && ! publicmethod . IsInTrue [ string ] ( fmt . Sprintf ( "%v月" , i ) , echarsList . XLine ) {
echarsList . XLine = append ( echarsList . XLine , fmt . Sprintf ( "%v月" , i ) )
monthAry = append ( monthAry , i )
echarsListOrg . Cylindrical = append ( echarsListOrg . Cylindrical , fmt . Sprintf ( "%v月" , i ) )
}
}
} else {
echarsList . XLine = append ( echarsList . XLine , "1月" , "2月" , "3月" , "4月" , "5月" , "6月" , "7月" , "8月" , "9月" , "10月" , "11月" , "12月" )
}
var orgFen orgShierTongji
// var dfgfd []YlineData
for _ , readv := range readStatisticsData {
AScore = AScore + readv . A
BScore = BScore + readv . B
CScore = CScore + readv . C
DScore = DScore + readv . D
EScore = EScore + readv . E
FScore = FScore + readv . F
GScore = GScore + readv . G
HScore = HScore + readv . H
IScore = IScore + readv . I
JScore = JScore + readv . J
KScore = KScore + readv . K
LScore = LScore + readv . L
jiBuQi ++
echarsList . Cylindrical = append ( echarsList . Cylindrical , readv . Department )
echarsListOrg . XLine = append ( echarsListOrg . XLine , readv . Department )
var cyLineAry_1 YlineData
cyLineAry_1 . Name = readv . Department
// var yZhoue YlineData
if readv . A == - 10000 {
readv . A = 0
}
if readv . B == - 10000 {
readv . B = 0
}
if readv . C == - 10000 {
readv . C = 0
}
if readv . D == - 10000 {
readv . D = 0
}
if readv . E == - 10000 {
readv . E = 0
}
if readv . F == - 10000 {
readv . F = 0
}
if readv . G == - 10000 {
readv . G = 0
}
if readv . H == - 10000 {
readv . H = 0
}
if readv . I == - 10000 {
readv . I = 0
}
if readv . J == - 10000 {
readv . J = 0
}
if readv . K == - 10000 {
readv . K = 0
}
if readv . L == - 10000 {
readv . L = 0
}
if len ( requestData . Month ) > 0 {
if publicmethod . IsInTrue [ int ] ( 1 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 1))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . A )
}
if publicmethod . IsInTrue [ int ] ( 2 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 2))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . B )
}
if publicmethod . IsInTrue [ int ] ( 3 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 3))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . C )
}
if publicmethod . IsInTrue [ int ] ( 4 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 4))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . D )
}
if publicmethod . IsInTrue [ int ] ( 5 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 5))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . E )
}
if publicmethod . IsInTrue [ int ] ( 6 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 6))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . F )
}
if publicmethod . IsInTrue [ int ] ( 7 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 7))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . G )
}
if publicmethod . IsInTrue [ int ] ( 8 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 8))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . H )
}
if publicmethod . IsInTrue [ int ] ( 9 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 9))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . I )
}
if publicmethod . IsInTrue [ int ] ( 10 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 10))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . J )
}
if publicmethod . IsInTrue [ int ] ( 11 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 11))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . K )
}
if publicmethod . IsInTrue [ int ] ( 12 , requestData . Month ) {
// echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 12))
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . L )
}
} else {
cyLineAry_1 . Data = append ( cyLineAry_1 . Data , readv . A , readv . B , readv . C , readv . D , readv . E , readv . F , readv . G , readv . H , readv . I , readv . J , readv . K , readv . L )
// cyLineAry_2.Data = append(cyLineAry_1.Data, readv.A, readv.B, readv.C, readv.D, readv.E, readv.F, readv.G, readv.H, readv.I, readv.J, readv.K, readv.L)
}
orgFen . A = append ( orgFen . A , readv . A )
orgFen . B = append ( orgFen . B , readv . B )
orgFen . C = append ( orgFen . C , readv . C )
orgFen . D = append ( orgFen . D , readv . D )
orgFen . E = append ( orgFen . E , readv . E )
orgFen . F = append ( orgFen . F , readv . F )
orgFen . G = append ( orgFen . G , readv . G )
orgFen . H = append ( orgFen . H , readv . H )
orgFen . I = append ( orgFen . I , readv . I )
orgFen . J = append ( orgFen . J , readv . J )
orgFen . K = append ( orgFen . K , readv . K )
orgFen . L = append ( orgFen . L , readv . L )
// jsonStr, _ := json.Marshal(orgFen.A)
// fmt.Printf("orgFen------1---->%v\n", string(jsonStr))
echarsList . YLine = append ( echarsList . YLine , cyLineAry_1 )
// echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2)
}
// jsonStrwww, _ := json.Marshal(orgFen)
// fmt.Printf("orgFen---------->%v\n", string(jsonStrwww))
if jiBuQi > 0 {
var pingJunFen TranscriptTableDateList
pingJunFen . DepartmentId = "0"
pingJunFen . Department = "平均分"
pingJunFen . A = publicmethod . DecimalEs ( AScore / float64 ( jiBuQi ) , 2 )
pingJunFen . B = publicmethod . DecimalEs ( BScore / float64 ( jiBuQi ) , 2 )
pingJunFen . C = publicmethod . DecimalEs ( CScore / float64 ( jiBuQi ) , 2 )
pingJunFen . D = publicmethod . DecimalEs ( DScore / float64 ( jiBuQi ) , 2 )
pingJunFen . E = publicmethod . DecimalEs ( EScore / float64 ( jiBuQi ) , 2 )
pingJunFen . F = publicmethod . DecimalEs ( FScore / float64 ( jiBuQi ) , 2 )
pingJunFen . G = publicmethod . DecimalEs ( GScore / float64 ( jiBuQi ) , 2 )
pingJunFen . H = publicmethod . DecimalEs ( HScore / float64 ( jiBuQi ) , 2 )
pingJunFen . I = publicmethod . DecimalEs ( IScore / float64 ( jiBuQi ) , 2 )
pingJunFen . J = publicmethod . DecimalEs ( JScore / float64 ( jiBuQi ) , 2 )
pingJunFen . K = publicmethod . DecimalEs ( KScore / float64 ( jiBuQi ) , 2 )
pingJunFen . L = publicmethod . DecimalEs ( LScore / float64 ( jiBuQi ) , 2 )
readStatisticsData = append ( readStatisticsData , pingJunFen )
}
var monthInt [ ] int
if len ( requestData . Month ) <= 0 {
for dkj := 1 ; dkj <= 12 ; dkj ++ {
monthInt = append ( monthInt , dkj )
}
} else {
monthInt = requestData . Month
}
// fmt.Printf("monthInt---------->%v\n", monthInt)
for _ , mvv := range monthInt {
switch mvv {
case 1 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "1月"
cyLineAry_2 . Data = orgFen . A
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 2 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "2月"
cyLineAry_2 . Data = orgFen . B
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 3 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "3月"
cyLineAry_2 . Data = orgFen . C
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 4 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "4月"
cyLineAry_2 . Data = orgFen . D
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 5 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "5月"
cyLineAry_2 . Data = orgFen . E
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 6 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "6月"
cyLineAry_2 . Data = orgFen . F
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 7 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "7月"
cyLineAry_2 . Data = orgFen . G
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 8 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "8月"
cyLineAry_2 . Data = orgFen . H
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 9 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "9月"
cyLineAry_2 . Data = orgFen . I
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 10 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "10月"
cyLineAry_2 . Data = orgFen . J
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 11 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "11月"
cyLineAry_2 . Data = orgFen . K
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
case 12 :
var cyLineAry_2 YlineData
cyLineAry_2 . Name = "12月"
cyLineAry_2 . Data = orgFen . L
echarsListOrg . YLine = append ( echarsListOrg . YLine , cyLineAry_2 )
}
}
outData := publicmethod . MapOut [ string ] ( )
outData [ "readStatisticsData" ] = readStatisticsData
outData [ "echarsList" ] = echarsList
outData [ "echarsListOrg" ] = echarsListOrg
response . Result ( 0 , outData , "查询完成" , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 11 : 14 : 37
@ 功能 : 时间维度统计个行政组织成绩
@ 参数
# orgCont 行政组织相关信息
# year 查询的年份
# month 查询月份边界
@ 返回值
#
@ 方法原型
#
* /
func ( t * TranscriptTableData ) StaticticsOrgTimeResult ( orgCont modelshr . AdministrativeOrganization , year int64 , month [ ] int64 ) {
//锁操作
t . mutext . Lock ( )
defer t . mutext . Unlock ( )
var pingJunFen TranscriptTableDateList
pingJunFen . DepartmentId = strconv . FormatInt ( orgCont . Id , 10 )
pingJunFen . Department = orgCont . Name
pingJunFen . Sort = orgCont . Sort
var everyMonthScore countEveryDepartmentMonthScore
for _ , v := range month {
// if v == 1 {
planCont , err := publicmethod . GetPlanVresion ( orgCont . Id , year , 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 ( orgCont . Id , year , v , planVersioInfo )
}
}
// }
}
syncProcessDepartTarget . Wait ( )
everyMonthScoreList := everyMonthScore . readMyDayData ( )
// fmt.Printf("everyMonthScoreList-->%v\n", everyMonthScoreList)
for _ , emslv := range everyMonthScoreList {
switch emslv . MonthVal {
case 1 :
pingJunFen . A = emslv . Score
case 2 :
pingJunFen . B = emslv . Score
case 3 :
pingJunFen . C = emslv . Score
case 4 :
pingJunFen . D = emslv . Score
case 5 :
pingJunFen . E = emslv . Score
case 6 :
pingJunFen . F = emslv . Score
case 7 :
pingJunFen . G = emslv . Score
case 8 :
pingJunFen . H = emslv . Score
case 9 :
pingJunFen . I = emslv . Score
case 10 :
pingJunFen . J = emslv . Score
case 11 :
pingJunFen . K = emslv . Score
case 12 :
pingJunFen . L = emslv . Score
default :
}
}
var monthIsFalse int64
for monthIsFalse = 1 ; monthIsFalse <= 12 ; monthIsFalse ++ {
if ! publicmethod . IsInTrue [ int64 ] ( monthIsFalse , month ) {
switch monthIsFalse {
case 1 :
pingJunFen . A = - 10000
case 2 :
pingJunFen . B = - 10000
case 3 :
pingJunFen . C = - 10000
case 4 :
pingJunFen . D = - 10000
case 5 :
pingJunFen . E = - 10000
case 6 :
pingJunFen . F = - 10000
case 7 :
pingJunFen . G = - 10000
case 8 :
pingJunFen . H = - 10000
case 9 :
pingJunFen . I = - 10000
case 10 :
pingJunFen . J = - 10000
case 11 :
pingJunFen . K = - 10000
case 12 :
pingJunFen . L = - 10000
default :
}
}
}
t . ScoreStatistics = append ( t . ScoreStatistics , pingJunFen )
// fmt.Printf("everyMonthScoreList-->%v\n", pingJunFen)
syncProcess . Done ( ) //结束本协程
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 14 : 20 : 46
@ 功能 : 按月份统计行政组织总成绩
@ 参数
# orgId 行政组织ID
# year 年
# month 月
# planVersion 部门当前执行的考核版本
@ 返回值
#
@ 方法原型
#
* /
func ( c * countEveryDepartmentMonthScore ) everyMonthCalculateNew ( orgId , year , month int64 , planVersion [ ] AddDutyNewCont ) {
//锁操作
c . mutext . Lock ( )
defer c . mutext . Unlock ( )
var weiDuScore float64 = 0 //维度分值
var zhiBiaoScore float64 = 0 //指标标准分值
var sumScore float64 = 0 //计算得分
for _ , v := range planVersion { //维度
weiDuScore = weiDuScore + float64 ( v . ZhiFraction )
for _ , sv := range v . Child { //指标
zhiBiaoScore = zhiBiaoScore + float64 ( sv . ReferenceScore )
if sv . Status == 3 { //为观察指标
sumScore = sumScore + float64 ( sv . ReferenceScore )
// fmt.Printf("为观察指标--->%v--->%v--->%v\n", sv.Name, sv.Id, sv.ReferenceScore)
} else {
var targetInfo modelskpi . EvaluationTarget
targetInfo . GetCont ( map [ string ] interface { } { "et_id" : sv . Id } , "et_type,et_cycle" )
if targetInfo . Type == 1 {
//定性考核
dingXingScore , _ := DingXingScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { month } , sv . Id )
sumScore = sumScore + dingXingScore
// fmt.Printf("定性考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingXingScore, sumScore)
} else {
var dingLiangScore float64
switch sv . Cycles {
case 5 : //季度
quarterList := [ ] int64 { 3 , 6 , 9 , 12 }
if ! publicmethod . IsInTrue [ int64 ] ( month , quarterList ) {
dingLiangScore = float64 ( sv . ReferenceScore )
fmt . Printf ( "季度指标--->%v--->%v--->%v\n" , sv . Name , sv . Id , dingLiangScore )
} else {
switch month {
case 3 :
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 1 ; i <= 3 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 3 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
case 6 :
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 4 ; i <= 6 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 6 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
case 9 :
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 7 ; i <= 9 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 9 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
case 12 :
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 10 ; i <= 12 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 12 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
default :
}
}
case 6 : //年度
if month == 12 {
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 1 ; i <= 12 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 12 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
// fmt.Printf("年度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore)
}
case 7 : //半年指标
switch month {
case 6 : //上半年
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 1 ; i <= 6 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 6 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
case 12 :
var sendList [ ] dingLiangKaoHe
isTrue := true
var dingLiangScoreGd float64 = 0
var fengDingZhi float64 = 0
for i := 7 ; i <= 12 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , year , int64 ( i ) , sv . Id , "" )
sendList = append ( sendList , sendListIng ... )
if i == 12 {
for _ , v := range sendListIng {
fengDingZhi = v . Capping
if v . MtOrAt == 2 {
dingLiangScoreGd = v . Score
isTrue = false
}
}
}
}
if ! isTrue {
dingLiangScore = dingLiangScoreGd
} else {
var daChengLv float64 = 0
var pingJunXiShu float64 = 0
for _ , j := range sendList {
daChengLv = daChengLv + j . CompletionRateAll
pingJunXiShu ++
}
if pingJunXiShu > 0 {
pingJunZhi := daChengLv / pingJunXiShu
dingLiangScore = publicmethod . DecimalEs ( GetQuantifyScore ( float64 ( sv . ReferenceScore ) , pingJunZhi , fengDingZhi ) , 2 )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
}
}
default :
dingLiangScore = float64 ( sv . ReferenceScore )
// fmt.Printf("半年指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore)
}
default : //月度指标
sendList , _ := GetDingLiangLog ( orgId , year , month , sv . Id , "" )
if len ( sendList ) < 1 {
dingLiangScore = float64 ( sv . ReferenceScore )
} else {
for _ , v := range sendList {
// if v.MtOrAt == 1 {
// }
dingLiangScore = dingLiangScore + v . Score
}
// sumScore = sumScore + dingLiangScore
}
}
dingLiangScoreGd , _ := publicmethod . DecimalNew ( dingLiangScore , 2 )
sumScore = sumScore + dingLiangScoreGd
// fmt.Printf("定量月度考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore, sumScore)
}
}
}
}
var everyMonthScoreInfo everyDepartmentScore
everyMonthScoreInfo . MonthVal = month
everyMonthScoreInfo . Score , _ = publicmethod . DecimalNew ( sumScore , 2 )
c . outData = append ( c . outData , everyMonthScoreInfo )
syncProcessDepartTarget . Done ( ) //结束本协程
}
func ( c * countEveryDepartmentMonthScore ) everyMonthCalculate ( orgId , year , month int64 , planVersion [ ] AddDutyNewCont ) {
//锁操作
c . mutext . Lock ( )
defer c . mutext . Unlock ( )
var weiDuScore float64 = 0 //维度分值
var zhiBiaoScore float64 = 0 //指标标准分值
var sumScore float64 = 0 //计算得分
for _ , v := range planVersion { //维度
weiDuScore = weiDuScore + float64 ( v . ZhiFraction )
for _ , sv := range v . Child { //指标
// if sv.Id == "13" {
zhiBiaoScore = zhiBiaoScore + float64 ( sv . ReferenceScore )
if sv . Status == 3 { //为观察指标
sumScore = sumScore + float64 ( sv . ReferenceScore )
// fmt.Printf("为观察指标--->%v--->%v--->%v\n", sv.Name, sv.Id, sv.ReferenceScore)
} else {
var targetInfo modelskpi . EvaluationTarget
targetInfo . GetCont ( map [ string ] interface { } { "et_id" : sv . Id } , "et_type,et_cycle" )
if sv . Cycles == 0 { //判断统计方式
sv . Cycles = targetInfo . Cycles
}
if targetInfo . Type == 1 {
//定性考核
dingXingScore , _ := DingXingScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { month } , sv . Id )
sumScore = sumScore + dingXingScore
// fmt.Printf("定性考核得分--->%v--->%v--->%v\n", sv.Name, sv.Id, dingXingScore)
} else {
var dingLiangScore float64
//定量考核
switch sv . Cycles {
case 5 : //季度指标
quarterList := [ ] int64 { 3 , 6 , 9 , 12 }
if ! publicmethod . IsInTrue [ int64 ] ( month , quarterList ) {
dingLiangScore = float64 ( sv . ReferenceScore )
// fmt.Printf("季度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore)
} else {
switch month {
case 3 :
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 1 , 2 , 3 } , sv . Id , sv . Cycles )
case 6 :
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 4 , 5 , 6 } , sv . Id , sv . Cycles )
case 9 :
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 7 , 8 , 9 } , sv . Id , sv . Cycles )
case 12 :
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 10 , 11 , 12 } , sv . Id , sv . Cycles )
default :
}
}
case 6 : //年度指标
if month == 12 {
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } , sv . Id , sv . Cycles )
} else {
dingLiangScore = float64 ( sv . ReferenceScore )
// fmt.Printf("年度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore)
}
case 7 : //半年指标
switch month {
case 6 :
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 1 , 2 , 3 , 4 , 5 , 6 } , sv . Id , sv . Cycles )
case 12 :
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { 7 , 8 , 9 , 10 , 11 , 12 } , sv . Id , sv . Cycles )
default :
dingLiangScore = float64 ( sv . ReferenceScore )
// fmt.Printf("半年指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore)
}
default : //月度指标
dingLiangScore , _ = DingLiangScoreCalculation ( orgId , year , sv . ReferenceScore , [ ] int64 { month } , sv . Id , sv . Cycles )
}
dingLiangScoreGd , _ := publicmethod . DecimalNew ( dingLiangScore , 2 )
sumScore = sumScore + dingLiangScoreGd
// fmt.Printf("定量考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScoreGd, sv.Cycles)
}
}
// }
}
}
var everyMonthScoreInfo everyDepartmentScore
everyMonthScoreInfo . MonthVal = month
everyMonthScoreInfo . Score , _ = publicmethod . DecimalNew ( sumScore , 2 )
c . outData = append ( c . outData , everyMonthScoreInfo )
syncProcessDepartTarget . Done ( ) //结束本协程
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 10 : 58 : 16
@ 功能 : 获取下级行政组织是否有主行政部门
@ 参数
# orgId 行政组织上级ID
@ 返回值
# orgList 行政组织子集列表
@ 方法原型
#
* /
func getSunOrgList ( orgId int64 , field ... string ) ( orgList [ ] modelshr . AdministrativeOrganization , ovErr error ) {
gormDb := overall . CONSTANT_DB_HR . Where ( "state = 1" )
if len ( field ) > 0 {
fieldStr := strings . Join ( field , "," )
gormDb = gormDb . Select ( fieldStr )
}
ovErr = gormDb . Where ( "ispower = 1 AND superior = ?" , orgId ) . Find ( & orgList ) . Error
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 14 : 46 : 27
@ 功能 : 指定时间段定性考核计算
@ 参数
# orgId 行政组织
# years 年
# targetScore 指标分值
# months 月份
# targetId 指标
@ 返回值
#
@ 方法原型
#
* /
func DingXingScoreCalculation ( orgId , years , targetScore int64 , months [ ] int64 , targetId string ) ( score float64 , EvalDepartment [ ] string ) {
var scoreFlowList [ ] modelskpi . ScoreFlow
err := overall . CONSTANT_DB_KPI . Model ( & modelskpi . ScoreFlow { } ) . Select ( "`sf_plus_reduce_score`,`sf_score`,`sf_count`" ) . Where ( "sf_reply IN ? AND sf_duty_department = ? AND sf_target_id = ? AND sf_year = ? AND sf_month IN ?" , [ ] int { 2 , 3 } , orgId , targetId , years , months ) . Find ( & scoreFlowList ) . Error
if err != nil || len ( scoreFlowList ) < 1 {
return float64 ( targetScore ) , [ ] string { }
}
var minusPoints float64 = 0 //获取减分
var extraPoints float64 = 0 //获取加分
for _ , v := range scoreFlowList {
quzhi := v . Score * int64 ( v . Count )
if v . PlusReduceScore == 1 {
extraPoints = extraPoints + float64 ( quzhi )
} else {
minusPoints = minusPoints + float64 ( quzhi )
}
var minusDepartment modelshr . AdministrativeOrganization
minErr := minusDepartment . GetCont ( map [ string ] interface { } { "id" : v . EvaluationDepartment } , "name" )
if minErr == nil {
if ! publicmethod . IsInTrue [ string ] ( minusDepartment . Name , EvalDepartment ) {
EvalDepartment = append ( EvalDepartment , minusDepartment . Name )
}
}
}
score = publicmethod . DecimalEs ( ( ( float64 ( targetScore ) + extraPoints / 100 ) - minusPoints / 100 ) , 2 )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 15 : 39 : 59
@ 功能 : 指定时间段定量考核计算
@ 参数
# orgId 行政组织
# years 年
# targetScore 指标分数
# months 月份
# targetId 指标Id
# cycles 1 : 班 ; 2 : 天 ; 3 : 周 ; 4 : 月 ; 5 : 季度 ; 6 : 年 ; 7 : 半年
@ 返回值
# score 得分
@ 方法原型
# func DingLiangScoreCalculation ( orgId , years , targetScore int64 , months [ ] int64 , targetId string , cycles int ) ( score float64 )
* /
func DingLiangScoreCalculation ( orgId , years , targetScore int64 , months [ ] int64 , targetId string , cycles int ) ( score float64 , EvalDepartment [ ] string ) {
var calculateScore float64 = 0
var passRate float64 = 0 //达成率
var cappingPrize float64 = 1 //达成率
for _ , vs := range months {
var flowLogList [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Where ( "`department` = ? AND `year` = ? AND `targetid` = ? AND `month` = ? AND fl_reply IN ?" , orgId , years , targetId , vs , [ ] int { 2 , 3 } ) . Find ( & flowLogList ) . Error
if err != nil || len ( flowLogList ) < 1 {
calculateScore = calculateScore + float64 ( targetScore )
fmt . Printf ( "指标分--abc->%v--->%v\n" , vs , targetScore )
passRate = passRate + 1
} else {
var sumScore float64 = 0
//循环计算相关指标得分
for _ , v := range flowLogList {
if v . ScoringMethod == 1 {
//自动计算
sumScoreing , passRateVal , _ , _ , cappingPrizeval := AnalysisReward ( targetId , v . Baseline , v . Edition , float64 ( targetScore ) , float64 ( v . Score ) , orgId , v . Year , v . Quarter , v . Month , cycles )
fmt . Printf ( "自动计算--->%v--->%v--->%v--->%v\n" , vs , sumScoreing , passRateVal , cappingPrizeval )
sumScore = sumScore + sumScoreing
passRate = passRate + passRateVal
cappingPrize = cappingPrizeval
} else {
//手动分
sumScore = sumScore + ( float64 ( v . ScoringScore ) / 100 )
passRate = passRate + 1
// fmt.Printf("手动分值--->%v\n", (float64(v.ScoringScore) / 100))
}
var minusDepartment modelshr . AdministrativeOrganization
minErr := minusDepartment . GetCont ( map [ string ] interface { } { "id" : v . EvaluationDepartment } , "name" )
if minErr == nil {
if ! publicmethod . IsInTrue [ string ] ( minusDepartment . Name , EvalDepartment ) {
EvalDepartment = append ( EvalDepartment , minusDepartment . Name )
}
}
}
calculateScore = calculateScore + sumScore
}
}
chushu := len ( months )
if chushu != 0 {
calculateScore = publicmethod . DecimalEs ( calculateScore / float64 ( chushu ) , 2 )
daChengLv := passRate / float64 ( chushu )
if daChengLv >= cappingPrize && cappingPrize != 0 {
calculateScore = publicmethod . DecimalEs ( cappingPrize * float64 ( targetScore ) , 2 )
} else {
calculateScore = publicmethod . DecimalEs ( daChengLv * float64 ( targetScore ) , 2 )
}
fmt . Printf ( "passRate:%v\nchushu:%v\ndaChengLv:%v\ncappingPrize:%v\ncalculateScore:%v\n" , passRate , chushu , daChengLv , cappingPrize , calculateScore )
}
score = calculateScore
return
}
func DingLiangScoreCalculationOld ( orgId , years , targetScore int64 , months [ ] int64 , targetId string , cycles int ) ( score float64 ) {
var flowLogList [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Where ( "`department` = ? AND `year` = ? AND `targetid` = ? AND `month` IN ? AND fl_reply IN ?" , orgId , years , targetId , months , [ ] int { 2 , 3 } ) . Find ( & flowLogList ) . Error
// fmt.Printf("targetId====>%v====>%v====>%v====>%v\n", targetId, err, flowLogList, len(flowLogList))
if err != nil || len ( flowLogList ) < 1 {
score = float64 ( targetScore )
return
}
var sumScore float64 = 0
//循环计算相关指标得分
for _ , v := range flowLogList {
if v . ScoringMethod == 1 {
//自动计算
sumScoreing , _ , _ , _ , _ := AnalysisReward ( targetId , v . Baseline , v . Edition , float64 ( targetScore ) , float64 ( v . Score ) , orgId , v . Year , v . Quarter , v . Month , cycles )
sumScore = sumScore + sumScoreing
} else {
//手动分
sumScore = sumScore + ( float64 ( v . ScoringScore ) / 100 )
// fmt.Printf("手动分值--->%v\n", (float64(v.ScoringScore) / 100))
}
}
if years > 2023 {
chushu := len ( months )
if chushu != 0 {
sumScore = publicmethod . DecimalEs ( sumScore / float64 ( chushu ) , 2 )
}
} else {
pingjun := false
for _ , v := range months {
if v > 6 && years == 2023 {
pingjun = true
}
}
if pingjun {
chushu := len ( months )
if chushu != 0 {
sumScore = publicmethod . DecimalEs ( sumScore / float64 ( chushu ) , 2 )
}
}
}
score = sumScore
// fmt.Printf("手动分值--2->%v\n", score)
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 27 15 : 59 : 23
@ 功能 : 计算单一定量指标得分
@ 参数
# targetId 指标
# rewardCont 上报时的全奖值 , 零奖值 , 封顶值设置
# targetScore 指标得分
# settlementScore 上报数值
# planKey 指标方案
# orgId 行政组织
# years 发生年
# quarter 发生季
# month 发生月
# cycles 1 : 班 ; 2 : 天 ; 3 : 周 ; 4 : 月 ; 5 : 季度 ; 6 : 年 ; 7 : 半年
@ 返回值
# score 得分
# completionRate 达成率
@ 方法原型
# score 指标得分
# completionRate 达成率
# zeroPrize 零奖值
# allPrize 全奖值
# cappingPrize 封顶值
* /
func AnalysisReward ( targetId , rewardCont , planKey string , targetScore , settlementScore float64 , orgId , years , quarter , month int64 , cycles int ) ( score , completionRate , zeroPrize , allPrize , cappingPrize float64 ) {
var currentTargetSeting FlowLogAllZreo
setIsTrue := true
var rewardAry [ ] FlowLogAllZreo
jsonErr := json . Unmarshal ( [ ] byte ( rewardCont ) , & rewardAry )
if jsonErr == nil {
//获取当前指标的全奖零奖值
for _ , v := range rewardAry {
if v . TargetId == targetId {
currentTargetSeting . Id = v . Id
currentTargetSeting . TargetId = v . TargetId //指标ID`
currentTargetSeting . Zeroprize = v . Zeroprize //零奖值"`
currentTargetSeting . Allprize = v . Allprize //全奖值"`
currentTargetSeting . Capping = v . Capping //封顶值"`
zeroPrize = v . Zeroprize //零奖值"`
allPrize = v . Allprize //全奖值"`
cappingPrize = v . Capping //封顶值"`
setIsTrue = false
}
}
}
isAll := false
if setIsTrue {
var setCont modelskpi . QuantitativeConfig
gormdb := overall . CONSTANT_DB_KPI . Where ( "`departmentid` = ? AND `target` = ? AND `year` = ?" , orgId , targetId , years )
switch cycles {
case 5 : //季度
gormdb = gormdb . Where ( "`timecopy` = ?" , quarter )
case 6 : //年
case 7 : //半年
banNian := 1
if ! publicmethod . IsInTrue [ int64 ] ( month , [ ] int64 { 1 , 2 , 3 , 4 , 5 , 6 } ) {
banNian = 2
}
gormdb = gormdb . Where ( "`timecopy` = ?" , banNian )
default :
gormdb = gormdb . Where ( "`timecopy` = ?" , month )
}
err := gormdb . Find ( setCont ) . Error
if err == nil {
currentTargetSeting . Id = strconv . FormatInt ( setCont . Id , 10 )
currentTargetSeting . TargetId = strconv . FormatInt ( setCont . Target , 10 ) //指标ID`
currentTargetSeting . Zeroprize = setCont . Zeroprize //零奖值"`
currentTargetSeting . Allprize = setCont . Allprize //全奖值"`
currentTargetSeting . Capping = setCont . CappingVal //封顶值"`
zeroPrize = setCont . Zeroprize //零奖值"`
allPrize = setCont . Allprize //全奖值"`
cappingPrize = setCont . CappingVal //封顶值"`
isAll = true
} else {
isAll = false
}
} else {
isAll = true
}
if isAll {
score , completionRate = TallyUpScore ( targetScore , settlementScore , currentTargetSeting . Zeroprize , currentTargetSeting . Allprize , currentTargetSeting . Capping )
fmt . Printf ( "计算单一定量指标得分--->%v\n--->%v\n--->%v\n" , settlementScore , score , completionRate )
} else {
completionRate = 1
score = targetScore
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 28 10 : 23 : 33
@ 功能 : 计算定量指标得分
@ 参数
# targetScore 指标分值
# actualValue 指标实际值
# zeroPrize 零奖值
# allPrize 全奖值
# cappingVal 封顶值
@ 返回值
# callBackScore 得分
# completionRate 达成率
@ 方法原型
# func TallyUpScore ( targetScore , actualValue , zeroPrize , allPrize , cappingVal float64 ) ( callBackScore , completionRate float64 )
* /
func TallyUpScore ( targetScore , actualValue , zeroPrize , allPrize , cappingVal float64 ) ( callBackScore , completionRate float64 ) {
// fmt.Printf("计算定量指标得分--->actualValue:%v\nzeroPrize:%v\nallPrize:%v\n", actualValue, zeroPrize, allPrize)
if zeroPrize == 0 && allPrize == 0 { //全奖值与零奖值都为0 那么达成率 100 和实际得分是 指标分
completionRate = 1
callBackScore = targetScore
} else {
if allPrize >= zeroPrize { //如果全奖值大于零奖值 执行正向操作
//stpe 1:判断提交实际数值是否小于等于零奖值
if actualValue <= zeroPrize { //满足此条件,那么达成率和实际得分都是0
completionRate = 0
callBackScore = 0
} else { //stpe 2:判断提交实际结算值大于零奖值
chuShu := actualValue - float64 ( zeroPrize ) //除数 = 实际值 - 零奖值
beiChuShu := float64 ( allPrize ) - float64 ( zeroPrize ) // 被除数 = 全奖值 - 零奖值
if beiChuShu != 0 { //stpe 3:判断被除数非零
completionRate = chuShu / beiChuShu //达成率
if completionRate <= 0 { //stpe 4:判断达成率小于等于零时。那么达成率和实际得分都是0
completionRate = 0
callBackScore = 0
} else {
//stpe 5:判断达成率是否等于大于封顶值
// fmt.Printf("判断达成率----->%v----->%v\n", completionRate*100, cappingVal)
if completionRate * 100 >= cappingVal / 100 {
if cappingVal > 0 { //stpe 6:判断封顶值是否大于0
callBackScore = ( cappingVal / 10000 ) * targetScore
// fmt.Printf("判断达成率---1-->%v----->%v\n", callBackScore, targetScore)
} else {
callBackScore = targetScore
// fmt.Printf("判断达成率-2--->%v----->%v\n", callBackScore, targetScore)
}
} else { //stpe 6:当达成率小于封顶值
callBackScore = completionRate * targetScore
// fmt.Printf("判断达成率--3--->%v----->%v\n", completionRate, targetScore)
}
}
} else { //被除数为零时,等式不成立。所以达成率和实际得分都是0
completionRate = 0
callBackScore = 0
}
}
} else { //如果全奖值小于于零奖值 执行反向操作
// fmt.Printf("全奖值小于零奖值--->zeroPrize:%v,allPrize:%v\n", zeroPrize, allPrize)
if ( actualValue >= zeroPrize ) || ( actualValue == 0 && ( zeroPrize != 0 || actualValue != 0 ) ) { //如果实际数值大于等于零奖值,那么达成率和实际得分都是0
chuShu := actualValue - float64 ( zeroPrize ) //除数 = 实际值 - 零奖值
beiChuShu := float64 ( allPrize ) - float64 ( zeroPrize ) // 被除数 = 全奖值 - 零奖值
if beiChuShu != 0 {
completionRate = chuShu / beiChuShu //达成率
} else {
completionRate = 0
}
callBackScore = 0
} else { //实际值小于零奖值
chuShu := actualValue - float64 ( zeroPrize ) //除数 = 实际值 - 零奖值
beiChuShu := float64 ( allPrize ) - float64 ( zeroPrize ) // 被除数 = 全奖值 - 零奖值
// fmt.Printf("全奖值被除数--->%v\n", beiChuShu)
if beiChuShu != 0 { //判断被除数非零
completionRate = chuShu / beiChuShu //达成率
if completionRate <= 0 { //判断达成率小于等于零时。那么达成率和实际得分都是0
completionRate = 0
callBackScore = 0
} else {
//stpe 5:判断达成率是否等于大于封顶值
if completionRate * 100 >= cappingVal / 100 {
if cappingVal > 0 { //stpe 6:判断封顶值是否大于0
callBackScore = ( cappingVal / 10000 ) * targetScore
} else {
callBackScore = targetScore
}
} else { //stpe 6:当达成率小于封顶值
callBackScore = completionRate * targetScore
}
// fmt.Printf("全奖值小于零奖值--->completionRate:%v,cappingVal:%v,completionRate:%v,targetScore:%v,callBackScore:%v\n", completionRate*100, cappingVal/100, completionRate, targetScore, callBackScore)
}
} else { //被除数为零时,等式不成立。所以达成率和实际得分都是0
completionRate = 0
callBackScore = 0
}
}
}
}
// callBackScore = publicmethod.DecimalEs(callBackScore, 2)
// completionRate = publicmethod.DecimalEs(completionRate, 4)
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 29 0 9 : 43 : 05
@ 功能 : 汇总详情定量历史记录
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) SummaryDetailsLiangLog ( c * gin . Context ) {
var requestData detailedResultsLog
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 101 , err , "数据获取失败!" , c )
return
}
if requestData . TargetId == "" {
response . Result ( 102 , err , "参数错误!请属入指标" , c )
return
}
if requestData . Department == "" {
response . Result ( 103 , err , "参数错误!请属入部门" , c )
return
}
if requestData . Year == 0 {
requestData . Year = publicmethod . ComputingTime ( time . Now ( ) . Unix ( ) , 1 )
}
if requestData . Months < 1 {
requestData . Months = 1
}
if requestData . Months > 12 {
requestData . Months = 12
}
orgId , _ := strconv . ParseInt ( requestData . Department , 10 , 64 )
monthInt := int64 ( requestData . Months )
var targetInfo modelskpi . EvaluationTarget
targetInfo . GetCont ( map [ string ] interface { } { "et_id" : requestData . TargetId } , "et_type,et_cycle" )
var sendList [ ] dingLiangKaoHe
switch targetInfo . Cycles {
case 5 : //季度指标
if publicmethod . IsInTrue [ int64 ] ( monthInt , [ ] int64 { 3 , 6 , 9 , 12 } ) {
if publicmethod . IsInTrue [ int64 ] ( monthInt , [ ] int64 { 1 , 2 , 3 } ) {
for i := 1 ; i <= 3 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
} else if publicmethod . IsInTrue [ int64 ] ( monthInt , [ ] int64 { 4 , 5 , 6 } ) {
for i := 4 ; i <= 6 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
} else if publicmethod . IsInTrue [ int64 ] ( monthInt , [ ] int64 { 7 , 8 , 9 } ) {
for i := 7 ; i <= 9 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
} else {
for i := 10 ; i <= 12 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
}
chushu := len ( sendList )
if chushu > 0 {
var sumScore float64 = 0
for _ , j := range sendList {
sumScore = sumScore + j . Score
}
var secondCont dingLiangKaoHe
secondCont . Score = publicmethod . DecimalEs ( sumScore / float64 ( chushu ) , 2 ) //得分
secondCont . MtOrAt = 1 //手动还是自动
secondCont . Cont = "平均分" //说明
sendList = append ( sendList , secondCont )
}
} else {
sendList , _ = GetDingLiangLog ( orgId , requestData . Year , monthInt , requestData . TargetId , "" )
}
case 6 : //年度指标
for i := 1 ; i <= 12 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
var sumScore float64 = 0
for _ , j := range sendList {
sumScore = sumScore + j . Score
}
var secondCont dingLiangKaoHe
secondCont . Score = publicmethod . DecimalEs ( sumScore / 12 , 2 ) //得分
secondCont . MtOrAt = 1 //手动还是自动
secondCont . Cont = "平均分" //说明
sendList = append ( sendList , secondCont )
case 7 : //半年指标
if publicmethod . IsInTrue [ int64 ] ( monthInt , [ ] int64 { 1 , 2 , 3 , 4 , 5 , 6 } ) {
for i := 1 ; i <= 6 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
} else {
for i := 7 ; i <= 12 ; i ++ {
sendListIng , _ := GetDingLiangLog ( orgId , requestData . Year , int64 ( i ) , requestData . TargetId , fmt . Sprintf ( "%v月份实际分值" , i ) )
sendList = append ( sendList , sendListIng ... )
}
}
var sumScore float64 = 0
for _ , j := range sendList {
sumScore = sumScore + j . Score
}
var secondCont dingLiangKaoHe
secondCont . Score = publicmethod . DecimalEs ( sumScore / 6 , 2 ) //得分
secondCont . MtOrAt = 1 //手动还是自动
secondCont . Cont = "平均分" //说明
secondCont . Nature = 1
sendList = append ( sendList , secondCont )
default :
sendList , _ = GetDingLiangLog ( orgId , requestData . Year , monthInt , requestData . TargetId , "" )
}
response . Result ( 0 , sendList , "查询完成!" , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 29 10 : 44 : 18
@ 功能 : 获取定量考核记录
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func GetDingLiangLog ( orgId , years , monthes int64 , targetId , cont string ) ( sendList [ ] dingLiangKaoHe , EvalDepartment [ ] string ) {
var flowLogList [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Where ( "`department` = ? AND `year` = ? AND `targetid` = ? AND `month` = ? AND fl_reply IN ?" , orgId , years , targetId , monthes , [ ] int { 2 , 3 } ) . Find ( & flowLogList ) . Error
if err != nil && len ( flowLogList ) < 1 {
return
} else {
for _ , v := range flowLogList {
var secondCont dingLiangKaoHe
targetScore , attribute , _ := GetTargetPlanScore ( v . Edition , targetId , orgId , years , monthes )
secondCont . Score , secondCont . CompletionRate , secondCont . Zeroprize , secondCont . Allprize , secondCont . Capping = AnalysisReward ( targetId , v . Baseline , v . Edition , targetScore , float64 ( v . Score ) , orgId , v . Year , v . Quarter , v . Month , attribute )
secondCont . Actual = publicmethod . DecimalEs ( float64 ( v . Score ) / 100 , 2 )
fmt . Printf ( "获取定量考核记录--->targetScore:%v\n--->attribute:%v\n--->Score:%v\n--->ScoringMethod:%v\n" , targetScore , attribute , secondCont . Score , v . ScoringMethod )
if v . ScoringMethod != 1 {
secondCont . Score = publicmethod . DecimalEs ( float64 ( v . ScoringScore ) / 100 , 2 )
}
fmt . Printf ( "获取定量考核记录-1-->targetScore:%v\n--->attribute:%v\n--->Score:%v\n--->ScoringMethod:%v\n--->ScoringScore:%v\n" , targetScore , attribute , secondCont . Score , v . ScoringMethod , v )
secondCont . MtOrAt = v . ScoringMethod
secondCont . Cont = fmt . Sprintf ( "%v%v" , v . Content , cont )
secondCont . Nature = attribute
if attribute == 3 {
secondCont . Score = targetScore
}
// fmt.Printf("获取定量考核记录--1->targetScore:%v\n--->attribute:%v\n--->Score:%v\n--->ScoringMethod:%v\n", targetScore, attribute, secondCont.Score, v.ScoringMethod)
secondCont . Score = publicmethod . DecimalEs ( secondCont . Score , 2 )
secondCont . Allprize = publicmethod . DecimalEs ( secondCont . Allprize / 100 , 2 )
secondCont . Zeroprize = publicmethod . DecimalEs ( secondCont . Zeroprize / 100 , 2 )
secondCont . Capping = publicmethod . DecimalEs ( secondCont . Capping / 100 , 2 )
secondCont . CompletionRate = publicmethod . DecimalEs ( secondCont . CompletionRate * 100 , 2 )
secondCont . CompletionRateAll = secondCont . CompletionRate
sendList = append ( sendList , secondCont )
var minusDepartment modelshr . AdministrativeOrganization
minErr := minusDepartment . GetCont ( map [ string ] interface { } { "id" : v . EvaluationDepartment } , "name" )
if minErr == nil {
if ! publicmethod . IsInTrue [ string ] ( minusDepartment . Name , EvalDepartment ) {
EvalDepartment = append ( EvalDepartment , minusDepartment . Name )
}
}
}
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 07 - 29 10 : 16 : 59
@ 功能 : 获取指标分数
@ 参数
# key 方案版本
# targetId 指标Id
# orgId 行政组织
# years 年
# months 月
@ 返回值
# targetScore 指标分
# attribute 1 、 使用 ; 2 : 禁用 ; 3 : 观察
@ 方法原型
# func GetTargetPlanScore ( key , targetId string , orgId , years , months int64 ) ( targetScore float64 , attribute int )
* /
func GetTargetPlanScore ( key , targetId string , orgId , years , months int64 ) ( targetScore float64 , attribute , cycles int ) {
var planVersionInfo modelskpi . PlanVersio
planVersionInfo , err := publicmethod . GetPlanVresion ( orgId , years , months )
// err := planVersionInfo.GetCont(map[string]interface{}{"`key`": key})
if err != nil {
planVersionInfo . GetCont ( map [ string ] interface { } { "`key`" : key } )
}
var planVersioInfo [ ] AddDutyNewCont
json . Unmarshal ( [ ] byte ( planVersionInfo . Content ) , & planVersioInfo )
if len ( planVersioInfo ) < 1 {
return
}
for _ , v := range planVersioInfo {
for _ , tv := range v . Child {
if targetId == tv . Id {
targetScore = float64 ( tv . ReferenceScore )
attribute = tv . Status
fmt . Printf ( "指标分数!-->%v-->%v\n" , targetScore , tv . Status )
cycles = tv . Cycles
}
}
}
return
}