You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.2 KiB
112 lines
4.2 KiB
|
3 years ago
|
package postpc
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"key_performance_indicators/models/modelshr"
|
||
|
|
"key_performance_indicators/models/modelskpi"
|
||
|
|
"key_performance_indicators/overall"
|
||
|
|
"key_performance_indicators/overall/publicmethod"
|
||
|
|
"sort"
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
// 获取岗位相关指标
|
||
|
|
func (a *ApiMethod) GetPostAboutTarget(c *gin.Context) {
|
||
|
|
var receivedValue publicmethod.PublicId
|
||
|
|
err := c.ShouldBindJSON(&receivedValue)
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(100, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
//获取岗位相关信息
|
||
|
|
var postCont modelshr.Position
|
||
|
|
postContErr := postCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}, "`id`", "`duties`", "`administrative_organization`", "`superior`", "`department`")
|
||
|
|
if postContErr != nil {
|
||
|
|
publicmethod.Result(107, postContErr, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
//根据维度生成方案列表
|
||
|
|
//1、获取维度
|
||
|
|
var dimensionModels modelskpi.DutyClass
|
||
|
|
dimensionList, dimeErr := dimensionModels.ContMap(map[string]interface{}{"`state`": 1}, "`id`", "`title`", "`sort`")
|
||
|
|
fmt.Printf("dimensionList--->%v\n", dimensionList)
|
||
|
|
if dimeErr != nil || len(dimensionList) <= 0 {
|
||
|
|
publicmethod.Result(107, postContErr, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
//2、根据维度获取岗位相关指标
|
||
|
|
var postPlanSync postDimeTarSync
|
||
|
|
for _, v := range dimensionList {
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go postPlanSync.GetPostTargent(postCont, v)
|
||
|
|
}
|
||
|
|
syncSeting.Wait()
|
||
|
|
planAry := postPlanSync.readDataLock() //读取线程通道数据
|
||
|
|
if len(planAry) < 1 {
|
||
|
|
publicmethod.Result(1, planAry, c, "该岗位没有设定专属指标!您可以从部门指标中引入!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
//根据维度序号排序
|
||
|
|
sort.Slice(planAry, func(i, j int) bool {
|
||
|
|
return planAry[i].Sort < planAry[j].Sort
|
||
|
|
})
|
||
|
|
publicmethod.Result(0, planAry, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取岗位与维度相关的指标
|
||
|
|
/*
|
||
|
|
@position 岗位信息
|
||
|
|
@dutyClass 维度信息
|
||
|
|
*/
|
||
|
|
func (p *postDimeTarSync) GetPostTargent(position modelshr.Position, dutyClass modelskpi.DutyClass) {
|
||
|
|
p.mutext.Lock()
|
||
|
|
defer p.mutext.Unlock()
|
||
|
|
//获取相关指标
|
||
|
|
var postTargetList []modelskpi.PostTarget
|
||
|
|
postTarErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.PostTarget{}).Where("`state` = 1 AND `dimension` = ? AND `rele_depart` = ? AND FIND_IN_SET(?,`departments_post`)", dutyClass.Id, position.AdministrativeOrganization, position.Id).Find(&postTargetList).Error
|
||
|
|
fmt.Printf("postTargetList---->%v\n", postTargetList)
|
||
|
|
if postTarErr == nil && len(postTargetList) > 0 {
|
||
|
|
var planCont postAboutDimeTar
|
||
|
|
planCont.Id = strconv.FormatInt(dutyClass.Id, 10)
|
||
|
|
planCont.Name = dutyClass.Title
|
||
|
|
planCont.Sort = dutyClass.Sort
|
||
|
|
for _, v := range postTargetList {
|
||
|
|
var targetCont postAboutTarget
|
||
|
|
targetCont.Id = strconv.FormatInt(v.Id, 10)
|
||
|
|
targetCont.Name = v.Title
|
||
|
|
targetCont.Content = "" //指标描述
|
||
|
|
targetCont.StandardScore = getPostDimeTarWeight(position.AdministrativeOrganization, position.Id, dutyClass.Id, v.Id, 1) //标准分
|
||
|
|
targetCont.Unit = v.Unit //单位
|
||
|
|
targetCont.IsTrue = 2 //是否允许修改 1:不允许;2:允许
|
||
|
|
targetCont.State = 1 //状态 1:启用;2:禁用;3:观察
|
||
|
|
|
||
|
|
planCont.Child = append(planCont.Child, targetCont)
|
||
|
|
}
|
||
|
|
p.planList = append(p.planList, planCont)
|
||
|
|
}
|
||
|
|
syncSeting.Done()
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
获取岗位考核指标或维度标准分
|
||
|
|
@orgid 行政组织
|
||
|
|
@postid 岗位
|
||
|
|
@dimensionid 维度
|
||
|
|
@targetid 指标
|
||
|
|
@hierarchy 1:维度;2:指标
|
||
|
|
*/
|
||
|
|
func getPostDimeTarWeight(orgid, postid, dimensionid, targetid int64, hierarchy int) int64 {
|
||
|
|
if hierarchy == 0 {
|
||
|
|
hierarchy = 2
|
||
|
|
}
|
||
|
|
var ddpwCont modelskpi.DepartDimePostWeight
|
||
|
|
if hierarchy == 1 {
|
||
|
|
ddpwCont.GetCont(map[string]interface{}{"orgid": orgid, "postid": postid, "dimension": dimensionid, "hierarchy": 1}, "`weight`")
|
||
|
|
} else {
|
||
|
|
ddpwCont.GetCont(map[string]interface{}{"orgid": orgid, "postid": postid, "dimension": dimensionid, "target": targetid, "hierarchy": 2}, "`weight`")
|
||
|
|
}
|
||
|
|
return ddpwCont.Weight
|
||
|
|
}
|