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.
360 lines
16 KiB
360 lines
16 KiB
package quantification
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/api/admin/dutyassess"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/hrsystem"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
//汇总详情
|
|
func (a *ApiGroup) SummaryDetails(c *gin.Context) {
|
|
var requestData detailedResults
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
response.Result(101, err, "数据获取失败!", c)
|
|
return
|
|
}
|
|
if requestData.Department == "" {
|
|
response.Result(102, err, "参数错误!请属入部门", c)
|
|
return
|
|
}
|
|
if requestData.Year == 0 {
|
|
requestData.Year = commonus.ComputingTime(time.Now().Unix(), 1)
|
|
}
|
|
if requestData.Months < 1 {
|
|
requestData.Months = 1
|
|
}
|
|
if requestData.Months > 12 {
|
|
requestData.Months = 12
|
|
}
|
|
//获取部门版本
|
|
var planVersion assessmentmodel.PlanVersio
|
|
pvErr := global.GVA_DB_Performanceappraisal.Where("department = ? AND state = 1", requestData.Department).First(&planVersion).Error
|
|
if pvErr != nil {
|
|
response.Result(103, err, "没有查询到数据!", c)
|
|
return
|
|
}
|
|
//版本内容解析
|
|
var planVersionCont []dutyassess.AddDutyNewCont
|
|
jsonErr := json.Unmarshal([]byte(planVersion.Content), &planVersionCont)
|
|
if jsonErr != nil {
|
|
response.Result(104, err, "没有查询到数据!", c)
|
|
return
|
|
}
|
|
if len(planVersionCont) < 1 {
|
|
response.Result(104, err, "没有查询到数据!", c)
|
|
return
|
|
}
|
|
var sumScore float64 = 0
|
|
var lookStatistics []detailedResultsList
|
|
for _, v := range planVersionCont { //维度
|
|
for _, cv := range v.Child { //指标
|
|
// if cv.Id == "6" {
|
|
var statisCont detailedResultsList
|
|
statisCont.GroupId = strconv.FormatInt(planVersion.Group, 10) //集团Id
|
|
var groupCont hrsystem.AdministrativeOrganization
|
|
groupCont.GetCont(map[string]interface{}{"`id`": planVersion.Group}, "name")
|
|
statisCont.GroupName = groupCont.Name //集团名称
|
|
statisCont.DepartmentId = strconv.FormatInt(planVersion.Department, 10) //部门ID
|
|
var departCont hrsystem.AdministrativeOrganization
|
|
departCont.GetCont(map[string]interface{}{"`id`": planVersion.Department}, "name")
|
|
statisCont.DepartmentName = departCont.Name //部门名称
|
|
statisCont.DimensionId = v.Id //维度Id
|
|
statisCont.DimensionName = v.Name //维度名称
|
|
statisCont.DimensionWeight = int64(v.ZhiFraction) //维度权重
|
|
statisCont.TargetId = cv.Id //指标ID
|
|
statisCont.TargetName = cv.Name //指标名称
|
|
statisCont.TargetCont = cv.Content //指标名称
|
|
statisCont.Targetweight = cv.ReferenceScore //指标权重
|
|
var evalTargetCont assessmentmodel.EvaluationTarget
|
|
if cv.Id != "" && cv.Id != "0" {
|
|
targetErr := evalTargetCont.GetCont(map[string]interface{}{"`et_id`": cv.Id}, "et_type")
|
|
if targetErr == nil {
|
|
if evalTargetCont.Type == 1 {
|
|
statisCont.Score, statisCont.ExecutiveDepartment = dingXingMonthSum(planVersion.Group, planVersion.Department, cv.ReferenceScore, requestData.Year, int64(requestData.Months), cv.Id, cv.Cycles, cv.Status)
|
|
sumScore = sumScore + statisCont.Score
|
|
} else {
|
|
statisCont.Score, statisCont.ExecutiveDepartment = dingLiangMonthSum(planVersion.Group, planVersion.Department, cv.ReferenceScore, requestData.Year, int64(requestData.Months), cv.Id, cv.Cycles, cv.Status)
|
|
sumScore = sumScore + statisCont.Score
|
|
}
|
|
|
|
}
|
|
}
|
|
statisCont.Type = evalTargetCont.Type //1:定性;2:定量
|
|
statisCont.Unit = cv.Unit //单位
|
|
statisCont.Cycle = cv.Cycles //周期
|
|
statisCont.Cycleattr = cv.CycleAttres //辅助参数
|
|
// statisCont.ExecutiveDepartment = //执行部门
|
|
// statisCont.Score = //得分
|
|
// if cv.Id != "" && cv.Id != "0" {
|
|
// // var targetCont assessmentmodel.EvaluationTarget
|
|
// // targetErr := global.GVA_DB_Performanceappraisal.Model(&targetCont).Select("et_type").Where("et_id = ?", cv.Id).First(&targetCont).Error
|
|
// if targetErr == nil {
|
|
// statisCont.Score, statisCont.ExecutiveDepartment = dingXingMonthSum(planVersion.Group, planVersion.Department, cv.ReferenceScore, requestData.Year, int64(requestData.Months), cv.Id)
|
|
// }
|
|
// }
|
|
|
|
lookStatistics = append(lookStatistics, statisCont)
|
|
// }
|
|
}
|
|
|
|
}
|
|
response.Result(0, lookStatistics, "查询成功", c)
|
|
}
|
|
|
|
//定性月份分值合计
|
|
func dingXingMonthSum(groupId, departmentId, weight, year, month int64, targetId string, cycs, status int) (score float64, EvalDepartment []string) {
|
|
|
|
//获取减分
|
|
var minusPoints float64 = 0
|
|
var scoreFlowList []assessmentmodel.ScoreFlow
|
|
minusErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Select("sf_score,sf_evaluation_department,sf_count").Where("sf_plus_reduce_score = 2 AND sf_reply IN ? AND sf_duty_group = ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?", []int{2, 3}, groupId, departmentId, year, month, targetId).Find(&scoreFlowList).Error
|
|
if minusErr == nil {
|
|
for _, mv := range scoreFlowList {
|
|
minusPoints = minusPoints + (float64(mv.Score) * float64(mv.Count))
|
|
var minusDepartment hrsystem.AdministrativeOrganization
|
|
minErr := minusDepartment.GetCont(map[string]interface{}{"id": mv.EvaluationDepartment}, "name")
|
|
// fmt.Printf("extraDepartment.Name---1-->%v\n", minusDepartment.Name)
|
|
if minErr == nil {
|
|
if commonus.IsInTrue[string](minusDepartment.Name, EvalDepartment) == false {
|
|
EvalDepartment = append(EvalDepartment, minusDepartment.Name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//获取加分
|
|
var extraPoints float64 = 0
|
|
extraErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Select("sf_score,sf_evaluation_department,sf_count").Where("sf_plus_reduce_score = 1 AND sf_reply IN ? AND sf_duty_group = ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?", []int{2, 3}, groupId, departmentId, year, month, targetId).Find(&scoreFlowList).Error
|
|
if extraErr == nil {
|
|
var orgIdAry []int64
|
|
for _, ev := range scoreFlowList {
|
|
extraPoints = extraPoints + float64(ev.Score)
|
|
if commonus.IsInTrue[int64](ev.EvaluationDepartment, orgIdAry) == false {
|
|
orgIdAry = append(orgIdAry, ev.EvaluationDepartment)
|
|
var extraDepartment hrsystem.AdministrativeOrganization
|
|
minErr := extraDepartment.GetCont(map[string]interface{}{"id": ev.EvaluationDepartment}, "name")
|
|
// fmt.Printf("extraDepartment.Name---2-->%v\n", extraDepartment.Name)
|
|
if minErr == nil {
|
|
if commonus.IsInTrue[string](extraDepartment.Name, EvalDepartment) == false {
|
|
EvalDepartment = append(EvalDepartment, extraDepartment.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
// fmt.Printf("EvalDepartment--2--->%v\n", EvalDepartment)
|
|
score = commonus.Decimal(((float64(weight) + extraPoints/100) - minusPoints/100))
|
|
|
|
if targetId == "6" {
|
|
// fmt.Printf("targetId--1--->%v--->%v--->%v--->%v\n", weight, extraPoints, minusPoints, score)
|
|
}
|
|
if cycs != 4 {
|
|
score = float64(weight)
|
|
}
|
|
if status == 3 {
|
|
score = float64(weight)
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取定量考核分值
|
|
func dingLiangMonthSum(groupId, departmentId, weight, year, month int64, targetId string, cycs, status int) (score float64, EvalDepartment []string) {
|
|
var flowDataLog []assessmentmodel.FlowDataLogType
|
|
err := global.GVA_DB_Performanceappraisal.Where("`group` = ? AND `department` = ? AND `year` = ? AND `month` = ? AND `targetid` = ?", groupId, departmentId, year, month, targetId).Find(&flowDataLog).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
var sumScore float64 = 0
|
|
var sumScoreEs float64 = 0
|
|
for _, v := range flowDataLog {
|
|
if status != 3 {
|
|
if v.ScoringMethod == 1 {
|
|
sumScore = sumScore + float64(v.Score)
|
|
sumScoreGet, _, _, _, _ := analysisReward(targetId, v.Baseline, float64(weight), float64(v.Score))
|
|
sumScoreEs = sumScoreEs + sumScoreGet
|
|
} else {
|
|
sumScoreEs = sumScoreEs + (float64(v.ScoringScore) / 100)
|
|
// sumScoreGet, _, _, _, _ := analysisReward(targetId, v.Baseline, float64(weight), float64(v.ScoringScore))
|
|
// sumScoreEs = sumScoreEs + sumScoreGet
|
|
}
|
|
}
|
|
|
|
var extraDepartment hrsystem.AdministrativeOrganization
|
|
minErr := extraDepartment.GetCont(map[string]interface{}{"id": v.EvaluationDepartment}, "name")
|
|
// fmt.Printf("extraDepartment.Name-3---->%v\n", extraDepartment.Name)
|
|
if minErr == nil {
|
|
if commonus.IsInTrue[string](extraDepartment.Name, EvalDepartment) == false {
|
|
EvalDepartment = append(EvalDepartment, extraDepartment.Name)
|
|
}
|
|
}
|
|
}
|
|
// fmt.Printf("EvalDepartment--3--->%v\n", EvalDepartment)
|
|
score = sumScoreEs
|
|
if cycs != 4 {
|
|
score = float64(weight)
|
|
}
|
|
if status == 3 {
|
|
score = float64(weight)
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取定量流水全奖、零奖、封顶值
|
|
/*
|
|
@targetId 指标ID
|
|
@rewardCont 全奖、零奖、封顶值设置
|
|
@targetScore 指标分值
|
|
@settlementScore 计算分值
|
|
返回说明
|
|
@scoreVal 计算得分
|
|
@allPrize 全奖值
|
|
@zeroPrize 零奖值
|
|
@CappingVal 封顶值
|
|
@achievement 达成率
|
|
*/
|
|
func analysisReward(targetId, rewardCont string, targetScore, settlementScore float64) (scoreVal, allPrize, zeroPrize, CappingVal, achievement float64) {
|
|
var rewardAry []FlowLogAllZreo
|
|
jsonErr := json.Unmarshal([]byte(rewardCont), &rewardAry)
|
|
if jsonErr != nil {
|
|
scoreVal = targetScore
|
|
return
|
|
}
|
|
if len(rewardAry) < 1 {
|
|
scoreVal = targetScore
|
|
return
|
|
}
|
|
|
|
for _, v := range rewardAry {
|
|
if v.TargetId == targetId {
|
|
allPrize = v.Allprize
|
|
zeroPrize = v.Zeroprize
|
|
CappingVal = v.Capping
|
|
|
|
// fmt.Printf("%v----全奖--1-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
|
|
if allPrize == 0 && zeroPrize == 0 { //全奖值与零奖值都为0 那么达成率 100 和实际得分是 指标分
|
|
achievement = 100
|
|
scoreVal = targetScore
|
|
// fmt.Printf("%v----全奖--2-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
if allPrize > zeroPrize { //如果全奖值大于零奖值 执行一下操作
|
|
if settlementScore <= zeroPrize { //实际结算值小于零奖值 那么达成率和实际得分都是0
|
|
scoreVal = 0
|
|
achievement = 0
|
|
// fmt.Printf("%v----全奖--3-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else { //实际结算值在全奖值 与 零奖值之间
|
|
chuShu := settlementScore - float64(zeroPrize)
|
|
beiChuShu := float64(allPrize) - float64(zeroPrize)
|
|
if beiChuShu != 0 {
|
|
achievement = commonus.DecimalEs(chuShu/beiChuShu, 4)
|
|
if achievement <= 0 {
|
|
achievement = 0
|
|
scoreVal = 0
|
|
// fmt.Printf("%v----全奖--4-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
if achievement*100 >= CappingVal/100 {
|
|
scoreVal = (CappingVal / 100) * targetScore / 100
|
|
} else {
|
|
scoreVal = (chuShu / beiChuShu) * targetScore
|
|
}
|
|
// fmt.Printf("%v----全奖--6-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
}
|
|
achievement = commonus.DecimalEs(achievement*100, 4)
|
|
// fmt.Printf("%v----全奖--6-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
achievement = 0
|
|
scoreVal = 0
|
|
}
|
|
}
|
|
|
|
} else { //如果全奖值小于零奖值 执行一下操作
|
|
if settlementScore >= zeroPrize { //实际结算值大于零奖值 那么达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
// fmt.Printf("%v----全奖--7-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
chuShu := settlementScore - float64(zeroPrize)
|
|
beiChuShu := float64(allPrize) - float64(zeroPrize)
|
|
if beiChuShu != 0 {
|
|
achievement = commonus.DecimalEs(chuShu/beiChuShu, 4)
|
|
if achievement <= 0 {
|
|
//如果在全奖值大于零件值的情况下出现达成率为0或负数,则达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
// fmt.Printf("%v----全奖--8-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
if achievement*100 >= CappingVal {
|
|
scoreVal = (CappingVal / 100) * targetScore / 100
|
|
// fmt.Printf("%v----全奖--13-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
scoreVal = (chuShu / beiChuShu) * targetScore
|
|
// fmt.Printf("%v----全奖--14-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
}
|
|
// fmt.Printf("%v----全奖--9-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
}
|
|
achievement = commonus.DecimalEs(achievement*100, 4)
|
|
// fmt.Printf("%v----全奖--10-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
} else {
|
|
//被除数为0时 那么达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
// fmt.Printf("%v----全奖--11-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
scoreVal = commonus.Decimal(scoreVal)
|
|
allPrize = commonus.Decimal(allPrize)
|
|
zeroPrize = commonus.Decimal(zeroPrize)
|
|
CappingVal = commonus.Decimal(CappingVal)
|
|
achievement = commonus.DecimalEs(achievement, 4)
|
|
// fmt.Printf("%v----全奖--12-->%v--零奖------->%v----封顶值---->%v----指标---->%v----计算---->%v-----结果------->%v-----达成率------->%v\n", targetId, allPrize, zeroPrize, CappingVal, targetScore, settlementScore, scoreVal, achievement)
|
|
return
|
|
}
|
|
|
|
//汇总历史记录表
|
|
func (a *ApiGroup) SummaryDetailsLiangLog(c *gin.Context) {
|
|
var requestData detailedResultsLog
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
response.Result(101, err, "数据获取失败!", c)
|
|
return
|
|
}
|
|
if requestData.TargetId == "" {
|
|
response.Result(102, err, "参数错误!请属入指标", c)
|
|
return
|
|
}
|
|
if requestData.Department == "" {
|
|
response.Result(102, err, "参数错误!请属入部门", c)
|
|
return
|
|
}
|
|
if requestData.Year == 0 {
|
|
requestData.Year = commonus.ComputingTime(time.Now().Unix(), 1)
|
|
}
|
|
if requestData.Months < 1 {
|
|
requestData.Months = 1
|
|
}
|
|
if requestData.Months > 12 {
|
|
requestData.Months = 12
|
|
}
|
|
//获取部门版本
|
|
var planVersion assessmentmodel.FlowDataLogType
|
|
pvErr := global.GVA_DB_Performanceappraisal.Where("department = ? AND state = 1", requestData.Department).First(&planVersion).Error
|
|
if pvErr != nil {
|
|
response.Result(103, err, "没有查询到数据!", c)
|
|
return
|
|
}
|
|
|
|
}
|
|
|