package departmentpc
import (
"encoding/json"
"fmt"
"key_performance_indicators/api/version1/postseting/postweb"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 15 0 9 : 42 : 53
@ 功能 : 获取定量考核任务列表
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetQuantitativeTasks ( c * gin . Context ) {
//获取登录人信息
myLoginCont , _ := publicmethod . LoginMyCont ( c )
//获取参数
var receivedValue GetQuanTasks
c . ShouldBindJSON ( & receivedValue )
var listCont [ ] modelskpi . QualitativeEvaluation
gormDb := overall . CONSTANT_DB_KPI . Where ( "`qe_type` = 2 AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`)" , myLoginCont . Key )
if receivedValue . OrgId != "" {
gormDb = gormDb . Where ( "qe_accept_evaluation = ?" , receivedValue . OrgId )
}
if receivedValue . Title != "" {
gormDb = gormDb . Where ( "et_title LIKE ?" , "%" + receivedValue . Title + "%" )
}
err := gormDb . Order ( "qe_type ASC,qe_group ASC,qe_accept_evaluation ASC,qe_dimension ASC,qe_target ASC,qe_target_sun ASC,qe_detailed_target ASC" ) . Find ( & listCont ) . Error
if err != nil || len ( listCont ) < 1 {
publicmethod . Result ( 1 , err , c , "您没有要参加的考核项目!" )
return
}
var sendListCont [ ] TargetContOutCont
for _ , v := range listCont {
var sendCont TargetContOutCont
sendCont . Id = strconv . FormatInt ( v . Id , 10 )
sendCont . Type = v . Type
sendCont . Group = strconv . FormatInt ( v . Group , 10 )
//公司
var groupCont modelshr . AdministrativeOrganization
groupCont . GetCont ( map [ string ] interface { } { "`id`" : v . Group } , "`name`" )
sendCont . GroupNAme = groupCont . Name
//部门
var departCont modelshr . AdministrativeOrganization
departCont . GetCont ( map [ string ] interface { } { "`id`" : v . AcceptEvaluation } , "`name`" )
sendCont . DepartmentName = departCont . Name
sendCont . DepartmentId = strconv . FormatInt ( v . AcceptEvaluation , 10 )
sendCont . PlanVersionNumber = v . QualEvalId //执行方案版本号
//维度相关信息
sendCont . Dimension = strconv . FormatInt ( v . Dimension , 10 )
var dimeCont modelskpi . DutyClass
dimeCont . GetCont ( map [ string ] interface { } { "`id`" : v . Dimension } , "`title`" )
sendCont . DimensionName = dimeCont . Title
//指标信息
sendCont . Target = strconv . FormatInt ( v . Target , 10 )
var targetCont modelskpi . EvaluationTarget
targetCont . GetCont ( map [ string ] interface { } { "`et_id`" : v . Target } , "`et_title`" , "`et_scoring_method`" )
sendCont . TargetName = targetCont . Title
//子栏目
sendCont . ScoringMethod = int64 ( targetCont . ScoringMethod )
if v . TargetSun != 0 {
sendCont . TargetSun = strconv . FormatInt ( v . TargetSun , 10 )
var sunTargetCont modelskpi . QualitativeTarget
sunTargetCont . GetCont ( map [ string ] interface { } { "`q_id`" : v . Target } , "`q_title`" )
sendCont . TargetSunName = sunTargetCont . Title
}
//指标细则
if v . DetailedTarget != 0 {
sendCont . DetailedTarget = strconv . FormatInt ( v . DetailedTarget , 10 )
var detailedTargetCont modelskpi . DetailedTarget
detailedTargetCont . GetCont ( map [ string ] interface { } { "`dt_id`" : v . Target } , "`dt_title`" , "`dt_content`" )
sendCont . DetailedTargetName = detailedTargetCont . Title
sendCont . Content = detailedTargetCont . Content
}
sendCont . Unit = v . Unit
sendCont . ReferenceScore = v . ReferenceScore
sendCont . Cycles = v . Cycles
sendCont . CycleAttres = v . CycleAttres
sendCont . State = v . State
userAry := strings . Split ( v . Operator , "," )
sendCont . UserList = userAry
for _ , u_v := range userAry {
var repoCont modelshr . PersonArchives
repoErr := repoCont . GetCont ( map [ string ] interface { } { "`key`" : u_v } , "`number`" , "`name`" )
if repoErr == nil {
var userCont QualEvalArrt
userCont . Id = u_v
userCont . Name = repoCont . Name
sendCont . UserListAry = append ( sendCont . UserListAry , userCont )
}
}
sendCont . DimensionWeight , sendCont . TargetWeight = getPlanVersionWeghit ( v . QualEvalId , strconv . FormatInt ( v . Dimension , 10 ) , strconv . FormatInt ( v . Target , 10 ) )
//获取目标设定
quanTitWhere := publicmethod . MapOut [ string ] ( )
quanTitWhere [ "company_id" ] = v . Group
quanTitWhere [ "department_id" ] = v . AcceptEvaluation
quanTitWhere [ "dimension" ] = v . Dimension
quanTitWhere [ "target" ] = v . Target
if v . DetailedTarget != 0 {
quanTitWhere [ "detailed" ] = v . DetailedTarget
}
quanTitWhere [ "year" ] = publicmethod . UnixTimeToDay ( time . Now ( ) . Unix ( ) , 16 )
quanTitWhere [ "timecopy" ] = AllZreoConfig ( v . Cycles )
//目标值设定
var quanTitCont modelskpi . QuanPeopleConfig
quanTitCont . GetCont ( quanTitWhere )
//全奖值、零奖值、封顶值
sendCont . ZeroPrize = strconv . FormatFloat ( float64 ( quanTitCont . Zeroprize ) / 100 , 'f' , - 1 , 64 )
sendCont . AllPrize = strconv . FormatFloat ( float64 ( quanTitCont . Allprize ) / 100 , 'f' , - 1 , 64 )
sendCont . CappingVal = quanTitCont . CappingVal / 100
//获取实际值
shiJiZhi := publicmethod . MapOut [ string ] ( )
shiJiZhi [ "fl_evaluation_user" ] = myLoginCont . Key
shiJiZhi [ "fl_evaluation_department" ] = myLoginCont . MainDeparment
shiJiZhi [ "fl_evaluation_group" ] = myLoginCont . Company
operationTime := time . Now ( ) . Unix ( )
if receivedValue . Time != "" {
strTime := fmt . Sprintf ( "%v-01 00:00:00" , receivedValue . Time )
stringToTime , strToTimeErr := publicmethod . DateToTimeStamp ( strTime )
if strToTimeErr == true {
operationTime = stringToTime
} else {
strTime = fmt . Sprintf ( "%v 00:00:00" , receivedValue . Time )
stringToTime , strToTimeErr = publicmethod . DateToTimeStamp ( strTime )
if strToTimeErr == true {
operationTime = stringToTime
}
}
}
years := publicmethod . ComputingTime ( operationTime , 1 )
quarter := publicmethod . ComputingTime ( operationTime , 2 )
months := publicmethod . ComputingTime ( operationTime , 3 )
switch v . Cycles {
case 1 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
shiJiZhi [ "fl_day" ] = publicmethod . ComputingTime ( operationTime , 5 )
case 2 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
shiJiZhi [ "fl_day" ] = publicmethod . ComputingTime ( operationTime , 5 )
case 3 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
case 4 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
case 5 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
case 6 :
shiJiZhi [ "fl_year" ] = years
default :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
shiJiZhi [ "fl_day" ] = publicmethod . ComputingTime ( operationTime , 5 )
}
sendCont . ReferTo = JudgeDingLiangIsTrue ( v . Target , v . AcceptEvaluation , years , quarter , months , v . Cycles )
actualValue := GetTimeIntervalDuty ( shiJiZhi , v . Id ) //实际值
sendCont . Actual = strconv . FormatFloat ( actualValue / 100 , 'f' , - 1 , 64 )
// chuShuVal := actualValue - quanTitCont.Zeroprize
// beiChuShuVal := quanTitCont.Allprize - quanTitCont.Zeroprize
// if beiChuShuVal > 0 {
// sendCont.ReachScore = chuShuVal / beiChuShuVal
// } else {
// sendCont.ReachScore = 0
// }
_ , sendCont . ReachScore = postweb . GetAchieAndActual ( actualValue , float64 ( sendCont . TargetWeight ) , quanTitCont . Zeroprize , quanTitCont . Allprize , quanTitCont . CappingVal )
/ *
*
@ 作者 : 秦东
@ 时间 : 2022 - 10 - 28 15 : 0 9 : 33
@ 功能 : 计算达成率及得分
@ 参数
# score 实际分
# weight 指标权重
# zeroprize 零奖值
# allprize 全奖值
# cappingval 封顶值
@ 返回值
# achievement 达成率
# actual 得分
@ 函数原型
# GetAchieAndActual ( score , weight , zeroprize , allprize , cappingval float64 ) ( achievement , actual float64 )
* /
if quanTitCont . Zeroprize == 0 && quanTitCont . Allprize == 0 {
sendCont . Reach = "未设置目标值"
} else {
dividend := quanTitCont . Allprize - quanTitCont . Zeroprize //被除数
if dividend == 0 {
sendCont . Reach = "未设置目标值"
} else {
sendCont . Reach = fmt . Sprintf ( "(实际值-零奖值)/(全奖值-零奖值)" )
}
}
sendCont . Reason = ""
sendCont . DetailedTarget = strconv . FormatInt ( v . DetailedTarget , 10 )
sendListCont = append ( sendListCont , sendCont )
}
publicmethod . Result ( 0 , sendListCont , c )
}
// 判断定量指标是否已经提交
func JudgeDingLiangIsTrue ( targetId , department int64 , year , quarter , monthsss int64 , types int ) bool {
var idList [ ] int64
gormDb := overall . CONSTANT_DB_KPI . Model ( & modelskpi . FlowDataLogType { } ) . Select ( "`id`" ) . Where ( "`targetid` = ? AND `department` = ?" , targetId , department )
switch types {
case 5 :
gormDb = gormDb . Where ( "`year` = ? AND `quarte` = ?" , year , quarter )
case 6 :
gormDb = gormDb . Where ( "`year` = ?" , year )
case 7 :
banNian := [ ] int { 1 , 2 , 3 , 4 , 5 , 6 }
if monthsss > 6 {
banNian = [ ] int { 7 , 8 , 9 , 10 , 11 , 12 }
}
gormDb = gormDb . Where ( "`year` = ? AND `month` IN ?" , year , banNian )
default :
gormDb = gormDb . Where ( "`year` = ? AND `month` = ?" , year , monthsss )
}
err := gormDb . Find ( & idList ) . Error
if err == nil && len ( idList ) > 0 {
return true
}
return false
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 15 10 : 23 : 22
@ 功能 : 获取维度与指标权重
@ 参数
# planKey 方案编号
# dimensionId 维度
# targetId 指标
@ 返回值
# dimensionIdWeghit 维度权重
# targetIdWeghit 指标权重
@ 方法原型
# getPlanVersionWeghit ( planKey , dimensionId , targetId string ) ( dimensionIdWeghit , targetIdWeghit int64 )
* /
func getPlanVersionWeghit ( planKey , dimensionId , targetId string ) ( dimensionIdWeghit , targetIdWeghit int64 ) {
var planVersionCont modelskpi . PlanVersio
err := overall . CONSTANT_DB_KPI . Model ( & modelskpi . PlanVersio { } ) . Select ( "`content`" ) . Where ( "`key` = ?" , planKey ) . First ( & planVersionCont ) . Error
if err != nil {
return
}
var planVersioInfo [ ] AddDutyNewCont
jsonErr := json . Unmarshal ( [ ] byte ( planVersionCont . Content ) , & planVersioInfo )
if jsonErr != nil {
return
}
for _ , v := range planVersioInfo {
if v . Id == dimensionId {
dimensionIdWeghit = int64 ( v . ZhiFraction )
for _ , cv := range v . Child {
if cv . Id == targetId {
targetIdWeghit = cv . ReferenceScore
}
}
}
}
return
}
/ * *
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 15 10 : 49 : 07
@ 功能 : 判断全奖与零奖参数
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
// 判断全奖与零奖参数
func AllZreoConfig ( cycles int ) ( monthInt int64 ) {
switch cycles {
case 4 :
monthInt = publicmethod . ComputingTime ( time . Now ( ) . Unix ( ) , 3 )
case 5 :
monthInt = publicmethod . ComputingTime ( time . Now ( ) . Unix ( ) , 2 )
default :
}
return
}
// 获取定量考核时间内审批通过的考核数据
func GetTimeIntervalDuty ( whereData interface { } , schemeID int64 ) ( actual float64 ) {
// jsonStr, _ := json.Marshal(whereData)
// fmt.Printf("jsonStr------1------>%v\n", string(jsonStr))
actual = 0
//相关审批流
var flowLogList [ ] modelskpi . FlowLog
err := overall . CONSTANT_DB_KPI . Where ( "`fl_reply` IN (2,3) AND FIND_IN_SET(?,`fl_evaluation_id`)" , schemeID ) . Where ( whereData ) . Find ( & flowLogList ) . Error
if err != nil {
return
}
for _ , v := range flowLogList {
actual = actual + GetSchemeFlowData ( v . Key , schemeID )
}
return
}
// 获取指定审批流方案数据
func GetSchemeFlowData ( flowKwy , schemeID int64 ) ( weightSum float64 ) {
weightSum = 0
overall . CONSTANT_DB_KPI . Model ( & modelskpi . FlowLogData { } ) . Where ( "`fld_evaluation_id` = ? AND `fld_flow_log` = ?" , schemeID , flowKwy ) . Pluck ( "COALESCE(SUM(fld_score), 0) as qe_reference_score" , & weightSum )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 02 - 23 16 : 35 : 22
@ 功能 : 获取关联指标细则
@ 参数
# targetid 指标ID
# tableid 栏目Id
# bylaws 细则Id
# orgid 行政组织
# post 岗位
# types 类型 ( 1 : 指标 ; 2 : 子目标 ; 3 : 细则 )
# level 级别 ( 1 : 部门级 ; 2 : 岗位级 )
@ 返回值
# bylawsId 相关ID
# err 信息
@ 方法原型
# GetTargetDetailsInfoList ( targetid , tableid , bylaws , orgid , post int64 , types , level int ) ( bylawsId [ ] int64 , err error )
* /
func GetTargetDetailsInfoList ( targetid , tableid , bylaws , orgid , post int64 , types , level int ) ( bylawsId [ ] int64 , err error ) {
if types == 0 {
types = 3
}
gormDb := overall . CONSTANT_DB_KPI . Model ( & modelskpi . TargetDepartment { } )
switch types {
case 1 :
gormDb = gormDb . Distinct ( ` target_id ` )
case 2 :
gormDb = gormDb . Distinct ( ` target_sun_id ` )
default :
gormDb = gormDb . Distinct ( ` target_bylaws ` )
}
gormDb = gormDb . Where ( "`state` = 1 AND `type` = ? AND `level` = ?" , types , level )
if targetid != 0 {
gormDb = gormDb . Where ( "`target_id` = ?" , targetid )
}
if tableid != 0 {
gormDb = gormDb . Where ( "`target_sun_id` = ?" , tableid )
}
if bylaws != 0 {
gormDb = gormDb . Where ( "`target_bylaws` = ?" , bylaws )
}
err = gormDb . Find ( & bylawsId ) . Error
return
}