package postweb
import (
"fmt"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"strconv"
"strings"
"github.com/gin-gonic/gin"
)
//岗位指标相关操作
// 获取指定人要考核的项目列表
func ( a * ApiMethod ) GetPostTarget ( c * gin . Context ) {
var receivedValue getPostManTargetList
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . Id == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
if receivedValue . Class == 0 {
receivedValue . Class = 1
}
//获取被考核人基本西悉尼
var userCont modelshr . PersonArchives
err = userCont . GetCont ( map [ string ] interface { } { "`key`" : receivedValue . Id } , "`company`" , "`maindeparment`" , "`admin_org`" , "`position`" )
if err != nil {
publicmethod . Result ( 107 , err , c )
return
}
//获取登录人信息
context , _ := publicmethod . LoginMyCont ( c )
var qualitSchemeList [ ] modelskpi . QualitativeEvaluationScheme
err = overall . CONSTANT_DB_KPI . Raw ( "SELECT q.* FROM qualitative_evaluation_scheme q Where q.state = 1 AND `attribute` = ? AND q.target_id = some (SELECT target_id FROM target_report tr WHERE tr.type = 2 AND tr.department_id = ? AND tr.post_id = ? AND tr.man_key = ?)" , receivedValue . Class , userCont . MainDeparment , userCont . Position , context . Key ) . Scan ( & qualitSchemeList ) . Error
if err != nil || len ( qualitSchemeList ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var outDataAry [ ] outPostManTargetList
for _ , v := range qualitSchemeList {
// jsonStr, _ := json.Marshal(v)
// fmt.Printf("v----------->%v\n", string(jsonStr))
var outCont outPostManTargetList
outCont . Id = strconv . FormatInt ( v . Id , 10 )
outCont . Class = v . Attribute
outCont . Title = v . Title
if v . Attribute == 1 {
if v . Source == 1 { //岗位
var postTarDeta modelskpi . PostTargetDetails
postTarDeta . GetCont ( map [ string ] interface { } { "`id`" : v . DetailsId } , "`punishmode`" )
outCont . AddReduce = postTarDeta . Punishmode
} else { //部门
var departTarDeta modelskpi . DetailedTarget
departTarDeta . GetCont ( map [ string ] interface { } { "`dt_id`" : v . DetailsId } , "`dt_add_reduce`" )
outCont . AddReduce = departTarDeta . AddReduce
}
}
outDataAry = append ( outDataAry , outCont )
}
publicmethod . Result ( 0 , outDataAry , c )
}
// 定性指标列表
func ( a * ApiMethod ) GetPostNature ( c * gin . Context ) {
var receivedValue publicmethod . PublicId
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . Id == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
//获取被考核人基本信息
var userCont modelshr . PersonArchives
err = userCont . GetCont ( map [ string ] interface { } { "`key`" : receivedValue . Id } , "`company`" , "`maindeparment`" , "`admin_org`" , "`position`" )
if err != nil {
publicmethod . Result ( 107 , err , c )
return
}
//获取登录人信息
context , _ := publicmethod . LoginMyCont ( c )
//获取被考核人本岗位的考核项目
var itemList [ ] modelskpi . ShemePeople
err = overall . CONSTANT_DB_KPI . Where ( "`state` IN (1,3) AND `type` = 2 AND `attribute` = 1 AND `run_state` <> 2 AND `org_id` = ? AND `post_id` = ? AND `man_key` = ?" , userCont . MainDeparment , userCont . Position , context . Key ) . Find ( & itemList ) . Error
if err != nil || len ( itemList ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var targetId [ ] int64
//获取指标内容
var outDataAry [ ] outPostManTargetList
for _ , v := range itemList {
if publicmethod . IsInTrue [ int64 ] ( v . TargetId , targetId ) == false {
var outCont outPostManTargetList
outCont . Id = strconv . FormatInt ( v . TargetId , 10 )
outCont . Title = v . Title
outCont . Class = v . Attribute
if v . Source == 1 { //岗位
var postTarDeta modelskpi . PostTargetDetails
postTarDeta . GetCont ( map [ string ] interface { } { "`id`" : v . DetailsId } , "`punishmode`" )
outCont . AddReduce = postTarDeta . Punishmode
} else { //部门
var departTarDeta modelskpi . DetailedTarget
departTarDeta . GetCont ( map [ string ] interface { } { "`dt_id`" : v . DetailsId } , "`dt_add_reduce`" )
outCont . AddReduce = departTarDeta . AddReduce
}
outCont . UserKey = receivedValue . Id
outCont . DimensionId = strconv . FormatInt ( v . DimensionId , 10 )
outDataAry = append ( outDataAry , outCont )
}
}
publicmethod . Result ( 0 , outDataAry , c )
}
// 获取定量指标列表
func ( a * ApiMethod ) GetPostRation ( c * gin . Context ) {
var receivedValue publicmethod . PublicId
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . Id == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
//获取被考核人基本信息
var userCont modelshr . PersonArchives
err = userCont . GetCont ( map [ string ] interface { } { "`key`" : receivedValue . Id } , "`company`" , "`maindeparment`" , "`admin_org`" , "`position`" )
if err != nil {
publicmethod . Result ( 107 , err , c )
return
}
//获取登录人信息
context , _ := publicmethod . LoginMyCont ( c )
//获取被考核人本岗位的考核项目
var itemList [ ] modelskpi . ShemePeople
err = overall . CONSTANT_DB_KPI . Where ( "`state` IN (1,3) AND `type` = 2 AND `attribute` = 2 AND `run_state` <> 2 AND `org_id` = ? AND `post_id` = ? AND `man_key` = ?" , userCont . MainDeparment , userCont . Position , context . Key ) . Find ( & itemList ) . Error
if err != nil || len ( itemList ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var targetId [ ] int64
//获取指标内容
var outDataAry [ ] outPostRation
for _ , v := range itemList {
if publicmethod . IsInTrue [ int64 ] ( v . TargetId , targetId ) == false {
var outCont outPostRation
outCont . Id = strconv . FormatInt ( v . TargetId , 10 )
outCont . Name = v . Title
outCont . UserKey = receivedValue . Id
outCont . DimensionId = strconv . FormatInt ( v . DimensionId , 10 )
outDataAry = append ( outDataAry , outCont )
}
}
publicmethod . Result ( 0 , outDataAry , c )
}
// 获取岗位定性考核指标细则列表
func ( a * ApiMethod ) GetPostDeimensoInfo ( c * gin . Context ) {
var receivedValue getNatureDimeList
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . UserKey == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
if receivedValue . DimensionId == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
if receivedValue . TargetId == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
//获取被考核人基本信息
var userCont modelshr . PersonArchives
err = userCont . GetCont ( map [ string ] interface { } { "`key`" : receivedValue . UserKey } , "`company`" , "`maindeparment`" , "`admin_org`" , "`position`" )
if err != nil {
publicmethod . Result ( 107 , err , c )
return
}
//获取登录人信息
context , _ := publicmethod . LoginMyCont ( c )
//获取被考核人本岗位的考核项目
var itemList [ ] modelskpi . ShemePeople
gormDb := overall . CONSTANT_DB_KPI . Where ( "`state` IN (1,3) AND `type` = 2 AND `attribute` = 1 AND `run_state` <> 2 AND `dimension_id` = ? AND `target_id` = ? AND `org_id` = ? AND `post_id` = ? AND `man_key` = ?" , receivedValue . DimensionId , receivedValue . TargetId , userCont . MainDeparment , userCont . Position , context . Key )
gormDb = publicmethod . PageTurningSettings ( gormDb , receivedValue . Page , receivedValue . PageSize )
errGorm := gormDb . Order ( "`son_target_id` DESC" ) . Find ( & itemList ) . Error
var total int64
totalErr := gormDb . Count ( & total ) . Error
if totalErr != nil {
total = 0
}
if errGorm != nil || len ( itemList ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var outList [ ] outNatureDimeCont
for _ , v := range itemList {
var outCont outNatureDimeCont
outCont . Id = v . Id
outCont . VersionNumber = v . VersionNumber // 版本编号"`
outCont . CompanyId = v . CompanyId // 归属公司"`
outCont . DepartmentId = v . DepartmentId // 归属部门"`
outCont . OrgId = v . OrgId // 归属行政组织"`
outCont . PostId = v . PostId // 归属岗位"`
outCont . Title = v . Title //考核项名称"`
outCont . DimensionId = v . DimensionId //维度"`
outCont . TargetId = v . TargetId // 指标"`
outCont . SonTargetId = v . SonTargetId //子栏目"`
outCont . DetailsId = v . DetailsId //细则"`
outCont . Attribute = v . Attribute // 属性 1:定性考核;2:定量考核"`
outCont . MinScore = v . MinScore // 最小分*100保存"`
outCont . MaxScore = v . MaxScore //最大分*100保存"`
outCont . ScoringMethod = v . ScoringMethod //计分方式(1:自动;2:手动)"`
outCont . State = v . State //状态(1:启用;2:禁用;3:删除)"`
outCont . Addtime = v . Addtime //添加时间"`
outCont . Eitetime = v . Eitetime // 编辑时间"`
outCont . CensorType = v . CensorType //检查方式(1:现场检查;2:资料检查;3:事件触发)"`
outCont . Source = v . Source //来源(1:岗位;2:部门引用)"`
outCont . RunState = v . RunState //运行状态(1:启用;2:禁用;3:观察)"`
outCont . Type = v . Type //类型(1:公司级;2:部门级)"`
outCont . ReportPerson = v . ReportPerson //上报人"`
outCont . ManDepartment = v . ManDepartment //提报人所在部门"`
outCont . Class = v . Class //1:定性考核;2:定量考核"`
outCont . Level = v . Level //类型(1:指标;2:子目标;3:细则)"`
outCont . Punishmode = v . Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金
outCont . Maxmoney = v . Maxmoney //最高罚款
outCont . Minmoney = v . Minmoney //最低罚款
if v . CensorType != "" {
outCont . CensorTypeAry = strings . Split ( v . CensorType , "," )
}
if v . DetailsId != 0 {
//获取指标信息
if v . Source == 1 { //岗位
var targetCont modelskpi . PostTargetDetails
targetCont . GetCont ( map [ string ] interface { } { "`id`" : v . DetailsId } , "content" , "add_reduce" , "censor_cont" )
outCont . Context = targetCont . Content //指标说明"`
outCont . AddReduce = targetCont . AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
outCont . CensorCont = targetCont . CensorCont //检查依据"`
} else { //部门
var departTarDeta modelskpi . DetailedTarget
departTarDeta . GetCont ( map [ string ] interface { } { "`dt_id`" : v . DetailsId } , "`dt_add_reduce`" )
outCont . Context = departTarDeta . Content //指标说明"`
outCont . AddReduce = departTarDeta . AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
outCont . CensorCont = departTarDeta . CensorCont //检查依据"`
}
}
if v . MinScore != 0 {
outCont . ScoreStr = fmt . Sprintf ( "%v-%v" , v . MinScore , v . MaxScore )
} else {
outCont . ScoreStr = fmt . Sprintf ( "%v" , v . MaxScore )
}
if v . Minmoney != 0 {
outCont . MoneyStr = fmt . Sprintf ( "%v-%v" , v . Minmoney , v . Maxmoney )
} else {
outCont . MoneyStr = fmt . Sprintf ( "%v" , v . Maxmoney )
}
outList = append ( outList , outCont )
}
publicmethod . ResultList ( 0 , receivedValue . Page , receivedValue . PageSize , total , int64 ( len ( outList ) ) , outList , c )
}