package evaluation
import (
"encoding/json"
"fmt"
"strconv"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/gin-gonic/gin"
)
//新定性考核列表
func ( e * EvaluationInterface ) NewQualitative ( c * gin . Context ) {
isTrue , userCont := commonus . ClientIdentity ( )
if isTrue != true {
response . Result ( 1001 , isTrue , "您的身份令牌已经失效!请重新登录获取身份令牌!" , c )
return
}
var requestData NewQualType
err := c . ShouldBindJSON ( & requestData )
if err != nil {
// response.Result(102, err, "数据获取失败!", c)
// return
}
userContJson , _ := json . Marshal ( userCont )
fmt . Printf ( "userCont----------------->%v\n" , string ( userContJson ) )
var qualEvaList [ ] NewQualOutList
gormDb := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeEvaluation { } ) . Select ( "DISTINCT qe_group,qe_accept_evaluation,qe_dimension,qe_target,et_title" ) . Joins ( "left join evaluationtarget on evaluationtarget.et_id = qualitative_evaluation.qe_target" ) . Where ( "`qe_type` = 1 AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`)" , userCont . Key )
if requestData . Group != "" {
gormDb = gormDb . Where ( "`qe_group` = ?" , requestData . Group )
}
if requestData . Department != "" {
gormDb = gormDb . Where ( "`qe_accept_evaluation` = ?" , requestData . Department )
}
if requestData . Title != "" {
gormDb = gormDb . Where ( "evaluationtarget.et_title LIKE ?" , "%" + requestData . Title + "%" )
}
errList := gormDb . Order ( "qe_group ASC,qe_accept_evaluation ASC,qe_dimension ASC,qe_target ASC" ) . Find ( & qualEvaList ) . Error
if errList != nil || len ( qualEvaList ) < 1 {
response . Result ( 102 , isTrue , "您没有要参加的考核项目!" , c )
return
}
todayVal := time . Now ( ) . Unix ( )
yearVal := commonus . ComputingTime ( todayVal , 1 )
monthVal := commonus . ComputingTime ( todayVal , 3 )
var outContList [ ] NewQualOutList
for _ , v := range qualEvaList {
var outCont NewQualOutList
outCont . Group = v . Group
where := commonus . MapOut ( )
where [ "id" ] = v . Group
orgCont , _ := commonus . GetNewOrgCont ( where , "id" , "name" )
outCont . GroupName = orgCont . Name
// _, groupCont := commonus.GetGroupCont(v.Group)
// outCont.GroupName = groupCont.Name
outCont . Department = v . Department
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = v . Department
orgContDepart , _ := commonus . GetNewOrgCont ( whereDepart , "id" , "name" )
outCont . DepartmentName = orgContDepart . Name
// _, departCont := commonus.GetBranchFactory(v.Department)
// outCont.DepartmentName = departCont.Name
qualId := GetDepartmentStatiscs ( v . Dimension , v . Target , v . Group , v . Department , 1 , userCont . Key )
if len ( qualId ) > 0 {
outCont . ExtraPoints , outCont . ScoreReduction = StatisticsMonthQual ( qualId , v . Group , v . Department , yearVal , monthVal )
}
outCont . Dimension = v . Dimension
dimensionCont , _ := commonus . GetDutyClassInfo ( v . Dimension )
outCont . DimensionName = dimensionCont . Title
outCont . Target = v . Target
outCont . Title = v . Title
outContList = append ( outContList , outCont )
}
response . Result ( 0 , outContList , "获取成功!" , c )
}
//获取定性考核详细指标
func ( e * EvaluationInterface ) NewGetQualDetailedTarget ( c * gin . Context ) {
isTrue , userCont := commonus . ClientIdentity ( )
if isTrue != true {
response . Result ( 1001 , isTrue , "您的身份令牌已经失效!请重新登录获取身份令牌!" , c )
return
}
var requestData NewQualDetailTar
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 102 , err , "数据获取失败!" , c )
return
}
if requestData . Group == "" || requestData . Department == "" || requestData . Target == "" {
response . Result ( 103 , err , "参数错误!请检查您的输入" , c )
return
}
var qualEvaList [ ] NewQualDetailOutList
gormDb := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeEvaluation { } ) . Select ( "qe_id,qe_group,qe_accept_evaluation,qe_dimension,qe_target,et_title,qe_detailed_target,dt_title,qe_target_sun,qe_qual_eval_id" ) . Joins ( "left join evaluationtarget on evaluationtarget.et_id = qualitative_evaluation.qe_target" ) . Joins ( "left join detailed_target on detailed_target.dt_id = qualitative_evaluation.qe_detailed_target" ) . Where ( "`qe_type` = 1 AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`)" , userCont . Key )
gormDb = gormDb . Where ( "`qe_group` = ?" , requestData . Group ) . Where ( "`qe_accept_evaluation` = ?" , requestData . Department ) . Where ( "`qe_target` = ?" , requestData . Target )
if requestData . Title != "" {
gormDb = gormDb . Where ( "`dt_title` LIKE ?" , "%" + requestData . Title + "%" )
}
errList := gormDb . Order ( "qe_group ASC,qe_accept_evaluation ASC,qe_dimension ASC,qe_target ASC,qe_detailed_target ASC" ) . Find ( & qualEvaList ) . Error
if errList != nil || len ( qualEvaList ) < 1 {
response . Result ( 102 , isTrue , "您没有要参加的考核项目!" , c )
return
}
var outContList [ ] NewQualDetailOutList
for _ , v := range qualEvaList {
detaiTargetCont , _ := commonus . GetDetailedTargetInfo ( v . DetailedTargetId )
var outCont NewQualDetailOutList
outCont . Id = v . Id
outCont . Group = v . Group
outCont . PlanVersionNumber = v . PlanVersionNumber
where := commonus . MapOut ( )
where [ "id" ] = v . Group
orgCont , _ := commonus . GetNewOrgCont ( where , "id" , "name" )
outCont . GroupName = orgCont . Name
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = v . Department
orgContDepart , _ := commonus . GetNewOrgCont ( whereDepart , "id" , "name" )
outCont . DepartmentName = orgContDepart . Name
// _, groupCont := commonus.GetGroupCont(v.Group)
// outCont.GroupName = groupCont.Name
outCont . Department = v . Department
// _, departCont := commonus.GetBranchFactory(v.Department)
// outCont.DepartmentName = departCont.Name
outCont . Dimension = v . Dimension
dimensionCont , _ := commonus . GetDutyClassInfo ( v . Dimension )
outCont . DimensionName = dimensionCont . Title
outCont . Target = v . Target
outCont . Title = v . Title
//子栏目
targetCont , _ := commonus . GetQualitativeTargetInfo ( v . TargetSun )
outCont . Target = v . TargetSun
outCont . TargetSunId = strconv . FormatInt ( v . TargetSun , 10 )
outCont . TargetSunName = targetCont . Title
outCont . DetailedTargetId = v . DetailedTargetId
outCont . DetailedTargetTitle = v . DetailedTargetTitle
outCont . DetailedTargetCont = detaiTargetCont . Content
outCont . AddReduce = detaiTargetCont . AddReduce
outCont . Company = detaiTargetCont . Company
outCont . State = 1
if detaiTargetCont . MinScore > 0 && detaiTargetCont . MaxScore > 0 {
outCont . Score = fmt . Sprintf ( "%v-%v" , float64 ( detaiTargetCont . MinScore ) / 100 , float64 ( detaiTargetCont . MaxScore ) / 100 )
outCont . State = 2
} else if detaiTargetCont . MinScore > 0 && detaiTargetCont . MaxScore <= 0 {
outCont . Score = fmt . Sprintf ( "%v" , float64 ( detaiTargetCont . MinScore ) / 100 )
outCont . State = 1
} else if detaiTargetCont . MinScore <= 0 && detaiTargetCont . MaxScore > 0 {
outCont . Score = fmt . Sprintf ( "%v" , float64 ( detaiTargetCont . MaxScore ) / 100 )
outCont . State = 1
} else {
outCont . Score = "0"
outCont . State = 3
}
outContList = append ( outContList , outCont )
}
response . Result ( 0 , outContList , "获取成功!" , c )
}
//判断全奖与零奖参数
func AllZreoConfig ( cycles int ) ( monthInt int64 ) {
switch cycles {
case 4 :
monthInt = commonus . ComputingTime ( time . Now ( ) . Unix ( ) , 3 )
// monthInt, _ = strconv.ParseInt(monthstr, 10, 64)
case 5 :
// var dfds error
monthInt = commonus . ComputingTime ( time . Now ( ) . Unix ( ) , 2 )
// monthInt, dfds = strconv.ParseInt(monthstrsss, 10, 64)
// fmt.Printf("monthstr--------monthInt-------->%v----->%v----->%v\n", monthstrsss, monthInt, dfds)
default :
}
return
}
//获取定量考核任务列表===>筛出已经提交的数据
func ( e * EvaluationInterface ) QualitativeEvalRationNew ( c * gin . Context ) {
isTrue , userCont := commonus . ClientIdentity ( )
if isTrue != true {
response . Result ( 1001 , isTrue , "您的身份令牌已经失效!请重新登录获取身份令牌!" , c )
return
}
var requestData GetRationFlowLog
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 102 , err , "数据获取失败!" , c )
return
}
//获取当月的起止时间
startMonth , endMonth := commonus . GetAppointMonthStarAndEndTimeInt ( time . Now ( ) . Unix ( ) )
//获取当月内所有的审批流程的部门及指标ID
// var qualEvalFlowLogList QualEvalFlowLog
var evalId [ ] int64
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . FlowLog { } ) . Select ( "fl_evaluation_id" ) . Where ( "fl_time BETWEEN ? AND ?" , startMonth , endMonth ) . Find ( & evalId )
var qualEvaList [ ] assessmentmodel . QualitativeEvaluation
gormDbIng := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeEvaluation { } ) . Select ( "qualitative_evaluation.*" )
gormDbIng = gormDbIng . Where ( "`qe_type` = 2 AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`)" , userCont . Key )
gormDbIng = gormDbIng . Not ( map [ string ] interface { } { "qe_id" : evalId } )
if requestData . GroupId != "" {
gormDbIng = gormDbIng . Where ( "qe_group = ?" , requestData . GroupId )
}
if requestData . DepartmentID != "" {
gormDbIng = gormDbIng . Where ( "qe_accept_evaluation = ?" , requestData . DepartmentID )
}
if requestData . TargetId != "" {
gormDbIng = gormDbIng . Where ( "qe_target = ?" , requestData . TargetId )
}
listErr := gormDbIng . 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 ( & qualEvaList ) . Error
if listErr != nil || len ( qualEvaList ) < 1 {
response . Result ( 102 , qualEvaList , "您没有要参加的考核项目!" , c )
return
}
}
//统计当月定性考核加减分情况
/ *
@ qualId 考核项目ID
@ dutyGroup 被考核集团
@ dutyDepartment 被考核部门
@ years 年
@ months 月
* /
func StatisticsMonthQual ( qualId [ ] int64 , dutyGroup , dutyDepartment , years , months int64 ) ( addSumScore , scoreReduction float64 ) {
where := commonus . MapOut ( )
// where["sf_evaluation_plan"] = qualId
where [ "sf_year" ] = years
where [ "sf_month" ] = months
where [ "sf_duty_group" ] = dutyGroup
where [ "sf_duty_department" ] = dutyDepartment
//加分
// var addSumScore float64 = 0
// global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Select("sf_score").Where("sf_evaluation_plan IN ?", qualId).Where(where).Where("sf_plus_reduce_score = 1").Where("sf_reply >= 2 AND sf_reply <> 4").Pluck("COALESCE(SUM(sf_score), 0) as addrescore", &addSumScore)
var jiaFenAry [ ] TongjiFenShu
// global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Select("sf_score,sf_count").Where("sf_evaluation_plan IN ?", qualId).Where(where).Where("sf_plus_reduce_score = 1").Where("sf_reply >= 2 AND sf_reply <> 4").Find(&jiaFenAry)
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_count" ) . Where ( "sf_evaluation_plan IN ?" , qualId ) . Where ( where ) . Where ( "sf_plus_reduce_score = 1" ) . Where ( "sf_reply IN (2,3)" ) . Find ( & jiaFenAry )
for _ , jiav := range jiaFenAry {
addSumScore = addSumScore + ( jiav . Score * jiav . Count )
}
//减分
// var scoreReduction float64 = 0
// global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Select("sf_score").Where("sf_evaluation_plan IN ?", qualId).Where(where).Where("sf_plus_reduce_score = 2").Where("sf_reply >= 2 AND sf_reply <> 4").Pluck("COALESCE(SUM(sf_score), 0) as redurescore", &scoreReduction)
var jianFenAry [ ] TongjiFenShu
// global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Select("sf_score,sf_count").Where("sf_evaluation_plan IN ?", qualId).Where(where).Where("sf_plus_reduce_score = 2").Where("sf_reply >= 2 AND sf_reply <> 4").Find(&jianFenAry)
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_count" ) . Where ( "sf_evaluation_plan IN ?" , qualId ) . Where ( where ) . Where ( "sf_plus_reduce_score = 2" ) . Where ( "sf_reply IN (2,3)" ) . Find ( & jianFenAry )
for _ , jianv := range jianFenAry {
scoreReduction = scoreReduction + ( jianv . Score * jianv . Count )
}
// fmt.Printf("scoreReduction----------->%v\n", jianFenAry)
addSumScore = commonus . Decimal ( addSumScore / 100 )
scoreReduction = commonus . Decimal ( scoreReduction / 100 )
return
}
//获取部门指标下的考核项目
/ *
@ dimension 维度
@ targetId 指标
@ dutyGroup 集团
@ dutyDepartment 部门
@ class 1 : 定性 ; 2 : 定量
@ userKey 员工编码
* /
func GetDepartmentStatiscs ( dimension , targetId , dutyGroup , dutyDepartment int64 , class int , userKey string ) ( qeid [ ] int64 ) {
// var qeid []int64
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeEvaluation { } ) . Select ( "qe_id" ) . Where ( "`qe_type` = ? AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`) AND qe_dimension = ? AND qe_target = ? AND qe_group = ? AND qe_accept_evaluation = ?" , class , userKey , dimension , targetId , dutyGroup , dutyDepartment ) . Find ( & qeid )
return
}