package statistics import ( "encoding/json" "fmt" "key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelskpi" "key_performance_indicators/overall/publicmethod" "strconv" "time" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2023-08-04 09:18:31 @ 功能: 汇总方案定量指标详情历史记录(新版) @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) SummaryPlanRecord(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(103, err, "参数错误!请属入部门", c) return } if requestData.Year == 0 { requestData.Year = publicmethod.ComputingTime(time.Now().Unix(), 1) } if requestData.Months < 1 { requestData.Months = 1 } if requestData.Months > 12 { requestData.Months = 12 } orgId, _ := strconv.ParseInt(requestData.Department, 10, 64) monthInt := int64(requestData.Months) //获取当前时间考核方案 targetScore, attribute, cycles := GetTargetPlanScore("", requestData.TargetId, orgId, requestData.Year, monthInt) // fmt.Printf("targetScore:%v\nattribute:%v\ncycles:%v\n", targetScore, attribute, cycles) var sendList []dingLiangKaoHe if err != nil { response.Result(101, err, "数据获取失败!", c) return } switch cycles { case 5: //季度度指标 if publicmethod.IsInTrue[int64](monthInt, []int64{3, 6, 9, 12}) { var fengDingZhi float64 = 0 var lingJiang float64 = 0 var quanJiang float64 = 0 isTrue := true var dingLiangScore float64 = 0 switch monthInt { case 3: for i := 1; i <= 3; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 3 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } case 6: for i := 4; i <= 6; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 6 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } case 9: for i := 7; i <= 9; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 9 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } case 12: for i := 10; i <= 12; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 12 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } default: } var secondCont dingLiangKaoHe secondCont.MtOrAt = 1 //手动还是自动 secondCont.Cont = "平均分" //说明 secondCont.Nature = 1 secondCont.Zeroprize = lingJiang secondCont.Allprize = quanJiang secondCont.Capping = fengDingZhi if attribute == 3 { secondCont.Score = targetScore } else { var daChengLv float64 = 0 var pingJunXiShu float64 = 0 for _, j := range sendList { daChengLv = daChengLv + j.CompletionRateAll pingJunXiShu++ } if pingJunXiShu > 0 { pingJunZhi := daChengLv / pingJunXiShu secondCont.Score = publicmethod.DecimalEs(GetQuantifyScore(targetScore, pingJunZhi, fengDingZhi), 2) secondCont.CompletionRate = publicmethod.DecimalEs(pingJunZhi, 2) } else { secondCont.Score = targetScore } if !isTrue { secondCont.Score = dingLiangScore } } sendList = append(sendList, secondCont) } else { sendList, _ = GetDingLiangLog(orgId, requestData.Year, monthInt, requestData.TargetId, "") } case 6: //年度指标 isTrue := true var dingLiangScore float64 = 0 var fengDingZhi float64 = 0 var lingJiang float64 = 0 var quanJiang float64 = 0 for i := 1; i <= 12; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 12 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } var secondCont dingLiangKaoHe secondCont.MtOrAt = 1 //手动还是自动 secondCont.Cont = "平均分" //说明 secondCont.Nature = 1 secondCont.Zeroprize = lingJiang secondCont.Allprize = quanJiang secondCont.Capping = fengDingZhi if attribute == 3 { secondCont.Score = targetScore } else { var daChengLv float64 = 0 var pingJunXiShu float64 = 0 for _, j := range sendList { daChengLv = daChengLv + j.CompletionRateAll pingJunXiShu++ } if pingJunXiShu > 0 { pingJunZhi := daChengLv / pingJunXiShu secondCont.Score = publicmethod.DecimalEs(GetQuantifyScore(targetScore, pingJunZhi, fengDingZhi), 2) secondCont.CompletionRate = publicmethod.DecimalEs(pingJunZhi, 2) } else { secondCont.Score = targetScore } if !isTrue { secondCont.Score = dingLiangScore } } sendList = append(sendList, secondCont) case 7: //半年指标 isTrue := true var dingLiangScore float64 = 0 var fengDingZhi float64 = 0 var lingJiang float64 = 0 var quanJiang float64 = 0 if publicmethod.IsInTrue[int64](monthInt, []int64{1, 2, 3, 4, 5, 6}) { for i := 1; i <= 6; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 6 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } } else { for i := 7; i <= 12; i++ { sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) if i == 12 { for _, v := range sendListIng { fengDingZhi = v.Capping lingJiang = v.Zeroprize quanJiang = v.Allprize if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } } var secondCont dingLiangKaoHe secondCont.MtOrAt = 1 //手动还是自动 secondCont.Cont = "平均分" //说明 secondCont.Nature = 1 secondCont.Zeroprize = lingJiang secondCont.Allprize = quanJiang secondCont.Capping = fengDingZhi if attribute == 3 { secondCont.Score = targetScore } else { var daChengLv float64 = 0 var pingJunXiShu float64 = 0 for _, j := range sendList { daChengLv = daChengLv + j.CompletionRateAll pingJunXiShu++ } if pingJunXiShu > 0 { pingJunZhi := daChengLv / pingJunXiShu secondCont.Score = publicmethod.DecimalEs(GetQuantifyScore(targetScore, pingJunZhi, fengDingZhi), 2) secondCont.CompletionRate = publicmethod.DecimalEs(pingJunZhi, 2) } else { secondCont.Score = targetScore } if !isTrue { secondCont.Score = dingLiangScore } } sendList = append(sendList, secondCont) default: sendList, _ = GetDingLiangLog(orgId, requestData.Year, monthInt, requestData.TargetId, "") // chushu := len(sendList) // var dingLiangScore float64 = 0 // if chushu > 0 { // isTrue := true // for _, v := range sendList { // dingLiangScore = dingLiangScore + v.Score // if v.MtOrAt == 2 { // dingLiangScore = v.Score // isTrue = false // } // } // if isTrue { // dingLiangScore, _ = publicmethod.DecimalNew(dingLiangScore/float64(chushu), 2) // statisCont.Score = dingLiangScore // } else { // statisCont.Score = dingLiangScore // } // } else { // targetScore, _, _ := GetTargetPlanScore("", cv.Id, orgId, requestData.Year, monthInt) // statisCont.Score = targetScore // } } response.Result(0, sendList, "查询完成!", c) } /* * @ 作者: 秦东 @ 时间: 2023-08-05 08:47:01 @ 功能: 计算定量指标分值 @ 参数 #targetScore 指标分 #completionRate 达成率 #capping 封顶值 @ 返回值 # @ 方法原型 # */ func GetQuantifyScore(targetScore, completionRate, capping float64) (score float64) { // fmt.Printf("targetScore:---》%v\ncompletionRate:---》%v\ncapping:---》%v\n", targetScore, completionRate, capping) if capping != 0 { if completionRate >= capping { score = targetScore * (capping / 100) } else { score = targetScore * (completionRate / 100) } } else { score = targetScore * (completionRate / 100) } return } /* * @ 作者: 秦东 @ 时间: 2023-08-07 10:42:04 @ 功能: 方案得分明细(new) @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) NewSummaryDetails(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 = publicmethod.ComputingTime(time.Now().Unix(), 1) } if requestData.Months < 1 { requestData.Months = 1 } if requestData.Months > 12 { requestData.Months = 12 } orgId, _ := strconv.ParseInt(requestData.Department, 10, 64) planVersion, _ := publicmethod.GetPlanVresion(orgId, requestData.Year, int64(requestData.Months)) var planVersioInfo []AddDutyNewCont json.Unmarshal([]byte(planVersion.Content), &planVersioInfo) var lookStatistics []detailedResultsList for _, v := range planVersioInfo { //维度 for _, cv := range v.Child { //指标 // if cv.Id == "120" { var statisCont detailedResultsList 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 //指标权重 statisCont.GroupId = strconv.FormatInt(planVersion.Group, 10) //集团Id statisCont.Versio = planVersion.Key var groupCont modelshr.AdministrativeOrganization groupCont.GetCont(map[string]interface{}{"`id`": planVersion.Group}, "name") statisCont.GroupName = groupCont.Name //集团名称 statisCont.DepartmentId = strconv.FormatInt(planVersion.Department, 10) //部门ID var departCont modelshr.AdministrativeOrganization departCont.GetCont(map[string]interface{}{"`id`": planVersion.Department}, "name") statisCont.DepartmentName = departCont.Name //部门名称 var evalTargetCont modelskpi.EvaluationTarget //指标信息 if cv.Id != "" && cv.Id != "0" { targetErr := evalTargetCont.GetCont(map[string]interface{}{"`et_id`": cv.Id}, "et_type") if targetErr == nil { monthInt := int64(requestData.Months) if evalTargetCont.Type == 1 { //定性指标 statisCont.Score, statisCont.ExecutiveDepartment = DingXingScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{monthInt}, cv.Id) } else { //定量指标 var sendList []dingLiangKaoHe var dingLiangScore float64 = 0 switch cv.Cycles { case 5: //季度指标 var fengDingZhi float64 = 0 isTrue := true switch monthInt { case 3: for i := 1; i <= 3; i++ { sendListIng, orgNameList := GetDingLiangLog(orgId, requestData.Year, int64(i), cv.Id, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) statisCont.ExecutiveDepartment = append(statisCont.ExecutiveDepartment, orgNameList...) if i == 3 { for _, v := range sendListIng { fengDingZhi = v.Capping if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } case 6: for i := 4; i <= 6; i++ { sendListIng, orgNameList := GetDingLiangLog(orgId, requestData.Year, int64(i), cv.Id, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) statisCont.ExecutiveDepartment = append(statisCont.ExecutiveDepartment, orgNameList...) if i == 6 { for _, v := range sendListIng { fengDingZhi = v.Capping if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } case 9: for i := 7; i <= 9; i++ { sendListIng, orgNameList := GetDingLiangLog(orgId, requestData.Year, int64(i), cv.Id, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) statisCont.ExecutiveDepartment = append(statisCont.ExecutiveDepartment, orgNameList...) if i == 9 { for _, v := range sendListIng { fengDingZhi = v.Capping if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } case 12: for i := 10; i <= 12; i++ { sendListIng, orgNameList := GetDingLiangLog(orgId, requestData.Year, int64(i), cv.Id, fmt.Sprintf("%v月份实际分值", i)) sendList = append(sendList, sendListIng...) statisCont.ExecutiveDepartment = append(statisCont.ExecutiveDepartment, orgNameList...) if i == 12 { for _, v := range sendListIng { fengDingZhi = v.Capping if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } } } default: isTrue = true } if isTrue { targetScore, attribute, _ := GetTargetPlanScore("", cv.Id, orgId, requestData.Year, monthInt) if attribute == 3 { statisCont.Score = targetScore } else { var daChengLv float64 = 0 var pingJunXiShu float64 = 0 for _, j := range sendList { daChengLv = daChengLv + j.CompletionRateAll pingJunXiShu++ } if pingJunXiShu > 0 { pingJunZhi := daChengLv / pingJunXiShu statisCont.Score = publicmethod.DecimalEs(GetQuantifyScore(targetScore, pingJunZhi, fengDingZhi), 2) } else { statisCont.Score = targetScore } } } else { statisCont.Score = dingLiangScore } default: sendList, statisCont.ExecutiveDepartment = GetDingLiangLog(orgId, requestData.Year, monthInt, cv.Id, "") chushu := len(sendList) if chushu > 0 { isTrue := true for _, v := range sendList { dingLiangScore = dingLiangScore + v.Score if v.MtOrAt == 2 { dingLiangScore = v.Score isTrue = false } } if isTrue { dingLiangScore, _ = publicmethod.DecimalNew(dingLiangScore/float64(chushu), 2) statisCont.Score = dingLiangScore } else { statisCont.Score = dingLiangScore } } else { targetScore, _, _ := GetTargetPlanScore("", cv.Id, orgId, requestData.Year, monthInt) statisCont.Score = targetScore } } } } } statisCont.Type = evalTargetCont.Type //1:定性;2:定量 statisCont.Unit = cv.Unit //单位 statisCont.Cycle = cv.Cycles //周期 statisCont.Cycleattr = cv.CycleAttres //辅助参数 lookStatistics = append(lookStatistics, statisCont) // } } } response.Result(0, lookStatistics, "查询完成", c) }