KPI绩效考核系统
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.

276 lines
10 KiB

package postpc
import (
"encoding/json"
"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, 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指标
@isQuote 1不是引用2引用部门
getPostDimeTarWeight(orgid, postid, dimensionid, targetid int64, hierarchy, isQuote int)
*/
func getPostDimeTarWeight(orgid, postid, dimensionid, targetid int64, hierarchy, isQuote int) int64 {
if hierarchy == 0 {
hierarchy = 2
}
where := publicmethod.MapOut[string]()
where["orgid"] = orgid
where["postid"] = postid
where["dimension"] = dimensionid
var ddpwCont modelskpi.DepartDimePostWeight
if hierarchy == 1 {
where["hierarchy"] = 1
// ddpwCont.GetCont(map[string]interface{}{"orgid": orgid, "postid": postid, "dimension": dimensionid, "hierarchy": 1}, "`weight`")
ddpwCont.GetCont(where, "`weight`")
} else {
where["target"] = targetid
where["hierarchy"] = 2
// ddpwCont.GetCont(map[string]interface{}{"orgid": orgid, "postid": postid, "dimension": dimensionid, "target": targetid, "hierarchy": 2}, "`weight`")
ddpwCont.GetCont(where, "`weight`")
}
return ddpwCont.Weight
}
// 引用指标部门指标
func (a *ApiMethod) QuoteDepartmentTarget(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, err, c)
return
}
//获取维度
var dimenId []int64
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`dimension_id`").Where("`state` = 1 AND `level` = 2 AND `post_id` = ?", receivedValue.Id).Find(&dimenId).Error
if err != nil || len(dimenId) < 1 {
publicmethod.Result(107, err, c)
return
}
var targetlist postDimeTarSync
//获取指标列表
for _, v := range dimenId {
syncSeting.Add(1)
go targetlist.getPostQuoteDepartmentTarget(v, receivedValue.Id)
}
syncSeting.Wait()
planAry := targetlist.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)
}
/*
获取岗位引入部门指标的列表
@dimensionId 维度
@postId 岗位
*/
func (p *postDimeTarSync) getPostQuoteDepartmentTarget(dimensionId int64, postId string) {
p.mutext.Lock()
defer p.mutext.Unlock()
var listCont postAboutDimeTar
//获取维度信息
var dimenCont modelskpi.DutyClass
dimenCont.GetCont(map[string]interface{}{"`id`": dimensionId}, "`title`", `sort`)
listCont.Id = strconv.FormatInt(dimensionId, 10)
listCont.Name = dimenCont.Title
listCont.Sort = dimenCont.Sort
//获取岗位信息
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": postId}, "`id`", "`administrative_organization`")
var targetId []int64
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`target_id`").Where("`state` = 1 AND `level` = 2 AND `dimension_id` = ? AND `post_id` = ?", dimensionId, postId).Find(&targetId)
if len(targetId) > 0 {
//获取指标信息
var targetList []modelskpi.EvaluationTarget
overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationTarget{}).Where("`et_state` = 1 AND `et_id` IN ?", targetId).Find(&targetList)
if len(targetList) > 0 {
for _, v := range targetList {
var targetCont postAboutTarget
targetCont.Id = strconv.FormatInt(v.Id, 10)
targetCont.Name = v.Title
targetCont.Content = "" //指标描述
targetCont.StandardScore = getPostDimeTarWeight(postCont.AdministrativeOrganization, postCont.Id, dimensionId, v.Id, 2, 2) //标准分
targetCont.Unit = v.Uniteing //单位
targetCont.IsTrue = 2 //是否允许修改 1:不允许;2:允许
targetCont.State = 1 //状态 1:启用;2:禁用;3:观察
targetCont.Type = v.Type
if v.Type == 1 {
detaildList := getQuoteTargetDepartList(dimensionId, v.Id, postCont.Id)
if len(detaildList) > 0 {
targetCont.Child = detaildList
listCont.Child = append(listCont.Child, targetCont)
}
} else {
listCont.Child = append(listCont.Child, targetCont)
}
}
}
}
if len(listCont.Child) > 0 {
p.planList = append(p.planList, listCont)
}
jsonStr, _ := json.Marshal(listCont)
fmt.Printf("jsonStr------->%v\n", string(jsonStr))
syncSeting.Done()
}
// 获取部门引用关联指标细则
func getQuoteTargetDepartList(dimensionId, targetId, postId int64) (listCont []quoteDeatinDeparment) {
var detaildId []int64
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`target_bylaws`").Where("`state` = 1 AND `level` = 2 AND `dimension_id` = ? AND `target_id` = ? AND `post_id` = ? AND `target_bylaws` <> 0", dimensionId, targetId, postId).Find(&detaildId)
if len(detaildId) < 1 {
return
}
var detaildList []modelskpi.DetailedTarget
overall.CONSTANT_DB_KPI.Model(&modelskpi.DetailedTarget{}).Select("`dt_id`,`dt_title`,`dt_content`,`dt_min_score`,`dt_max_score`").Where("`dt_state` = 1 AND `dt_id` IN ?", detaildId).Find(&detaildList)
if len(detaildList) < 1 {
return
}
for _, v := range detaildList {
var contList quoteDeatinDeparment
contList.Id = strconv.FormatInt(v.Id, 10)
contList.Name = v.Title
biaoZhun := ""
if v.MinScore != 0 {
biaoZhun = fmt.Sprintf("%v-%v", v.MinScore, v.MaxScore)
} else {
biaoZhun = fmt.Sprintf("%v", v.MaxScore)
}
contList.ReferenceScore = biaoZhun
listCont = append(listCont, contList)
}
fmt.Println("----------------->")
return
}
// 提交岗位考核方案
func (a *ApiMethod) SubmitPostScheme(c *gin.Context) {
var receivedValue postScheme
c.ShouldBindJSON(&receivedValue)
if receivedValue.OrgId == "" {
publicmethod.Result(101, receivedValue.OrgId, c, "请指定行政组织ID")
return
}
if receivedValue.PostId == "" {
publicmethod.Result(101, receivedValue.PostId, c, "请指定行政组织ID")
return
}
if receivedValue.Year == "" {
publicmethod.Result(101, receivedValue.Year, c, "请指定方案属于哪一年的?")
return
}
if len(receivedValue.PostChild) < 1 && len(receivedValue.DepartmentChild) < 1 {
publicmethod.Result(1, receivedValue, c, "考核项目不能为空!")
return
}
jsonCont, _ := json.Marshal(receivedValue)
publicmethod.Result(0, string(jsonCont), c)
}