package quantification
import (
"encoding/json"
"fmt"
"strconv"
"time"
"gin_server_admin/api/admin/dutyassess"
"gin_server_admin/commonus"
"gin_server_admin/global"
"gin_server_admin/model/assessmentmodel"
"gin_server_admin/model/common/response"
"gin_server_admin/model/hrsystem"
"github.com/gin-gonic/gin"
)
// 汇总详情
func ( a * ApiGroup ) SummaryDetails ( c * gin . Context ) {
var requestData detailedResults
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 101 , err , "数据获取失败!" , c )
return
}
if requestData . Department == "" {
response . Result ( 102 , err , "参数错误!请属入部门" , c )
return
}
if requestData . Year == 0 {
requestData . Year = commonus . ComputingTime ( time . Now ( ) . Unix ( ) , 1 )
}
if requestData . Months < 1 {
requestData . Months = 1
}
if requestData . Months > 12 {
requestData . Months = 12
}
//获取部门版本
var planVersion assessmentmodel . PlanVersio
pvErr := global . GVA_DB_Performanceappraisal . Where ( "department = ? AND state = 1" , requestData . Department ) . Order ( "department desc" ) . First ( & planVersion ) . Error
if pvErr != nil {
response . Result ( 103 , err , "没有查询到数据!" , c )
return
}
//版本内容解析
var planVersionCont [ ] dutyassess . AddDutyNewCont
jsonErr := json . Unmarshal ( [ ] byte ( planVersion . Content ) , & planVersionCont )
if jsonErr != nil {
response . Result ( 104 , err , "没有查询到数据!" , c )
return
}
if len ( planVersionCont ) < 1 {
response . Result ( 104 , err , "没有查询到数据!" , c )
return
}
var sumScore float64 = 0
var lookStatistics [ ] detailedResultsList
for _ , v := range planVersionCont { //维度
for _ , cv := range v . Child { //指标
// if cv.Id == "52" {
var statisCont detailedResultsList
statisCont . GroupId = strconv . FormatInt ( planVersion . Group , 10 ) //集团Id
var groupCont hrsystem . AdministrativeOrganization
groupCont . GetCont ( map [ string ] interface { } { "`id`" : planVersion . Group } , "name" )
statisCont . GroupName = groupCont . Name //集团名称
statisCont . DepartmentId = strconv . FormatInt ( planVersion . Department , 10 ) //部门ID
var departCont hrsystem . AdministrativeOrganization
departCont . GetCont ( map [ string ] interface { } { "`id`" : planVersion . Department } , "name" )
statisCont . DepartmentName = departCont . Name //部门名称
statisCont . DimensionId = v . Id //维度Id
statisCont . DimensionName = v . Name //维度名称
statisCont . DimensionWeight = int64 ( v . ZhiFraction ) //维度权重
statisCont . TargetId = cv . Id //指标ID
statisCont . TargetName = cv . Name //指标名称
statisCont . TargetCont = cv . Content //指标名称
statisCont . Targetweight = cv . ReferenceScore //指标权重
var evalTargetCont assessmentmodel . EvaluationTarget
if cv . Id != "" && cv . Id != "0" {
targetErr := evalTargetCont . GetCont ( map [ string ] interface { } { "`et_id`" : cv . Id } , "et_type" )
if targetErr == nil {
if evalTargetCont . Type == 1 {
statisCont . Score , statisCont . ExecutiveDepartment = DingXingMonthSum ( planVersion . Group , planVersion . Department , cv . ReferenceScore , requestData . Year , int64 ( requestData . Months ) , cv . Id , cv . Cycles , cv . Status )
sumScore = sumScore + statisCont . Score
} else {
statisCont . Score , statisCont . ExecutiveDepartment = DingLiangMonthSum ( planVersion . Group , planVersion . Department , cv . ReferenceScore , requestData . Year , int64 ( requestData . Months ) , cv . Id , cv . Cycles , cv . Status )
sumScore = sumScore + statisCont . Score
}
}
}
statisCont . Type = evalTargetCont . Type //1:定性;2:定量
statisCont . Unit = cv . Unit //单位
statisCont . Cycle = cv . Cycles //周期
statisCont . Cycleattr = cv . CycleAttres //辅助参数
// statisCont.ExecutiveDepartment = //执行部门
// statisCont.Score = //得分
// if cv.Id != "" && cv.Id != "0" {
// // var targetCont assessmentmodel.EvaluationTarget
// // targetErr := global.GVA_DB_Performanceappraisal.Model(&targetCont).Select("et_type").Where("et_id = ?", cv.Id).First(&targetCont).Error
// if targetErr == nil {
// statisCont.Score, statisCont.ExecutiveDepartment = dingXingMonthSum(planVersion.Group, planVersion.Department, cv.ReferenceScore, requestData.Year, int64(requestData.Months), cv.Id)
// }
// }
lookStatistics = append ( lookStatistics , statisCont )
// }
}
}
response . Result ( 0 , lookStatistics , "查询成功" , c )
}
// 定性月份分值合计
/ *
@ groupId 集团
@ departmentId 部门
@ weight 权重
@ year 年
@ month 月
@ targetId 指标ID
@ cycs 1 : 班 ; 2 : 天 ; 3 : 周 ; 4 : 月 ; 5 : 季度 ; 6 : 年
@ status 1 : 启用 ; 2 : 禁用 ; 3 : 观察
* /
func DingXingMonthSum ( groupId , departmentId , weight , year , month int64 , targetId string , cycs , status int ) ( score float64 , EvalDepartment [ ] string ) {
//获取减分
var minusPoints float64 = 0
var scoreFlowList [ ] assessmentmodel . ScoreFlow
minusErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_evaluation_department,sf_count" ) . Where ( "sf_plus_reduce_score = 2 AND sf_reply IN ? AND sf_duty_group = ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , groupId , departmentId , year , month , targetId ) . Find ( & scoreFlowList ) . Error
if minusErr == nil {
for _ , mv := range scoreFlowList {
minusPoints = minusPoints + ( float64 ( mv . Score ) * float64 ( mv . Count ) )
var minusDepartment hrsystem . AdministrativeOrganization
minErr := minusDepartment . GetCont ( map [ string ] interface { } { "id" : mv . EvaluationDepartment } , "name" )
// fmt.Printf("extraDepartment.Name---1-->%v\n", minusDepartment.Name)
if minErr == nil {
if commonus . IsInTrue [ string ] ( minusDepartment . Name , EvalDepartment ) == false {
EvalDepartment = append ( EvalDepartment , minusDepartment . Name )
}
}
}
}
//获取加分
var extraPoints float64 = 0
extraErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_evaluation_department,sf_count" ) . Where ( "sf_plus_reduce_score = 1 AND sf_reply IN ? AND sf_duty_group = ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , groupId , departmentId , year , month , targetId ) . Find ( & scoreFlowList ) . Error
if extraErr == nil {
var orgIdAry [ ] int64
for _ , ev := range scoreFlowList {
extraPoints = extraPoints + float64 ( ev . Score )
if commonus . IsInTrue [ int64 ] ( ev . EvaluationDepartment , orgIdAry ) == false {
orgIdAry = append ( orgIdAry , ev . EvaluationDepartment )
var extraDepartment hrsystem . AdministrativeOrganization
minErr := extraDepartment . GetCont ( map [ string ] interface { } { "id" : ev . EvaluationDepartment } , "name" )
// fmt.Printf("extraDepartment.Name---2-->%v\n", extraDepartment.Name)
if minErr == nil {
if commonus . IsInTrue [ string ] ( extraDepartment . Name , EvalDepartment ) == false {
EvalDepartment = append ( EvalDepartment , extraDepartment . Name )
}
}
}
}
}
// fmt.Printf("EvalDepartment--2--->%v\n", EvalDepartment)
score = commonus . Decimal ( ( ( float64 ( weight ) + extraPoints / 100 ) - minusPoints / 100 ) )
if targetId == "6" {
// fmt.Printf("targetId--1--->%v--->%v--->%v--->%v\n", weight, extraPoints, minusPoints, score)
}
if cycs != 4 {
score = float64 ( weight )
}
if status == 3 {
score = float64 ( weight )
}
return
}
// 获取定量考核分值
/ *
@ groupId 集团
@ departmentId 部门
@ weight 权重
@ year 年
@ month 月
@ targetId 指标ID
@ cycs 1 : 班 ; 2 : 天 ; 3 : 周 ; 4 : 月 ; 5 : 季度 ; 6 : 年
@ status 1 : 启用 ; 2 : 禁用 ; 3 : 观察
* /
func DingLiangMonthSum ( groupId , departmentId , weight , year , month int64 , targetId string , cycs , status int ) ( score float64 , EvalDepartment [ ] string ) {
var flowDataLog [ ] assessmentmodel . FlowDataLogType
err := global . GVA_DB_Performanceappraisal . Where ( "`group` = ? AND `department` = ? AND `year` = ? AND `month` = ? AND `targetid` = ?" , groupId , departmentId , year , month , targetId ) . Find ( & flowDataLog ) . Error
fmt . Printf ( "err ------flowDataLog------>err:%v------>status:%v------>flowDataLog:%v\n" , err , status , flowDataLog )
if err != nil || len ( flowDataLog ) < 1 {
score = float64 ( weight )
return
}
var sumScore float64 = 0
var sumScoreEs float64 = 0
for _ , v := range flowDataLog {
_ , targetScore , statues , cycle , _ := getPlanVersion ( v . Edition , strconv . FormatInt ( v . TargetId , 10 ) )
if statues > 0 {
status = statues
}
if v . TargetId == 12 {
fmt . Printf ( "Jiba------2------>%v\n" , statues )
}
if status != 3 {
if v . TargetId == 12 {
fmt . Printf ( "Jiba------3------>%v\n" , v . ScoringMethod )
}
if v . ScoringMethod == 1 {
sumScore = sumScore + float64 ( v . Score )
sumScoreGet , _ , _ , _ , _ := analysisReward ( targetId , v . Baseline , targetScore , float64 ( v . Score ) )
// sumScoreGet, _, _, _, _ := analysisReward(targetId, v.Baseline, float64(weight), float64(v.Score))
switch cycle {
case 5 :
if commonus . IsInTrue [ int64 ] ( month , [ ] int64 { 3 , 6 , 9 , 12 } ) == false {
sumScoreGet = targetScore
}
case 6 :
if month != 12 {
sumScoreGet = targetScore
}
default :
}
sumScoreEs = sumScoreEs + sumScoreGet
fmt . Printf ( "sumScoreEs--1--->%v\n" , v . Score )
} else {
scorSc := v . ScoringScore
switch cycle {
case 5 :
if commonus . IsInTrue [ int64 ] ( month , [ ] int64 { 3 , 6 , 9 , 12 } ) == false {
scorSc = targetScore * 100
}
case 6 :
if month != 12 {
scorSc = targetScore * 100
}
default :
}
sumScoreEs = sumScoreEs + ( float64 ( scorSc ) / 100 )
// sumScoreGet, _, _, _, _ := analysisReward(targetId, v.Baseline, float64(weight), float64(v.ScoringScore))
// sumScoreEs = sumScoreEs + sumScoreGet
fmt . Printf ( "sumScoreEs--2--->%v\n" , sumScoreEs )
}
} else {
sumScoreEs = sumScoreEs + targetScore
}
if v . TargetId == 12 {
fmt . Printf ( "Jiba------1------>%v\n" , sumScoreEs )
}
var extraDepartment hrsystem . AdministrativeOrganization
minErr := extraDepartment . GetCont ( map [ string ] interface { } { "id" : v . EvaluationDepartment } , "name" )
// fmt.Printf("extraDepartment.Name-3---->%v\n", extraDepartment.Name)
if minErr == nil {
if commonus . IsInTrue [ string ] ( extraDepartment . Name , EvalDepartment ) == false {
EvalDepartment = append ( EvalDepartment , extraDepartment . Name )
}
}
}
fmt . Printf ( "sumScoreEs--3--->%v\n" , sumScoreEs )
score = sumScoreEs
// if cycs != 4 {
// score = float64(weight)
// }
// if status == 3 {
// score = float64(weight)
// }
return
}
//获取定量流水全奖、零奖、封顶值
/ *
@ targetId 指标ID
@ rewardCont 全奖 、 零奖 、 封顶值设置
@ targetScore 指标分值
@ settlementScore 计算分值
返回说明
@ scoreVal 计算得分
@ allPrize 全奖值
@ zeroPrize 零奖值
@ CappingVal 封顶值
@ achievement 达成率
* /
func analysisReward ( targetId , rewardCont string , targetScore , settlementScore float64 ) ( scoreVal , allPrize , zeroPrize , CappingVal , achievement float64 ) {
var rewardAry [ ] FlowLogAllZreo
jsonErr := json . Unmarshal ( [ ] byte ( rewardCont ) , & rewardAry )
if jsonErr != nil {
scoreVal = targetScore
return
}
if len ( rewardAry ) < 1 {
scoreVal = targetScore
return
}
settlementScore = settlementScore / 100
for _ , v := range rewardAry {
if v . TargetId == targetId {
allPrize = v . Allprize / 100
zeroPrize = v . Zeroprize / 100
CappingVal = v . Capping / 100
// fmt.Printf("%v----全奖--1-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
if allPrize == 0 && zeroPrize == 0 { //全奖值与零奖值都为0 那么达成率 100 和实际得分是 指标分
achievement = 100
scoreVal = targetScore
// fmt.Printf("%v----全奖--2-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
if allPrize > zeroPrize { //如果全奖值大于零奖值 执行一下操作
if settlementScore <= zeroPrize { //实际结算值小于零奖值 那么达成率和实际得分都是0
scoreVal = 0
achievement = 0
// fmt.Printf("%v----全奖--3-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else { //实际结算值在全奖值 与 零奖值之间
chuShu := settlementScore - float64 ( zeroPrize )
beiChuShu := float64 ( allPrize ) - float64 ( zeroPrize )
if beiChuShu != 0 {
achievement = commonus . DecimalEs ( chuShu / beiChuShu , 4 )
if achievement <= 0 {
achievement = 0
scoreVal = 0
// fmt.Printf("%v----全奖--4-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
if achievement * 100 >= CappingVal {
if CappingVal > 0 {
scoreVal = ( CappingVal / 100 ) * targetScore
// fmt.Printf("%v----全奖--6-1->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
scoreVal = targetScore
// fmt.Printf("%v----全奖--6-2->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
}
} else {
scoreVal = ( chuShu / beiChuShu ) * targetScore
// fmt.Printf("%v----全奖--6-3->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
}
}
achievement = commonus . DecimalEs ( achievement * 100 , 4 )
// fmt.Printf("%v----全奖--6-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
achievement = 0
scoreVal = 0
}
}
} else { //如果全奖值小于零奖值 执行一下操作
if settlementScore >= zeroPrize { //实际结算值大于零奖值 那么达成率和实际得分都是0
achievement = 0
scoreVal = 0
// fmt.Printf("%v----全奖--7-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
chuShu := settlementScore - float64 ( zeroPrize )
beiChuShu := float64 ( allPrize ) - float64 ( zeroPrize )
if beiChuShu != 0 {
achievement = commonus . DecimalEs ( chuShu / beiChuShu , 4 )
if achievement <= 0 {
//如果在全奖值大于零件值的情况下出现达成率为0或负数,则达成率和实际得分都是0
achievement = 0
scoreVal = 0
// fmt.Printf("%v----全奖--8-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
if achievement * 100 >= CappingVal {
scoreVal = ( CappingVal / 100 ) * targetScore
// fmt.Printf("%v----全奖--13-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
scoreVal = ( chuShu / beiChuShu ) * targetScore
// fmt.Printf("%v----全奖--14-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
}
// fmt.Printf("%v----全奖--9-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
}
achievement = commonus . DecimalEs ( achievement * 100 , 4 )
// fmt.Printf("%v----全奖--10-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
} else {
//被除数为0时 那么达成率和实际得分都是0
achievement = 0
scoreVal = 0
// fmt.Printf("%v----全奖--11-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
}
}
}
}
}
}
// if settlementScore == 0 {
// scoreVal = 0
// } else {
// scoreVal = commonus.Decimal(scoreVal)
// }
scoreVal = commonus . Decimal ( scoreVal )
allPrize = commonus . Decimal ( allPrize )
zeroPrize = commonus . Decimal ( zeroPrize )
CappingVal = commonus . Decimal ( CappingVal )
achievement = commonus . DecimalEs ( achievement , 4 )
// fmt.Printf("%v----全奖--12-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
return
}
// 汇总历史记录表
func ( a * ApiGroup ) 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 = commonus . ComputingTime ( time . Now ( ) . Unix ( ) , 1 )
}
if requestData . Months < 1 {
requestData . Months = 1
}
if requestData . Months > 12 {
requestData . Months = 12
}
//获取部门版本
// var planVersion assessmentmodel.FlowDataLogType
// pvErr := global.GVA_DB_Performanceappraisal.Where("department = ? AND state = 1", requestData.Department).First(&planVersion).Error
// if pvErr != nil {
// response.Result(103, err, "没有查询到数据!", c)
// return
// }
var list [ ] dingLiangKaoHe
//获取定量考核数据列表
var flowDataLog [ ] assessmentmodel . FlowDataLogType
flowErr := global . GVA_DB_Performanceappraisal . Where ( "`department` = ? AND `targetid` = ? AND `year` = ? AND `month` = ?" , requestData . Department , requestData . TargetId , requestData . Year , requestData . Months ) . Find ( & flowDataLog ) . Error
if flowErr != nil {
//获取部门现行考核版本
var departPlanVersion assessmentmodel . PlanVersio
dpvErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . PlanVersio { } ) . Where ( "`state` = 1 AND `department` = ?" , requestData . Department ) . First ( & departPlanVersion ) . Error
if dpvErr == nil {
} else {
response . Result ( 104 , err , "没有查询到数据!" , c )
return
}
}
for _ , v := range flowDataLog {
_ , targetScore , status , cycle , _ := getPlanVersion ( v . Edition , strconv . FormatInt ( v . TargetId , 10 ) )
var listCont dingLiangKaoHe
var settlementScore float64 = 0
if v . ScoringMethod == 1 {
listCont . Actual = commonus . Decimal ( float64 ( v . Score ) / 100 )
settlementScore = float64 ( v . Score )
listCont . Score , listCont . Allprize , listCont . Zeroprize , listCont . Capping , listCont . CompletionRate = analysisReward ( strconv . FormatInt ( v . TargetId , 10 ) , v . Baseline , targetScore , settlementScore )
} else {
// listCont.Actual = commonus.Decimal(float64(v.ScoringScore) / 100)
listCont . Actual = commonus . Decimal ( float64 ( v . Score ) / 100 )
// settlementScore = float64(v.ScoringScore)
_ , listCont . Allprize , listCont . Zeroprize , listCont . Capping , listCont . CompletionRate = analysisReward ( strconv . FormatInt ( v . TargetId , 10 ) , v . Baseline , targetScore , settlementScore )
listCont . Score = commonus . Decimal ( float64 ( v . ScoringScore ) / 100 )
}
listCont . MtOrAt = v . ScoringMethod
listCont . Cont = v . Content
listCont . Nature = status
if status == 3 {
listCont . Score = targetScore
}
switch cycle {
case 5 :
if commonus . IsInTrue [ int ] ( requestData . Months , [ ] int { 3 , 6 , 9 , 12 } ) == false {
listCont . Score = targetScore
}
case 6 :
if requestData . Months != 12 {
listCont . Score = targetScore
}
default :
}
// if v.TargetId == 12 {
// fmt.Printf("Jiba------------>%v\n", listCont)
// }
listCont . Allprize = commonus . Decimal ( listCont . Allprize )
listCont . Zeroprize = commonus . Decimal ( listCont . Zeroprize )
listCont . Capping = commonus . Decimal ( listCont . Capping )
listCont . Actual = commonus . Decimal ( listCont . Actual )
list = append ( list , listCont )
}
response . Result ( 0 , list , "查询完成!" , c )
}
// 获取版本信息
func getPlanVersion ( key , targetId string ) ( dimeScore , targetScore float64 , status , cycle , cycleattr int ) {
var planVersionCont assessmentmodel . PlanVersio
err := global . GVA_DB_Performanceappraisal . Where ( "`key` = ?" , key ) . First ( & planVersionCont ) . Error
if err != nil {
return
}
//版本内容解析
var planVersionContInfo [ ] dutyassess . AddDutyNewCont
jsonErr := json . Unmarshal ( [ ] byte ( planVersionCont . Content ) , & planVersionContInfo )
if jsonErr != nil {
return
}
if len ( planVersionContInfo ) < 1 {
return
}
for _ , v := range planVersionContInfo {
for _ , tv := range v . Child {
if targetId == tv . Id {
dimeScore = float64 ( v . ZhiFraction )
targetScore = float64 ( tv . ReferenceScore )
status = tv . Status
cycle = tv . Cycles
cycleattr = tv . CycleAttres
}
}
}
return
}
// 汇总历史记录表定性
func ( a * ApiGroup ) SummaryDetailsXingLog ( 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 = commonus . ComputingTime ( time . Now ( ) . Unix ( ) , 1 )
}
if requestData . Months < 1 {
requestData . Months = 1
}
if requestData . Months > 12 {
requestData . Months = 12
}
var scoreFlowList [ ] assessmentmodel . ScoreFlow
minusErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_plus_reduce_score,sf_score,sf_evaluation_department,sf_count,sf_evaluation_user,sf_happen_time,sf_time,sf_reason" ) . Where ( "sf_reply IN ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , requestData . Department , requestData . Year , requestData . Months , requestData . TargetId ) . Find ( & scoreFlowList ) . Error
if minusErr != nil {
response . Result ( 105 , minusErr , "没有数据" , c )
return
}
var flowScoreList [ ] dingXingLogScoreList
for _ , v := range scoreFlowList {
var flowScoreCont dingXingLogScoreList
flowScoreCont . AddOrSubtract = v . PlusReduceScore
fenshu := v . Score * int64 ( v . Count )
flowScoreCont . Score = commonus . Decimal ( float64 ( fenshu ) / 100 )
flowScoreCont . Time = commonus . TimeStampToDate ( v . HappenTime , 6 )
var evalUser EvalUserContStruct
if v . EvaluationDepartment != 0 {
var orgCont hrsystem . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . EvaluationDepartment } , "`name`" )
evalUser . Department = orgCont . Name
}
if v . EvaluationUser != 0 {
var myCong hrsystem . PersonArchives
myCong . GetCont ( map [ string ] interface { } { "`key`" : v . EvaluationUser } , "`name`" )
evalUser . UserName = myCong . Name
}
flowScoreCont . Cont = v . Reason
flowScoreCont . EvalUserCont = append ( flowScoreCont . EvalUserCont , evalUser )
flowScoreList = append ( flowScoreList , flowScoreCont )
}
response . Result ( 0 , flowScoreList , "查询成功" , c )
}
// 定性月份分值合计
func dingXingMonthSumNew ( departmentId , year , month int64 , targetId string ) ( score float64 , EvalDepartment [ ] string ) {
var banBenHao [ ] string
err := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Distinct ( "sf_planversion" ) . Where ( "`sf_duty_department` = ? AND `sf_target_id` = ? AND `sf_year` = ? AND `sf_month` = ?" , departmentId , targetId , year , month ) . Find ( & banBenHao ) . Error
fmt . Printf ( "err---->%v-----bb----->%v\n" , err , banBenHao )
for _ , v := range banBenHao {
var banBenNeiRong string
banBenErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . PlanVersio { } ) . Select ( "`content`" ) . Where ( "`key` = ?" , v ) . First ( & banBenNeiRong ) . Error
fmt . Printf ( "banBenErr---->%v-----banBenNeiRong----->%v\n" , banBenErr , banBenNeiRong )
if banBenErr != nil {
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . PlanVersio { } ) . Select ( "`content`" ) . Where ( "`state` = 1 AND `department` = ?" , departmentId ) . First ( & banBenNeiRong )
}
getScore , getDepartment := getDingXingKaoHe ( departmentId , year , month , targetId , v , banBenNeiRong )
score = score + getScore
for _ , dv := range getDepartment {
if commonus . IsInTrue [ string ] ( dv , EvalDepartment ) == false {
EvalDepartment = append ( EvalDepartment , dv )
}
}
}
return
}
// 获取定性考核
func getDingXingKaoHe ( departmentId , year , month int64 , targetId , banBenNeiRong , editionCont string ) ( scoreAll float64 , EvalDepartment [ ] string ) {
//获取减分
var minusPoints float64 = 0
var scoreFlowList [ ] assessmentmodel . ScoreFlow
minusErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_evaluation_department,sf_count" ) . Where ( "sf_plus_reduce_score = 2 AND sf_reply IN ? AND sf_planversion = ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , banBenNeiRong , departmentId , year , month , targetId ) . Find ( & scoreFlowList ) . Error
if minusErr == nil {
for _ , mv := range scoreFlowList {
minusPoints = minusPoints + ( float64 ( mv . Score ) * float64 ( mv . Count ) )
var minusDepartment hrsystem . AdministrativeOrganization
minErr := minusDepartment . GetCont ( map [ string ] interface { } { "id" : mv . EvaluationDepartment } , "name" )
// fmt.Printf("extraDepartment.Name---1-->%v\n", minusDepartment.Name)
if minErr == nil {
if commonus . IsInTrue [ string ] ( minusDepartment . Name , EvalDepartment ) == false {
EvalDepartment = append ( EvalDepartment , minusDepartment . Name )
}
}
}
}
//获取加分
var extraPoints float64 = 0
extraErr := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_evaluation_department,sf_count" ) . Where ( "sf_plus_reduce_score = 1 AND sf_reply IN ? AND sf_planversion = ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , banBenNeiRong , departmentId , year , month , targetId ) . Find ( & scoreFlowList ) . Error
if extraErr == nil {
var orgIdAry [ ] int64
for _ , ev := range scoreFlowList {
extraPoints = extraPoints + float64 ( ev . Score )
if commonus . IsInTrue [ int64 ] ( ev . EvaluationDepartment , orgIdAry ) == false {
orgIdAry = append ( orgIdAry , ev . EvaluationDepartment )
var extraDepartment hrsystem . AdministrativeOrganization
minErr := extraDepartment . GetCont ( map [ string ] interface { } { "id" : ev . EvaluationDepartment } , "name" )
// fmt.Printf("extraDepartment.Name---2-->%v\n", extraDepartment.Name)
if minErr == nil {
if commonus . IsInTrue [ string ] ( extraDepartment . Name , EvalDepartment ) == false {
EvalDepartment = append ( EvalDepartment , extraDepartment . Name )
}
}
}
}
}
_ , targetScore , status , cycle , _ := getPlanVersion ( editionCont , targetId )
if status == 3 {
scoreAll = commonus . Decimal ( targetScore / 100 )
} else {
switch cycle {
case 5 :
if commonus . IsInTrue [ int64 ] ( month , [ ] int64 { 3 , 6 , 9 , 12 } ) == false {
scoreAll = commonus . Decimal ( targetScore / 100 )
}
case 6 :
if month != 12 {
scoreAll = commonus . Decimal ( targetScore / 100 )
}
default :
scoreAll = commonus . Decimal ( ( ( targetScore / 100 + extraPoints / 100 ) - minusPoints / 100 ) )
}
}
return
}