package quantification
import (
"encoding/json"
"strconv"
"gin_server_admin/commonus"
"gin_server_admin/global"
"gin_server_admin/model/assessmentmodel"
)
//计算数值用的
/ *
计算定性数值
* /
//获取定性总值
func AuxiliaryCalculationSumNature ( where interface { } ) ( sumScore float64 ) {
var addSumScore float64 = 0
//加分
var jiaFenAry [ ] TongjiFenShu
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_count" ) . 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
var jianFenAry [ ] TongjiFenShu
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_score,sf_count" ) . 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 )
}
// if addSumScore > scoreReduction {
// sumScore = addSumScore - scoreReduction
// } else {
// sumScore = scoreReduction - addSumScore
// }
sumScore = addSumScore - scoreReduction
return
// return sumScore * -1
}
// 获取定性总数
func AuxiliaryCalculationCountNature ( where interface { } ) ( sumScore float64 ) {
gormDb := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Where ( where ) . Where ( "sf_reply IN (2,3)" )
gormDb . Pluck ( "COALESCE(COUNT(sf_id), 0) as countid" , & sumScore ) //获取总数
return
}
// 计算总值和平均值
func AverageOfSumNature ( where interface { } , class ... int ) ( sumScore float64 , averageScore float64 ) {
sumScore = AuxiliaryCalculationSumNature ( where ) / 100
// panic(sumScore)
if len ( class ) > 0 {
countPage := AuxiliaryCalculationCountNature ( where )
if countPage > 0 {
averageScore = sumScore / countPage
}
}
if sumScore != 0 {
sumScore = commonus . Decimal ( sumScore )
}
if averageScore != 0 {
averageScore = commonus . Decimal ( averageScore )
}
return
}
// 统计查询条件
func ( d * dataLockStatistics ) StatisticalQueryCriteria ( qualId int64 ) {
d . mutext . Lock ( )
defer d . mutext . Unlock ( )
var flKey [ ] int64
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . FlowLogData { } ) . Distinct ( "fld_flow_log" ) . Select ( "fld_flow_log" ) . Where ( "fld_target_id = ?" , qualId ) . Find ( & flKey )
if len ( flKey ) > 0 {
var flowLogList [ ] assessmentmodel . FlowLog
// floLogErr := global.GVA_DB_Performanceappraisal.Where("FIND_IN_SET(?,`fl_evaluation_id`)", qualId).Find(&flowLogList).Error
floLogErr := global . GVA_DB_Performanceappraisal . Where ( "fl_key IN ?" , flKey ) . Find ( & flowLogList ) . Error
if floLogErr == nil {
for _ , fv := range flowLogList {
// fvDepartId := strconv.FormatInt(fv.DutyDepartment, 10)
// if commonus.IsItTrueString(fvDepartId, d.accDepart) == false {
// d.accDepart = append(d.accDepart, fvDepartId)
// }
yearStr := strconv . FormatInt ( int64 ( fv . Year ) , 10 )
if commonus . IsItTrueString ( yearStr , d . YearTime ) == false {
d . YearTime = append ( d . YearTime , yearStr )
}
//判断组织架构是否有数据
if len ( d . OrgMap ) > 0 {
for oi , ov := range d . OrgMap {
//判断公司是否已经存在
if ov . Id == strconv . FormatInt ( fv . DutyGroup , 10 ) {
//判断是否有分厂数据
if len ( ov . Child ) > 0 {
isYes := true
for _ , dv := range ov . Child {
if dv . Id == strconv . FormatInt ( fv . DutyDepartment , 10 ) {
isYes = false //该部门分厂已经存在
}
}
if isYes == true {
//该部门分厂不存在是添加
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
d . OrgMap [ oi ] . Child = append ( d . OrgMap [ oi ] . Child , orgDepartMapCont )
}
}
} else {
//没有分厂数据,根据上级数据进行新增
if fv . DutyDepartment != 0 {
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
d . OrgMap [ oi ] . Child = append ( d . OrgMap [ oi ] . Child , orgDepartMapCont )
}
}
}
} else {
if fv . DutyGroup != 0 {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = fv . DutyGroup
orgGroupCont , orgGroupErr := commonus . GetNewOrgCont ( where , "name" )
if orgGroupErr == nil {
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( fv . DutyGroup , 10 )
orgMapCont . Name = orgGroupCont . Name
if fv . DutyDepartment != 0 {
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
orgMapCont . Child = append ( orgMapCont . Child , orgDepartMapCont )
}
}
d . OrgMap = append ( d . OrgMap , orgMapCont )
}
}
}
}
} else {
//没有数据的时候根据数值进行新增
if fv . DutyGroup != 0 {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = fv . DutyGroup
orgGroupCont , orgGroupErr := commonus . GetNewOrgCont ( where , "name" )
if orgGroupErr == nil {
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( fv . DutyGroup , 10 )
orgMapCont . Name = orgGroupCont . Name
if fv . DutyDepartment != 0 {
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
orgMapCont . Child = append ( orgMapCont . Child , orgDepartMapCont )
}
}
d . OrgMap = append ( d . OrgMap , orgMapCont )
}
}
}
}
}
}
synergeticProcess . Done ( )
}
func ( d * dataLockStatistics ) StatisticalQueryCriteriaXin ( qualId int64 ) {
d . mutext . Lock ( )
defer d . mutext . Unlock ( )
// fmt.Printf("%v----------1--3--------%v\n", qualId, qualId)
var flowLogList [ ] assessmentmodel . ScoreFlow
// floLogErr := global.GVA_DB_Performanceappraisal.Where("sf_evaluation_plan = ?", qualId).Find(&flowLogList).Error
floLogErr := global . GVA_DB_Performanceappraisal . Where ( "sf_target_id = ?" , qualId ) . Find ( & flowLogList ) . Error
if floLogErr == nil {
for _ , fv := range flowLogList {
// fvDepartId := strconv.FormatInt(fv.DutyDepartment, 10)
// if commonus.IsItTrueString(fvDepartId, d.accDepart) == false {
// d.accDepart = append(d.accDepart, fvDepartId)
// }
yearStr := strconv . FormatInt ( int64 ( fv . Year ) , 10 )
if commonus . IsItTrueString ( yearStr , d . YearTime ) == false {
d . YearTime = append ( d . YearTime , yearStr )
}
//判断组织架构是否有数据
if len ( d . OrgMap ) > 0 {
for oi , ov := range d . OrgMap {
//判断公司是否已经存在
if ov . Id == strconv . FormatInt ( fv . DutyGroup , 10 ) {
//判断是否有分厂数据
if len ( ov . Child ) > 0 {
isYes := true
for _ , dv := range ov . Child {
if dv . Id == strconv . FormatInt ( fv . DutyDepartment , 10 ) {
isYes = false //该部门分厂已经存在
}
}
if isYes == true {
//该部门分厂不存在是添加
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
d . OrgMap [ oi ] . Child = append ( d . OrgMap [ oi ] . Child , orgDepartMapCont )
}
}
} else {
//没有分厂数据,根据上级数据进行新增
if fv . DutyDepartment != 0 {
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
d . OrgMap [ oi ] . Child = append ( d . OrgMap [ oi ] . Child , orgDepartMapCont )
}
}
}
} else {
if fv . DutyGroup != 0 {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = fv . DutyGroup
orgGroupCont , orgGroupErr := commonus . GetNewOrgCont ( where , "name" )
if orgGroupErr == nil {
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( fv . DutyGroup , 10 )
orgMapCont . Name = orgGroupCont . Name
if fv . DutyDepartment != 0 {
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
orgMapCont . Child = append ( orgMapCont . Child , orgDepartMapCont )
}
}
d . OrgMap = append ( d . OrgMap , orgMapCont )
}
}
}
}
} else {
//没有数据的时候根据数值进行新增
if fv . DutyGroup != 0 {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = fv . DutyGroup
orgGroupCont , orgGroupErr := commonus . GetNewOrgCont ( where , "name" )
if orgGroupErr == nil {
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( fv . DutyGroup , 10 )
orgMapCont . Name = orgGroupCont . Name
if fv . DutyDepartment != 0 {
//写入部门
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = fv . DutyDepartment
orgDepartCont , orgDepartErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgDepartErr == nil {
var orgDepartMapCont orgModels
orgDepartMapCont . Id = strconv . FormatInt ( fv . DutyDepartment , 10 )
orgDepartMapCont . Name = orgDepartCont . Name
orgMapCont . Child = append ( orgMapCont . Child , orgDepartMapCont )
}
}
d . OrgMap = append ( d . OrgMap , orgMapCont )
}
}
}
}
}
synergeticProcess . Done ( )
}
//获取指标参考值
/ *
@ dimensionId 维度
@ targetId 指标
@ departmentId 部门
* /
func GetTargetReferenceValue ( dimensionId , targetId , departmentId string ) ( standardValue float64 ) {
var planVersion assessmentmodel . PlanVersio
err := global . GVA_DB_Performanceappraisal . Where ( "state = 1 AND department = ?" ) . First ( & planVersion ) . Error
if err != nil {
return
}
var planVersioInfo [ ] AddDutyNewCont
jsonErr := json . Unmarshal ( [ ] byte ( planVersion . Content ) , & planVersioInfo )
if jsonErr != nil {
return
}
for _ , v := range planVersioInfo {
if v . Id == dimensionId {
for _ , cv := range v . Child {
if cv . Id == targetId {
standardValue = cv . ReferenceScore
}
}
}
}
return
}