package postpc import ( "key_performance_indicators/models/modelskpi" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strconv" "github.com/gin-gonic/gin" ) //岗位指标相关操作 // 获取岗位指标详情 func (a *ApiMethod) GetPostTarget(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 postTargetCont modelskpi.PostTarget err = postTargetCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}) if err != nil { publicmethod.Result(107, err, c) return } var sendData getPostOneTarget sendData.Id = postTargetCont.Id sendData.Title = postTargetCont.Title //标题"` sendData.Type = postTargetCont.Type //1:定性考核;2:定量考核"` sendData.State = postTargetCont.State //:状态(1:启用;2:禁用;3:删除)"` sendData.Time = postTargetCont.Time //创建时间"` sendData.Share = postTargetCont.Share //1:共用;2:私用"` sendData.ReleDepart = postTargetCont.ReleDepart //相关部门"` sendData.DepartmentsPost = postTargetCont.DepartmentsPost //相关岗位"` sendData.Dimension = postTargetCont.Dimension //维度"` sendData.Key = postTargetCont.Key //UUID"` sendData.Report = postTargetCont.Report //上报人"` sendData.Unit = postTargetCont.Unit //单位"` sendData.Cycle = postTargetCont.Cycle //1:班;2:天;3:周;4:月;5:季度;6:年"` sendData.Cycleattr = postTargetCont.Cycleattr //辅助计数"` sendData.ScoringMethod = postTargetCont.ScoringMethod //计分方式(1:自动;2:手动)"` sendData.VisibleRange = postTargetCont.VisibleRange //可见范围"` sendData.VisibleGroup = postTargetCont.VisibleGroup //可见范围(集团)"` _, sendData.RelevantPostsMan, _ = getTargetAboutPost(postTargetCont.ReleDepart, postTargetCont.Dimension, postTargetCont.Id) publicmethod.Result(0, sendData, c) } /* 获取岗位指标相关岗位 @departmentId 部门Id @dimensionId 维度 @targetId 指标 */ func getTargetAboutPost(departmentId, dimensionId, targetId int64) (postId []int64, postPeopleList []postPeople, err error) { err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = 2 AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ?").Find(&postId).Error if len(postId) > 0 { for i := 0; i < len(postId); i++ { var postmanCont postPeople postmanCont.Id = strconv.FormatInt(postId[i], 10) _, postmanCont.Operator, _ = getTargetAboutPostMan(departmentId, postId[i], dimensionId, targetId) postPeopleList = append(postPeopleList, postmanCont) } } return } /* 获取岗位指标相关岗位提报人 @departmentId 部门Id @postid 岗位 @dimensionId 维度 @targetId 指标 */ func getTargetAboutPostMan(departmentId, postid, dimensionId, targetId int64) (peopleId []int64, postPeople []string, err error) { err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = 2 AND `department_id` = ? AND `post_id` = ? AND `dimension_id` = ? AND `target_id` = ?").Find(&peopleId).Error if len(peopleId) > 0 { for i := 0; i < len(peopleId); i++ { postPeople = append(postPeople, strconv.FormatInt(peopleId[i], 10)) } } return }