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"
"time"
"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 )
}
outCont . UserKey = receivedValue . UserKey
outList = append ( outList , outCont )
}
publicmethod . ResultList ( 0 , receivedValue . Page , receivedValue . PageSize , total , int64 ( len ( outList ) ) , outList , c )
}
// 获取被考核人定性指标细则详细内容
func ( a * ApiMethod ) GetNaturePostDimerons ( c * gin . Context ) {
var receivedValue postNaturcInfo
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . UserKey == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
if receivedValue . Id == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
var shemeCont modelskpi . QualitativeEvaluationScheme
errSheme := shemeCont . GetCont ( map [ string ] interface { } { "`id`" : receivedValue . Id } )
if errSheme != nil {
publicmethod . Result ( 107 , receivedValue , c )
return
}
var outCont outNatureDimePostCont
outCont . Id = shemeCont . Id
outCont . VersionNumber = shemeCont . VersionNumber // 版本编号"`
outCont . CompanyId = shemeCont . CompanyId // 归属公司"`
outCont . DepartmentId = shemeCont . DepartmentId // 归属部门"`
outCont . OrgId = shemeCont . OrgId // 归属行政组织"`
outCont . PostId = shemeCont . PostId // 归属岗位"`
outCont . Title = shemeCont . Title //考核项名称"`
outCont . DimensionId = shemeCont . DimensionId //维度"`
outCont . TargetId = shemeCont . TargetId // 指标"`
outCont . SonTargetId = shemeCont . SonTargetId //子栏目"`
outCont . DetailsId = shemeCont . DetailsId //细则"`
outCont . Attribute = shemeCont . Attribute // 属性 1:定性考核;2:定量考核"`
outCont . MinScore = shemeCont . MinScore // 最小分*100保存"`
outCont . MaxScore = shemeCont . MaxScore //最大分*100保存"`
outCont . ScoringMethod = shemeCont . ScoringMethod //计分方式(1:自动;2:手动)"`
outCont . State = shemeCont . State //状态(1:启用;2:禁用;3:删除)"`
outCont . Addtime = shemeCont . Addtime //添加时间"`
outCont . Eitetime = shemeCont . Eitetime // 编辑时间"`
outCont . CensorType = shemeCont . CensorType //检查方式(1:现场检查;2:资料检查;3:事件触发)"`
outCont . Source = shemeCont . Source //来源(1:岗位;2:部门引用)"`
outCont . RunState = shemeCont . RunState //运行状态(1:启用;2:禁用;3:观察)"`
outCont . Punishmode = shemeCont . Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金
outCont . Maxmoney = shemeCont . Maxmoney //最高罚款
outCont . Minmoney = shemeCont . Minmoney //最低罚款
if shemeCont . CensorType != "" {
outCont . CensorTypeAry = strings . Split ( shemeCont . CensorType , "," )
}
if shemeCont . DetailsId != 0 {
//获取指标信息
if shemeCont . Source == 1 { //岗位
var targetCont modelskpi . PostTargetDetails
targetCont . GetCont ( map [ string ] interface { } { "`id`" : shemeCont . 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`" : shemeCont . DetailsId } , "`dt_add_reduce`" )
outCont . Context = departTarDeta . Content //指标说明"`
outCont . AddReduce = departTarDeta . AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
outCont . CensorCont = departTarDeta . CensorCont //检查依据"`
}
}
if shemeCont . MinScore != 0 {
outCont . ScoreStr = fmt . Sprintf ( "%v-%v" , shemeCont . MinScore , shemeCont . MaxScore )
} else {
outCont . ScoreStr = fmt . Sprintf ( "%v" , shemeCont . MaxScore )
}
if shemeCont . Minmoney != 0 {
outCont . MoneyStr = fmt . Sprintf ( "%v-%v" , shemeCont . Minmoney , shemeCont . Maxmoney )
} else {
outCont . MoneyStr = fmt . Sprintf ( "%v" , shemeCont . Maxmoney )
}
outCont . UserKey = receivedValue . UserKey
publicmethod . Result ( 0 , outCont , c )
}
// 提交个人岗位定性考核数据
func ( a * ApiMethod ) SendUsNatureEvaluation ( c * gin . Context ) {
var receivedValue sendMyEvaluationData
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . Id == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
var postShemeCont modelskpi . QualitativeEvaluationScheme
err = postShemeCont . GetCont ( map [ string ] interface { } { "`id`" : receivedValue . Id } )
if err != nil {
publicmethod . Result ( 107 , err , c )
return
}
if receivedValue . UserKey == "" {
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
}
if receivedValue . AddOrDecrease == 0 {
receivedValue . AddOrDecrease = 2
}
if receivedValue . Punishmode == 0 {
receivedValue . Punishmode = 1
}
var scoreVal int64 = 0
var moneyVal int64 = 0
isTrue := false
var msg string
switch receivedValue . Punishmode {
case 1 :
scoreVal , isTrue , msg = judgeScoreOrMoneyIsTrue ( receivedValue . ScoreState , receivedValue . Score , postShemeCont . MaxScore , postShemeCont . MinScore )
if isTrue != true {
publicmethod . Result ( 1 , isTrue , c , msg )
return
}
case 2 :
moneyVal , isTrue , msg = judgeScoreOrMoneyIsTrue ( receivedValue . MoneyState , receivedValue . Money , postShemeCont . Maxmoney , postShemeCont . Minmoney )
if isTrue != true {
publicmethod . Result ( 1 , isTrue , c , msg )
return
}
case 3 :
scoreVal , isTrue , msg = judgeScoreOrMoneyIsTrue ( receivedValue . ScoreState , receivedValue . Score , postShemeCont . MaxScore , postShemeCont . MinScore )
if isTrue != true {
publicmethod . Result ( 1 , isTrue , c , msg )
return
}
moneyVal , isTrue , msg = judgeScoreOrMoneyIsTrue ( receivedValue . MoneyState , receivedValue . Money , postShemeCont . Maxmoney , postShemeCont . Minmoney )
if isTrue != true {
publicmethod . Result ( 1 , isTrue , c , msg )
return
}
}
if receivedValue . Count == 0 {
receivedValue . Count = 1
}
currentTime := time . Now ( ) . Unix ( )
if receivedValue . HappenTime != "" {
happTime , timeErr := publicmethod . DateToTimeStamp ( receivedValue . HappenTime )
if timeErr == true {
currentTime = happTime
}
}
if receivedValue . Rectification == 0 {
receivedValue . Rectification = 2
}
uuId := publicmethod . GetUUid ( 1 )
//流程列表
var flowCont modelskpi . PostWorkflowOrders
fmt . Printf ( "%v---%v---%v---%v---%v\n" , currentTime , uuId , flowCont , scoreVal , moneyVal )
}
/ *
判断分数是否符合要求
@ scoreState 1 、 定分 ; 2 、 区间分 ; 3 、 不定性分值
@ score 要操作的数值
@ MaxScore 最大值
@ minScore 最小值
* /
func judgeScoreOrMoneyIsTrue ( scoreState int , score string , maxScore , minScore int64 ) ( scoreInt64 int64 , isTrue bool , msg string ) {
isTrue = false
switch scoreState {
case 2 , 3 :
if score == "" {
return
}
scoreInt64 , _ = strconv . ParseInt ( score , 10 , 64 )
scoreInt64 = scoreInt64 * 100
if scoreInt64 > maxScore {
msg = fmt . Sprintf ( "您提交的数值超过允许提交的最大值(最大值:%v)!" , float64 ( maxScore ) / 100 )
return
}
if scoreInt64 < minScore {
msg = fmt . Sprintf ( "您提交的数值低于允许提交的最小值(最小值:%v)!" , float64 ( minScore ) / 100 )
return
}
isTrue = true
case 1 :
scoreInt64 , _ = strconv . ParseInt ( score , 10 , 64 )
scoreInt64 = scoreInt64 * 100
isTrue = true
default :
msg = "请您输入要操作的数据,谢谢!"
return
}
return
}