package nature
import (
"strconv"
"strings"
"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 ( a * ApiGroup ) Index ( c * gin . Context ) {
outPut := commonus . MapOut ( )
response . Result ( 0 , outPut , "手机考核入口" , c )
}
//计算定性考核组织范围,及起止年份
func ( a * ApiGroup ) GetTargetOrgAndYear ( c * gin . Context ) {
isTrue , _ := commonus . ClientIdentity ( )
if isTrue != true {
response . Result ( 101 , isTrue , "您的身份令牌已经失效!请重新登录获取身份令牌!" , c )
return
}
var requestData getTargetId [ string ]
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 102 , err , "数据获取失败!" , c )
return
}
if len ( requestData . TargetId ) < 1 {
response . Result ( 102 , err , "未获取到指标" , c )
return
}
// group, isTrue := commonus.GetNewHrOrg(41)
var accDepart [ ] string
var orgMap [ ] orgModelsAry
for _ , v := range requestData . TargetId {
// fmt.Printf("v-------------->%v\n", v)
var releDepart string
// var orgMap []orgModelsAry
err := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . EvaluationTarget { } ) . Select ( "et_relevant_departments" ) . Where ( "`et_id` = ?" , v ) . First ( & releDepart ) . Error
if err == nil {
departAry := strings . Split ( releDepart , "," )
// fmt.Printf("releDepart-------------->%v\n", departAry)
if len ( departAry ) > 0 {
for _ , vv := range departAry {
orgId , _ := strconv . ParseInt ( vv , 10 , 64 )
group , isTrue := commonus . GetNewHrOrg ( orgId )
if commonus . IsItTrueString ( vv , accDepart ) {
accDepart = append ( accDepart , vv )
}
// fmt.Printf("Group-----%v----Depart----->%v\n", group, vv)
if isTrue == true {
if len ( orgMap ) > 0 {
isYes := false
for oi , ov := range orgMap {
if ov . Id == strconv . FormatInt ( group , 10 ) {
isYes = true
where := commonus . MapOut ( )
where [ "id" ] = vv
orgCont , _ := commonus . GetNewOrgCont ( where , "name" )
var orgSunCont orgModels
orgSunCont . Id = vv
orgSunCont . Name = orgCont . Name
orgMap [ oi ] . Child = append ( orgMap [ oi ] . Child , orgSunCont )
}
}
if isYes == false {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = group
orgCont , _ := commonus . GetNewOrgCont ( where , "name" )
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( group , 10 )
orgMapCont . Name = orgCont . Name
orgMap = append ( orgMap , orgMapCont )
}
} else {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = group
orgCont , _ := commonus . GetNewOrgCont ( where , "name" )
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( group , 10 )
orgMapCont . Name = orgCont . Name
orgMap = append ( orgMap , orgMapCont )
}
}
}
}
}
}
//获取时间
// targetIdAry := strings.Split(requestData.TargetId, ",")
var progIdAry [ ] int64
var timeList [ ] int64
gromDb := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeEvaluation { } ) . Select ( "qe_id" ) . Where ( "qe_target IN ?" , requestData . TargetId )
if len ( accDepart ) > 0 {
gromDb = gromDb . Where ( "qe_accept_evaluation IN ?" , accDepart )
}
quaEvaErr := gromDb . Find ( & progIdAry ) . Error
if quaEvaErr == nil {
if len ( progIdAry ) > 0 {
var timeAry [ ] int64
scoFlowDb := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . ScoreFlow { } ) . Select ( "sf_happen_time" ) . Where ( "sf_evaluation_plan IN ?" , progIdAry )
scoFlowErr := scoFlowDb . Find ( & timeAry ) . Error
if scoFlowErr == nil {
// maxTime, minTime = commonus.NewUserModel(timeAry)
if len ( timeAry ) > 0 {
timeList = commonus . UniqueSort ( timeAry )
}
}
}
}
var yearTime [ ] string
if len ( timeList ) > 0 {
for _ , tv := range timeList {
yearStr := commonus . TimeStampToDate ( tv , 11 )
if commonus . IsItTrueString ( yearStr , yearTime ) == false {
yearTime = append ( yearTime , yearStr )
}
}
} else {
yearStr := commonus . TimeStampToDate ( time . Now ( ) . Unix ( ) , 11 )
yearTime = append ( yearTime , yearStr )
}
// var outYear []string
// if maxTime == 0 && minTime == 0 {
// yearStr := commonus.TimeStampToDate(time.Now().Unix(), 11)
// yearTime = append(yearTime, yearStr)
// }
outMap := commonus . MapOut ( )
outMap [ "grouplist" ] = orgMap
outMap [ "timelist" ] = yearTime
response . Result ( 0 , outMap , "数据获取失败!" , c )
}
//获取存在的组织架构
func getExistOrg ( targetId string ) [ ] orgModelsAry {
var releDepart string
var orgMap [ ] orgModelsAry
err := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . EvaluationTarget { } ) . Select ( "et_relevant_departments" ) . Where ( "`et_id` = ?" , targetId ) . First ( & releDepart ) . Error
if err == nil {
departAry := strings . Split ( releDepart , "," )
// fmt.Printf("releDepart-------------->%v\n", departAry)
if len ( departAry ) > 0 {
for _ , vv := range departAry {
orgId , _ := strconv . ParseInt ( vv , 10 , 64 )
group , isTrue := commonus . GetNewHrOrg ( orgId )
// fmt.Printf("Group-----%v----Depart----->%v\n", group, vv)
if isTrue == true {
if len ( orgMap ) > 0 {
isYes := false
for oi , ov := range orgMap {
if ov . Id == strconv . FormatInt ( group , 10 ) {
isYes = true
where := commonus . MapOut ( )
where [ "id" ] = vv
orgCont , _ := commonus . GetNewOrgCont ( where , "name" )
var orgSunCont orgModels
orgSunCont . Id = vv
orgSunCont . Name = orgCont . Name
orgMap [ oi ] . Child = append ( orgMap [ oi ] . Child , orgSunCont )
}
}
if isYes == false {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = group
orgCont , _ := commonus . GetNewOrgCont ( where , "name" )
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( group , 10 )
orgMapCont . Name = orgCont . Name
orgMap = append ( orgMap , orgMapCont )
}
} else {
//写入集团信息
where := commonus . MapOut ( )
where [ "id" ] = group
orgCont , _ := commonus . GetNewOrgCont ( where , "name" )
var orgMapCont orgModelsAry
orgMapCont . Id = strconv . FormatInt ( group , 10 )
orgMapCont . Name = orgCont . Name
orgMap = append ( orgMap , orgMapCont )
}
}
}
}
}
return orgMap
}
//定性考核统计
func ( a * ApiGroup ) NatureStatistics ( c * gin . Context ) {
isTrue , _ := commonus . ClientIdentity ( )
if isTrue != true {
response . Result ( 101 , isTrue , "您的身份令牌已经失效!请重新登录获取身份令牌!" , c )
return
}
var requestData natureParameter
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 102 , err , "数据获取失败!" , c )
return
}
if len ( requestData . TargetId ) < 1 {
response . Result ( 103 , err , "未获取到指标" , c )
return
}
for _ , v := range requestData . TargetId {
calculationEvaluation ( v , requestData )
}
}
//计算指标相关数值
func calculationEvaluation ( taskId string , dataAry natureParameter ) ( err error ) {
var scorFlowList [ ] assessmentmodel . ScoreFlow
gormDb := global . GVA_DB_Performanceappraisal . Where ( "`sf_evaluation_plan` = ?" , taskId )
if len ( dataAry . Year ) > 0 {
gormDb = gormDb . Where ( "`sf_year` IN ?" , dataAry . Year )
switch dataAry . TimeAttribute . Class {
case 1 :
var monthAry [ ] int
for _ , v := range dataAry . TimeAttribute . Time {
if v == 1 {
for i := 1 ; i < 7 ; i ++ {
monthAry = append ( monthAry , i )
}
}
if v == 2 {
for j := 7 ; j < 13 ; j ++ {
monthAry = append ( monthAry , j )
}
}
}
if len ( monthAry ) > 0 {
gormDb = gormDb . Where ( "`sf_month` IN ?" , monthAry )
}
case 2 :
var quarterAry [ ] int
for _ , v := range dataAry . TimeAttribute . Time {
quarterAry = append ( quarterAry , v )
}
if len ( quarterAry ) > 0 {
gormDb = gormDb . Where ( "`sf_quarter` IN ?" , quarterAry )
}
case 3 :
var monthAry [ ] int
for _ , v := range dataAry . TimeAttribute . Time {
monthAry = append ( monthAry , v )
}
if len ( monthAry ) > 0 {
gormDb = gormDb . Where ( "`sf_month` IN ?" , monthAry )
}
default :
}
}
if len ( dataAry . Org ) > 0 {
gormDb = gormDb . Where ( "`sf_duty_department` IN ?" , dataAry . Org )
}
err = gormDb . Find ( & scorFlowList ) . Error
if err != nil {
return
}
return
}