From 4f73a36a6b739252faab27b97ead0bf223b38fe7 Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Wed, 23 Aug 2023 11:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../departmentpc/dingliang.go | 1 + .../departmentpc/programme.go | 16 +- .../departmentpc/rulesmatrix.go | 1 + .../departmentweb/department.go | 20 +- .../departmentseting/departmentweb/web.go | 147 ++ api/version1/entry.go | 2 + .../jurisdiction/jurisdictionpc/people.go | 2 +- api/version1/statistics/newpc.go | 564 ++++++ api/version1/statistics/orgstatistics.go | 140 ++ api/version1/statistics/pc.go | 1591 +++++++++++++++++ api/version1/statistics/pcplant.go | 151 ++ api/version1/statistics/type.go | 229 +++ apirouter/entry.go | 28 +- apirouter/v1/statisticsrouter/pc.go | 41 + apirouter/v1/statisticsrouter/type.go | 14 + config/configDatabase/database.yaml | 22 +- go.mod | 1 + go.sum | 2 + initialization/route/initRoute.go | 3 + models/modelskpi/flow_data_log.go | 1 + overall/publicmethod/formatOutput.go | 2 +- overall/publicmethod/technique.go | 190 +- overall/publicmethod/type.go | 15 + 23 files changed, 3130 insertions(+), 53 deletions(-) create mode 100644 api/version1/departmentseting/departmentweb/web.go create mode 100644 api/version1/statistics/newpc.go create mode 100644 api/version1/statistics/orgstatistics.go create mode 100644 api/version1/statistics/pc.go create mode 100644 api/version1/statistics/pcplant.go create mode 100644 api/version1/statistics/type.go create mode 100644 apirouter/v1/statisticsrouter/pc.go create mode 100644 apirouter/v1/statisticsrouter/type.go diff --git a/api/version1/departmentseting/departmentpc/dingliang.go b/api/version1/departmentseting/departmentpc/dingliang.go index f0ceaeb..8f49b95 100644 --- a/api/version1/departmentseting/departmentpc/dingliang.go +++ b/api/version1/departmentseting/departmentpc/dingliang.go @@ -138,6 +138,7 @@ func (a *ApiMethod) GetQuantitativeTasks(c *gin.Context) { sendCont.UserListAry = append(sendCont.UserListAry, userCont) } } + fmt.Printf("版本号吗!--->%v\n", v.QualEvalId) sendCont.DimensionWeight, sendCont.TargetWeight = getPlanVersionWeghit(v.QualEvalId, strconv.FormatInt(v.Dimension, 10), strconv.FormatInt(v.Target, 10)) //获取目标设定 quanTitWhere := publicmethod.MapOut[string]() diff --git a/api/version1/departmentseting/departmentpc/programme.go b/api/version1/departmentseting/departmentpc/programme.go index 1f675ce..7c57787 100644 --- a/api/version1/departmentseting/departmentpc/programme.go +++ b/api/version1/departmentseting/departmentpc/programme.go @@ -131,14 +131,14 @@ func (a *ApiMethod) EditDepartPrograState(c *gin.Context) { return } //判断是否可执行操作 - if editDepartStateIsTrue(planVersionCont, receivedValue.State) { - msg := "要操作的方案还有未走完的审批流程!请不要进行此操作!" - if receivedValue.State == 1 { - msg = "当前激活的方案中还有未走完的审批流程!请不要进行此操作!" - } - publicmethod.Result(1, receivedValue, c, msg) - return - } + // if editDepartStateIsTrue(planVersionCont, receivedValue.State) { + // msg := "要操作的方案还有未走完的审批流程!请不要进行此操作!" + // if receivedValue.State == 1 { + // msg = "当前激活的方案中还有未走完的审批流程!请不要进行此操作!" + // } + // publicmethod.Result(1, receivedValue, c, msg) + // return + // } //根据操作不同执行相应函数 editState := publicmethod.MapOut[string]() editState["`state`"] = 2 diff --git a/api/version1/departmentseting/departmentpc/rulesmatrix.go b/api/version1/departmentseting/departmentpc/rulesmatrix.go index 7fe8937..1142cc4 100644 --- a/api/version1/departmentseting/departmentpc/rulesmatrix.go +++ b/api/version1/departmentseting/departmentpc/rulesmatrix.go @@ -186,6 +186,7 @@ func (a *ApiMethod) GetTargetDetailsList(c *gin.Context) { publicmethod.Result(107, err, c) return } + // return var listCont []modelskpi.DetailedTarget err = overall.CONSTANT_DB_KPI.Where("`dt_id` IN ?", idList).Order("dt_parentid desc, dt_parentid_sun").Find(&listCont).Error if err != nil || len(listCont) < 1 { diff --git a/api/version1/departmentseting/departmentweb/department.go b/api/version1/departmentseting/departmentweb/department.go index 8760826..ae2578a 100644 --- a/api/version1/departmentseting/departmentweb/department.go +++ b/api/version1/departmentseting/departmentweb/department.go @@ -237,16 +237,16 @@ func (a *ApiMethod) BasisDepartTargetTimeStatistics(c *gin.Context) { var yAxisOne YaxisStruct yAxisOne.Name = "目标值 / 实际值 / 单位" // yAxisOne.Name = fmt.Sprintf("目标值(%v)/实际值(%v)/单位(%v)", targetCont.Uniteing, targetCont.Uniteing, "%") - yAxisOne.Type = "value" //图像类型 - yAxisOne.Min = yMinValLeft //最小值 - yAxisOne.Max = yMaxValLeft //最大值 + yAxisOne.Type = "value" //图像类型 + yAxisOne.Min = publicmethod.DecimalEs(yMinValLeft, 3) //最小值 + yAxisOne.Max = publicmethod.DecimalEs(yMaxValLeft, 3) //最大值 yAxisOne.FormAtter = targetCont.Uniteing sendCont.YAxis = append(sendCont.YAxis, yAxisOne) var yAxisTwo YaxisStruct yAxisTwo.Name = "达成率" - yAxisTwo.Type = "value" //图像类型 - yAxisTwo.Min = yMinValRight //最小值 - yAxisTwo.Max = yMaxValRight //最大值 + yAxisTwo.Type = "value" //图像类型 + yAxisTwo.Min = publicmethod.DecimalEs(yMinValRight, 3) //最小值 + yAxisTwo.Max = publicmethod.DecimalEs(yMaxValRight, 3) //最大值 yAxisTwo.FormAtter = "%" sendCont.YAxis = append(sendCont.YAxis, yAxisTwo) fmt.Printf("%v---------->%v------------->%v------------->%v------------->%v------------->%v------------->%v\n", axisLeftMax, axisLeftMin, axisRightMax, axisRightMin, yAxisOne, yAxisTwo, yMaxValLeft) @@ -720,7 +720,8 @@ func (a *ApiMethod) TotalScoreOFOrgComesFromTimeSearch(c *gin.Context) { // if v.Id == 354 { sendData.XAxisVal = append(sendData.XAxisVal, v.Name) SyncSeting.Add(1) - go syncOrgTimeScore.OrgCalculateScore(v, currentYears, currentMonths) + // go syncOrgTimeScore.OrgCalculateScore(v, currentYears, currentMonths) + go syncOrgTimeScore.TallyUpOrgCalculateScore(v, currentYears, currentMonths) // } } @@ -1156,6 +1157,8 @@ func GetOrgHingeTarget(targetId int64, attribute int, ysers, months string, orgI orgScore := GetAryValue(ov.Id, orgScore) dataList = append(dataList, orgScore) } + maxVal = publicmethod.DecimalEs(maxVal, 2) + minVal = publicmethod.DecimalEs(minVal, 2) fmt.Printf("orgScore------->%v------->%v------->%v\n", orgScore, maxVal, minVal) return } @@ -1595,7 +1598,8 @@ func (g *GeteveryYearDttsb) GetOrgMoreTimeScore(orgCont modelshr.AdministrativeO for i := 1; i <= months; i++ { monthStr := strconv.Itoa(i) SyncSeting.Add(1) - go syncOrgTimeScore.OrgCalculateScore(orgCont, yearsStr, monthStr) + // go syncOrgTimeScore.OrgCalculateScore(orgCont, yearsStr, monthStr) + go syncOrgTimeScore.TallyUpOrgCalculateScore(orgCont, yearsStr, monthStr) } SyncSeting.Wait() scoreList, maxScore, minSchor := syncOrgTimeScore.readPlanTaskData() diff --git a/api/version1/departmentseting/departmentweb/web.go b/api/version1/departmentseting/departmentweb/web.go new file mode 100644 index 0000000..333f501 --- /dev/null +++ b/api/version1/departmentseting/departmentweb/web.go @@ -0,0 +1,147 @@ +package departmentweb + +import ( + "encoding/json" + "key_performance_indicators/api/version1/statistics" + "key_performance_indicators/models/modelshr" + "key_performance_indicators/models/modelskpi" + "key_performance_indicators/overall/publicmethod" + "strconv" + "time" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-29 16:50:53 +@ 功能: 按时间计算行政组织成绩 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (s *SyncOrgTimeAllScore) TallyUpOrgCalculateScore(orgCont modelshr.AdministrativeOrganization, year, month string) { + //锁操作 + s.mutext.Lock() + defer s.mutext.Unlock() + yearInt, _ := strconv.ParseInt(year, 10, 64) + monthInt, _ := strconv.ParseInt(month, 10, 64) + //获取版本信息 + planCont, err := publicmethod.GetPlanVresion(orgCont.Id, yearInt, monthInt) + var getPoints float64 //行政组织总分 + if err == nil { + var planVersioInfo []SchemeInfo + jsonErr := json.Unmarshal([]byte(planCont.Content), &planVersioInfo) + if jsonErr == nil { + for _, v := range planVersioInfo { //维度 + for _, sv := range v.Child { //指标 + if sv.Status == 3 { //为观察指标 + getPoints = getPoints + float64(sv.ReferenceScore) + } else { + var targetInfo modelskpi.EvaluationTarget + targetInfo.GetCont(map[string]interface{}{"et_id": sv.Id}, "et_type,et_cycle") + if sv.Cycles == 0 { //判断统计方式 + sv.Cycles = targetInfo.Cycles + } + if targetInfo.Type == 1 { //定性考核 + dingXingScore, _ := statistics.DingXingScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{monthInt}, sv.Id) + getPoints = getPoints + dingXingScore + } else { //定量考核 + var dingLiangScore float64 + switch sv.Cycles { + case 5: //季度指标 + quarterList := []int64{3, 6, 9, 12} + if !publicmethod.IsInTrue[int64](monthInt, quarterList) { + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("季度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } else { + switch monthInt { + case 3: + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{1, 2, 3}, sv.Id, sv.Cycles) + case 6: + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{4, 5, 6}, sv.Id, sv.Cycles) + case 9: + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{7, 8, 9}, sv.Id, sv.Cycles) + case 12: + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{10, 11, 12}, sv.Id, sv.Cycles) + default: + } + } + case 6: //年度指标 + if monthInt == 12 { + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, sv.Id, sv.Cycles) + } else { + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("年度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } + + case 7: //半年指标 + switch monthInt { + case 6: + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{1, 2, 3, 4, 5, 6}, sv.Id, sv.Cycles) + case 12: + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{7, 8, 9, 10, 11, 12}, sv.Id, sv.Cycles) + default: + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("半年指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } + default: //月度指标 + dingLiangScore, _ = statistics.DingLiangScoreCalculation(orgCont.Id, yearInt, sv.ReferenceScore, []int64{monthInt}, sv.Id, sv.Cycles) + } + dingLiangScoreGd, _ := publicmethod.DecimalNew(dingLiangScore, 2) + getPoints = getPoints + dingLiangScoreGd + } + } + } + } + } + } + tayTime := time.Now().Unix() + currentYears := publicmethod.UnixTimeToDay(tayTime, 16) + currentMonth := publicmethod.UnixTimeToDay(tayTime, 17) + + currentYearsInt, _ := strconv.Atoi(currentYears) + currentMonthInt, _ := strconv.Atoi(currentMonth) + yearsInt, _ := strconv.Atoi(year) + monthsInt, _ := strconv.Atoi(month) + if currentYearsInt == yearsInt && monthsInt > currentMonthInt { + getPoints = 0 + } + if s.AxisMax < getPoints { + s.AxisMax = getPoints + } + if s.AxisMin == 0 { + s.AxisMin = getPoints + } else { + if s.AxisMin > getPoints { + s.AxisMin = getPoints + } + } + + var orgScore SyncOTASVal + orgScore.OrgId = orgCont.Id + orgScore.Score = publicmethod.DecimalEs(getPoints, 2) + orgScore.Months, _ = strconv.Atoi(month) + s.OrgScore = append(s.OrgScore, orgScore) + SyncSeting.Done() +} + +/** +@ 作者: 秦东 +@ 时间: 2023-07-29 17:03:39 +@ 功能: 计算行政组织月份得分 +@ 参数 + # +@ 返回值 + # +@ 方法原型 + # +*/ +// func (){} diff --git a/api/version1/entry.go b/api/version1/entry.go index cc8055b..61c2c02 100644 --- a/api/version1/entry.go +++ b/api/version1/entry.go @@ -10,6 +10,7 @@ import ( "key_performance_indicators/api/version1/jurisdiction/jurisdictionpc" "key_performance_indicators/api/version1/postseting/postpc" "key_performance_indicators/api/version1/postseting/postweb" + "key_performance_indicators/api/version1/statistics" "key_performance_indicators/api/version1/systemapproval" ) @@ -24,6 +25,7 @@ type ApiEntry struct { EmpowerApi empower.ApiMethod //系统授权 WorkFlowChat flowchart.ApiMethod //工作流 SystemAppExamine systemapproval.ApiMethod //系统审批处理 + StatisticsApi statistics.ApiMethod //指标统计 } var AppApiEntry = new(ApiEntry) diff --git a/api/version1/jurisdiction/jurisdictionpc/people.go b/api/version1/jurisdiction/jurisdictionpc/people.go index 16d1ccf..dcc2003 100644 --- a/api/version1/jurisdiction/jurisdictionpc/people.go +++ b/api/version1/jurisdiction/jurisdictionpc/people.go @@ -46,7 +46,7 @@ func (a *ApiMethod) SearchPeople(c *gin.Context) { var listCont []modelshr.PersonArchives gormDb := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Where("`emp_type` BETWEEN ? AND ?", 1, 10) if receivedValue.Name != "" { - gormDb = gormDb.Where("`name` LIKE ?", "%"+receivedValue.Name+"%") + gormDb = gormDb.Where("`name` LIKE ? OR `number` LIKE ?", "%"+receivedValue.Name+"%", "%"+receivedValue.Name+"%") } var total int64 gormDbTotal := gormDb diff --git a/api/version1/statistics/newpc.go b/api/version1/statistics/newpc.go new file mode 100644 index 0000000..d7c9c11 --- /dev/null +++ b/api/version1/statistics/newpc.go @@ -0,0 +1,564 @@ +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 == "43" { + + 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) +} diff --git a/api/version1/statistics/orgstatistics.go b/api/version1/statistics/orgstatistics.go new file mode 100644 index 0000000..a030c76 --- /dev/null +++ b/api/version1/statistics/orgstatistics.go @@ -0,0 +1,140 @@ +package statistics + +import ( + "key_performance_indicators/models/modelshr" + "key_performance_indicators/overall" + "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-17 16:44:24 +@ 功能: 行政组织成绩单(新版) +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) OrgTranscriptNew(c *gin.Context) { + //获取登录人信息 + context, err := publicmethod.LoginMyCont(c) + if err != nil { + publicmethod.Result(1, err, c, "您无权进行此操作!") + return + } + var requestData TranscriptTable + c.ShouldBindJSON(&requestData) + //获取当前访问人的公司组织架构 + var orgList []modelshr.AdministrativeOrganization + gromDb := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`,`sort`").Where("ispower = 1 AND state = 1 AND organization_type > 2") + if requestData.Group != "" { + gromDb = gromDb.Where("superior = ?", requestData.Group) + } else { + gromDb = gromDb.Where("superior = ?", context.Company) + } + if requestData.Department != "" { + gromDb = gromDb.Where("`id` = ?", requestData.Department) + } + err = gromDb.Find(&orgList).Error + if err != nil { + response.Result(102, err, "没有查询到数据", c) + return + } + if len(orgList) <= 0 { + response.Result(103, err, "没有查询到数据", c) + return + } + var orgAry []modelshr.AdministrativeOrganization //行政组织列表 + for _, ov := range orgList { + if ov.Id != 163 && ov.Id != 281 { + sunOrgList, orgSunErr := getSunOrgList(ov.Id, "`id`", "`name`", "`sort`") + if orgSunErr == nil && len(sunOrgList) > 0 { + orgAry = append(orgAry, sunOrgList...) + } else { + orgAry = append(orgAry, ov) + } + } + + } + //计算要查询的年份 + currentYear := publicmethod.ComputingTime(time.Now().Unix(), 1) //当前年 + todayYear := currentYear //今年 + if requestData.Year != "" { + yearInt64, _ := strconv.ParseInt(requestData.Year, 10, 64) + currentYear = yearInt64 + } + //计算月 + var monthTody []int64 + if len(requestData.Month) < 1 { + if currentYear == todayYear { + monthTodyIng := publicmethod.ComputingTime(time.Now().Unix(), 3) + var montInt64 int64 + for montInt64 = 1; montInt64 <= monthTodyIng; montInt64++ { + monthTody = append(monthTody, montInt64) + } + } else { + var montInt64All int64 + for montInt64All = 1; montInt64All <= 12; montInt64All++ { + monthTody = append(monthTody, montInt64All) + } + } + } else { + for _, mmv := range requestData.Month { + monthTody = append(monthTody, int64(mmv)) + } + } + //保证月份不为负数 + if len(monthTody) < 1 { + monthTody = append(monthTody, 1) + } + /* + 设定协程 + 遍历行政组织,并发计算 + */ + var orgTranscript TranscriptTableData + for _, v := range orgAry { + // if v.Id == 362 { + syncProcess.Add(1) + go orgTranscript.StaticticsOrgTimeResult(v, currentYear, monthTody) + // } + } + syncProcess.Wait() +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-08-18 08:16:52 +@ 功能: 计算每个行政组织得分 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (t *TranscriptTableData) EveryOrgCensusResult(orgCont modelshr.AdministrativeOrganization, year int64, month []int64) { + //锁操作 + t.mutext.Lock() + defer t.mutext.Unlock() + + syncProcess.Done() //结束本协程 +} diff --git a/api/version1/statistics/pc.go b/api/version1/statistics/pc.go new file mode 100644 index 0000000..1ec3c45 --- /dev/null +++ b/api/version1/statistics/pc.go @@ -0,0 +1,1591 @@ +package statistics + +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" + "strings" + "time" + + "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 10:44:25 +@ 功能:行政组织成绩单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) OrgTranscript(c *gin.Context) { + //获取登录人信息 + context, err := publicmethod.LoginMyCont(c) + if err != nil { + publicmethod.Result(1, err, c, "您无权进行此操作!") + return + } + var requestData TranscriptTable + c.ShouldBindJSON(&requestData) + //获取当前访问人的公司组织架构 + var orgList []modelshr.AdministrativeOrganization + gromDb := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`,`sort`").Where("ispower = 1 AND state = 1 AND organization_type > 2") + if requestData.Group != "" { + gromDb = gromDb.Where("superior = ?", requestData.Group) + } else { + gromDb = gromDb.Where("superior = ?", context.Company) + } + if requestData.Department != "" { + gromDb = gromDb.Where("`id` = ?", requestData.Department) + } + err = gromDb.Find(&orgList).Error + if err != nil { + response.Result(102, err, "没有查询到数据", c) + return + } + if len(orgList) <= 0 { + response.Result(103, err, "没有查询到数据", c) + return + } + var orgAry []modelshr.AdministrativeOrganization + for _, ov := range orgList { + if ov.Id != 163 && ov.Id != 281 { + sunOrgList, orgSunErr := getSunOrgList(ov.Id, "`id`", "`name`", "`sort`") + if orgSunErr == nil && len(sunOrgList) > 0 { + orgAry = append(orgAry, sunOrgList...) + } else { + orgAry = append(orgAry, ov) + } + } + + } + + // fmt.Printf("orgAry---------------------->%v\n", orgAry) + //计算要查询的年份 + currentYear := publicmethod.ComputingTime(time.Now().Unix(), 1) //当前年 + todayYear := currentYear //今年 + if requestData.Year != "" { + yearInt64, _ := strconv.ParseInt(requestData.Year, 10, 64) + currentYear = yearInt64 + } + //计算月 + var monthTody []int64 + if len(requestData.Month) < 1 { + if currentYear == todayYear { + monthTodyIng := publicmethod.ComputingTime(time.Now().Unix(), 3) + var montInt64 int64 + for montInt64 = 1; montInt64 <= monthTodyIng; montInt64++ { + monthTody = append(monthTody, montInt64) + } + } else { + var montInt64All int64 + for montInt64All = 1; montInt64All <= 12; montInt64All++ { + monthTody = append(monthTody, montInt64All) + } + } + } else { + for _, mmv := range requestData.Month { + monthTody = append(monthTody, int64(mmv)) + } + } + //保证月份不为负数 + if len(monthTody) < 1 { + monthTody = append(monthTody, 1) + } + /* + 设定协程 + 遍历行政组织,并发计算 + */ + var orgTranscript TranscriptTableData + for _, v := range orgAry { + // if v.Id == 362 { + syncProcess.Add(1) + go orgTranscript.StaticticsOrgTimeResult(v, currentYear, monthTody) + // } + } + syncProcess.Wait() + readStatisticsData := orgTranscript.readTranscriptData() //读取通道数据 + // response.Result(0, readStatisticsData, "查询完成", c) + // return + //根据维度序号排序 + sort.Slice(readStatisticsData, func(i, j int) bool { + return readStatisticsData[i].Sort < readStatisticsData[j].Sort + }) + var AScore float64 = 0 + var BScore float64 = 0 + var CScore float64 = 0 + var DScore float64 = 0 + var EScore float64 = 0 + var FScore float64 = 0 + var GScore float64 = 0 + var HScore float64 = 0 + var IScore float64 = 0 + var JScore float64 = 0 + var KScore float64 = 0 + var LScore float64 = 0 + jiBuQi := 0 + var echarsList TranscriptTableDateListChars + + var echarsListOrg TranscriptTableDateListChars + + if len(requestData.Month) > 0 { + var monthAry []int + for i := 1; i <= 12; i++ { + if publicmethod.IsInTrue[int](i, requestData.Month) && !publicmethod.IsInTrue[string](fmt.Sprintf("%v月", i), echarsList.XLine) { + echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", i)) + monthAry = append(monthAry, i) + echarsListOrg.Cylindrical = append(echarsListOrg.Cylindrical, fmt.Sprintf("%v月", i)) + } + } + } else { + echarsList.XLine = append(echarsList.XLine, "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月") + } + var orgFen orgShierTongji + // var dfgfd []YlineData + for _, readv := range readStatisticsData { + AScore = AScore + readv.A + BScore = BScore + readv.B + CScore = CScore + readv.C + DScore = DScore + readv.D + EScore = EScore + readv.E + FScore = FScore + readv.F + GScore = GScore + readv.G + HScore = HScore + readv.H + IScore = IScore + readv.I + JScore = JScore + readv.J + KScore = KScore + readv.K + LScore = LScore + readv.L + jiBuQi++ + echarsList.Cylindrical = append(echarsList.Cylindrical, readv.Department) + echarsListOrg.XLine = append(echarsListOrg.XLine, readv.Department) + + var cyLineAry_1 YlineData + cyLineAry_1.Name = readv.Department + + // var yZhoue YlineData + + if readv.A == -10000 { + readv.A = 0 + } + if readv.B == -10000 { + readv.B = 0 + } + if readv.C == -10000 { + readv.C = 0 + } + if readv.D == -10000 { + readv.D = 0 + } + if readv.E == -10000 { + readv.E = 0 + } + if readv.F == -10000 { + readv.F = 0 + } + if readv.G == -10000 { + readv.G = 0 + } + if readv.H == -10000 { + readv.H = 0 + } + if readv.I == -10000 { + readv.I = 0 + } + if readv.J == -10000 { + readv.J = 0 + } + if readv.K == -10000 { + readv.K = 0 + } + if readv.L == -10000 { + readv.L = 0 + } + if len(requestData.Month) > 0 { + if publicmethod.IsInTrue[int](1, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 1)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.A) + + } + if publicmethod.IsInTrue[int](2, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 2)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.B) + + } + if publicmethod.IsInTrue[int](3, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 3)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.C) + + } + if publicmethod.IsInTrue[int](4, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 4)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.D) + + } + if publicmethod.IsInTrue[int](5, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 5)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.E) + + } + if publicmethod.IsInTrue[int](6, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 6)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.F) + + } + if publicmethod.IsInTrue[int](7, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 7)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.G) + + } + if publicmethod.IsInTrue[int](8, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 8)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.H) + + } + if publicmethod.IsInTrue[int](9, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 9)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.I) + + } + if publicmethod.IsInTrue[int](10, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 10)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.J) + + } + if publicmethod.IsInTrue[int](11, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 11)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.K) + + } + if publicmethod.IsInTrue[int](12, requestData.Month) { + // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 12)) + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.L) + + } + + } else { + cyLineAry_1.Data = append(cyLineAry_1.Data, readv.A, readv.B, readv.C, readv.D, readv.E, readv.F, readv.G, readv.H, readv.I, readv.J, readv.K, readv.L) + // cyLineAry_2.Data = append(cyLineAry_1.Data, readv.A, readv.B, readv.C, readv.D, readv.E, readv.F, readv.G, readv.H, readv.I, readv.J, readv.K, readv.L) + } + orgFen.A = append(orgFen.A, readv.A) + orgFen.B = append(orgFen.B, readv.B) + orgFen.C = append(orgFen.C, readv.C) + orgFen.D = append(orgFen.D, readv.D) + orgFen.E = append(orgFen.E, readv.E) + orgFen.F = append(orgFen.F, readv.F) + orgFen.G = append(orgFen.G, readv.G) + orgFen.H = append(orgFen.H, readv.H) + orgFen.I = append(orgFen.I, readv.I) + orgFen.J = append(orgFen.J, readv.J) + orgFen.K = append(orgFen.K, readv.K) + orgFen.L = append(orgFen.L, readv.L) + // jsonStr, _ := json.Marshal(orgFen.A) + // fmt.Printf("orgFen------1---->%v\n", string(jsonStr)) + echarsList.YLine = append(echarsList.YLine, cyLineAry_1) + // echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + + } + // jsonStrwww, _ := json.Marshal(orgFen) + // fmt.Printf("orgFen---------->%v\n", string(jsonStrwww)) + if jiBuQi > 0 { + var pingJunFen TranscriptTableDateList + pingJunFen.DepartmentId = "0" + pingJunFen.Department = "平均分" + pingJunFen.A = publicmethod.DecimalEs(AScore/float64(jiBuQi), 2) + pingJunFen.B = publicmethod.DecimalEs(BScore/float64(jiBuQi), 2) + pingJunFen.C = publicmethod.DecimalEs(CScore/float64(jiBuQi), 2) + pingJunFen.D = publicmethod.DecimalEs(DScore/float64(jiBuQi), 2) + pingJunFen.E = publicmethod.DecimalEs(EScore/float64(jiBuQi), 2) + pingJunFen.F = publicmethod.DecimalEs(FScore/float64(jiBuQi), 2) + pingJunFen.G = publicmethod.DecimalEs(GScore/float64(jiBuQi), 2) + pingJunFen.H = publicmethod.DecimalEs(HScore/float64(jiBuQi), 2) + pingJunFen.I = publicmethod.DecimalEs(IScore/float64(jiBuQi), 2) + pingJunFen.J = publicmethod.DecimalEs(JScore/float64(jiBuQi), 2) + pingJunFen.K = publicmethod.DecimalEs(KScore/float64(jiBuQi), 2) + pingJunFen.L = publicmethod.DecimalEs(LScore/float64(jiBuQi), 2) + + readStatisticsData = append(readStatisticsData, pingJunFen) + } + var monthInt []int + if len(requestData.Month) <= 0 { + for dkj := 1; dkj <= 12; dkj++ { + monthInt = append(monthInt, dkj) + } + } else { + monthInt = requestData.Month + } + // fmt.Printf("monthInt---------->%v\n", monthInt) + + for _, mvv := range monthInt { + switch mvv { + case 1: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "1月" + cyLineAry_2.Data = orgFen.A + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 2: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "2月" + cyLineAry_2.Data = orgFen.B + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 3: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "3月" + cyLineAry_2.Data = orgFen.C + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 4: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "4月" + cyLineAry_2.Data = orgFen.D + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 5: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "5月" + cyLineAry_2.Data = orgFen.E + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 6: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "6月" + cyLineAry_2.Data = orgFen.F + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 7: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "7月" + cyLineAry_2.Data = orgFen.G + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 8: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "8月" + cyLineAry_2.Data = orgFen.H + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 9: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "9月" + cyLineAry_2.Data = orgFen.I + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 10: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "10月" + cyLineAry_2.Data = orgFen.J + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 11: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "11月" + cyLineAry_2.Data = orgFen.K + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + case 12: + var cyLineAry_2 YlineData + cyLineAry_2.Name = "12月" + cyLineAry_2.Data = orgFen.L + echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) + } + } + + outData := publicmethod.MapOut[string]() + outData["readStatisticsData"] = readStatisticsData + outData["echarsList"] = echarsList + outData["echarsListOrg"] = echarsListOrg + + response.Result(0, outData, "查询完成", c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 11:14:37 +@ 功能: 时间维度统计个行政组织成绩 +@ 参数 + + #orgCont 行政组织相关信息 + #year 查询的年份 + #month 查询月份边界 + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (t *TranscriptTableData) StaticticsOrgTimeResult(orgCont modelshr.AdministrativeOrganization, year int64, month []int64) { + //锁操作 + t.mutext.Lock() + defer t.mutext.Unlock() + var pingJunFen TranscriptTableDateList + pingJunFen.DepartmentId = strconv.FormatInt(orgCont.Id, 10) + pingJunFen.Department = orgCont.Name + pingJunFen.Sort = orgCont.Sort + + var everyMonthScore countEveryDepartmentMonthScore + for _, v := range month { + // if v == 1 { + planCont, err := publicmethod.GetPlanVresion(orgCont.Id, year, v) + fmt.Printf("planCont:%v\n%v\n", planCont, err) + if err == nil { + var planVersioInfo []AddDutyNewCont + jsonErr := json.Unmarshal([]byte(planCont.Content), &planVersioInfo) + if jsonErr == nil { + syncProcessDepartTarget.Add(1) + //按月份计算 + go everyMonthScore.everyMonthCalculateNew(orgCont.Id, year, v, planVersioInfo) + } + } + // } + + } + syncProcessDepartTarget.Wait() + everyMonthScoreList := everyMonthScore.readMyDayData() + // fmt.Printf("everyMonthScoreList-->%v\n", everyMonthScoreList) + for _, emslv := range everyMonthScoreList { + switch emslv.MonthVal { + case 1: + pingJunFen.A = emslv.Score + case 2: + pingJunFen.B = emslv.Score + case 3: + pingJunFen.C = emslv.Score + case 4: + pingJunFen.D = emslv.Score + case 5: + pingJunFen.E = emslv.Score + case 6: + pingJunFen.F = emslv.Score + case 7: + pingJunFen.G = emslv.Score + case 8: + pingJunFen.H = emslv.Score + case 9: + pingJunFen.I = emslv.Score + case 10: + pingJunFen.J = emslv.Score + case 11: + pingJunFen.K = emslv.Score + case 12: + pingJunFen.L = emslv.Score + default: + } + + } + var monthIsFalse int64 + for monthIsFalse = 1; monthIsFalse <= 12; monthIsFalse++ { + if !publicmethod.IsInTrue[int64](monthIsFalse, month) { + switch monthIsFalse { + case 1: + pingJunFen.A = -10000 + case 2: + pingJunFen.B = -10000 + case 3: + pingJunFen.C = -10000 + case 4: + pingJunFen.D = -10000 + case 5: + pingJunFen.E = -10000 + case 6: + pingJunFen.F = -10000 + case 7: + pingJunFen.G = -10000 + case 8: + pingJunFen.H = -10000 + case 9: + pingJunFen.I = -10000 + case 10: + pingJunFen.J = -10000 + case 11: + pingJunFen.K = -10000 + case 12: + pingJunFen.L = -10000 + default: + } + } + + } + t.ScoreStatistics = append(t.ScoreStatistics, pingJunFen) + // fmt.Printf("everyMonthScoreList-->%v\n", pingJunFen) + syncProcess.Done() //结束本协程 +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 14:20:46 +@ 功能: 按月份统计行政组织总成绩 +@ 参数 + + #orgId 行政组织ID + #year 年 + #month 月 + #planVersion 部门当前执行的考核版本 + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (c *countEveryDepartmentMonthScore) everyMonthCalculateNew(orgId, year, month int64, planVersion []AddDutyNewCont) { + //锁操作 + c.mutext.Lock() + defer c.mutext.Unlock() + var weiDuScore float64 = 0 //维度分值 + var zhiBiaoScore float64 = 0 //指标标准分值 + var sumScore float64 = 0 //计算得分 + for _, v := range planVersion { //维度 + weiDuScore = weiDuScore + float64(v.ZhiFraction) + for _, sv := range v.Child { //指标 + zhiBiaoScore = zhiBiaoScore + float64(sv.ReferenceScore) + if sv.Status == 3 { //为观察指标 + sumScore = sumScore + float64(sv.ReferenceScore) + fmt.Printf("为观察指标--->%v--->%v--->%v\n", sv.Name, sv.Id, sv.ReferenceScore) + } else { + var targetInfo modelskpi.EvaluationTarget + targetInfo.GetCont(map[string]interface{}{"et_id": sv.Id}, "et_type,et_cycle") + if targetInfo.Type == 1 { + //定性考核 + dingXingScore, _ := DingXingScoreCalculation(orgId, year, sv.ReferenceScore, []int64{month}, sv.Id) + sumScore = sumScore + dingXingScore + fmt.Printf("定性考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingXingScore, sumScore) + } else { + + var dingLiangScore float64 + switch sv.Cycles { + case 5: //季度 + quarterList := []int64{3, 6, 9, 12} + if !publicmethod.IsInTrue[int64](month, quarterList) { + dingLiangScore = float64(sv.ReferenceScore) + fmt.Printf("季度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } else { + switch month { + case 3: + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 1; i <= 3; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 3 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + case 6: + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 4; i <= 6; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 6 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + case 9: + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 7; i <= 9; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 9 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + case 12: + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 10; i <= 12; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 12 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + default: + } + } + case 6: //年度 + if month == 12 { + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 1; i <= 12; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 12 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + } else { + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("年度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } + case 7: //半年指标 + switch month { + + case 6: //上半年 + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 1; i <= 6; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 6 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + case 12: + var sendList []dingLiangKaoHe + isTrue := true + var dingLiangScoreGd float64 = 0 + var fengDingZhi float64 = 0 + for i := 7; i <= 12; i++ { + sendListIng, _ := GetDingLiangLog(orgId, year, int64(i), sv.Id, "") + sendList = append(sendList, sendListIng...) + if i == 12 { + for _, v := range sendListIng { + fengDingZhi = v.Capping + if v.MtOrAt == 2 { + dingLiangScoreGd = v.Score + isTrue = false + } + } + } + } + if !isTrue { + dingLiangScore = dingLiangScoreGd + } else { + var daChengLv float64 = 0 + var pingJunXiShu float64 = 0 + for _, j := range sendList { + daChengLv = daChengLv + j.CompletionRateAll + pingJunXiShu++ + } + if pingJunXiShu > 0 { + pingJunZhi := daChengLv / pingJunXiShu + dingLiangScore = publicmethod.DecimalEs(GetQuantifyScore(float64(sv.ReferenceScore), pingJunZhi, fengDingZhi), 2) + } else { + dingLiangScore = float64(sv.ReferenceScore) + } + } + default: + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("半年指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } + default: //月度指标 + sendList, _ := GetDingLiangLog(orgId, year, month, sv.Id, "") + if len(sendList) < 1 { + dingLiangScore = float64(sv.ReferenceScore) + } else { + for _, v := range sendList { + // if v.MtOrAt == 1 { + // } + dingLiangScore = dingLiangScore + v.Score + } + // sumScore = sumScore + dingLiangScore + } + + } + dingLiangScoreGd, _ := publicmethod.DecimalNew(dingLiangScore, 2) + sumScore = sumScore + dingLiangScoreGd + fmt.Printf("定量月度考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore, sumScore) + } + } + + } + } + var everyMonthScoreInfo everyDepartmentScore + everyMonthScoreInfo.MonthVal = month + + everyMonthScoreInfo.Score, _ = publicmethod.DecimalNew(sumScore, 2) + + c.outData = append(c.outData, everyMonthScoreInfo) + syncProcessDepartTarget.Done() //结束本协程 +} +func (c *countEveryDepartmentMonthScore) everyMonthCalculate(orgId, year, month int64, planVersion []AddDutyNewCont) { + //锁操作 + c.mutext.Lock() + defer c.mutext.Unlock() + var weiDuScore float64 = 0 //维度分值 + var zhiBiaoScore float64 = 0 //指标标准分值 + var sumScore float64 = 0 //计算得分 + for _, v := range planVersion { //维度 + weiDuScore = weiDuScore + float64(v.ZhiFraction) + for _, sv := range v.Child { //指标 + // if sv.Id == "13" { + + zhiBiaoScore = zhiBiaoScore + float64(sv.ReferenceScore) + if sv.Status == 3 { //为观察指标 + sumScore = sumScore + float64(sv.ReferenceScore) + // fmt.Printf("为观察指标--->%v--->%v--->%v\n", sv.Name, sv.Id, sv.ReferenceScore) + } else { + var targetInfo modelskpi.EvaluationTarget + targetInfo.GetCont(map[string]interface{}{"et_id": sv.Id}, "et_type,et_cycle") + if sv.Cycles == 0 { //判断统计方式 + sv.Cycles = targetInfo.Cycles + } + if targetInfo.Type == 1 { + //定性考核 + dingXingScore, _ := DingXingScoreCalculation(orgId, year, sv.ReferenceScore, []int64{month}, sv.Id) + sumScore = sumScore + dingXingScore + // fmt.Printf("定性考核得分--->%v--->%v--->%v\n", sv.Name, sv.Id, dingXingScore) + } else { + var dingLiangScore float64 + //定量考核 + switch sv.Cycles { + case 5: //季度指标 + quarterList := []int64{3, 6, 9, 12} + if !publicmethod.IsInTrue[int64](month, quarterList) { + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("季度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } else { + switch month { + case 3: + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{1, 2, 3}, sv.Id, sv.Cycles) + case 6: + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{4, 5, 6}, sv.Id, sv.Cycles) + case 9: + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{7, 8, 9}, sv.Id, sv.Cycles) + case 12: + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{10, 11, 12}, sv.Id, sv.Cycles) + default: + } + } + case 6: //年度指标 + if month == 12 { + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, sv.Id, sv.Cycles) + } else { + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("年度指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } + + case 7: //半年指标 + switch month { + case 6: + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{1, 2, 3, 4, 5, 6}, sv.Id, sv.Cycles) + case 12: + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{7, 8, 9, 10, 11, 12}, sv.Id, sv.Cycles) + default: + dingLiangScore = float64(sv.ReferenceScore) + // fmt.Printf("半年指标--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore) + } + default: //月度指标 + dingLiangScore, _ = DingLiangScoreCalculation(orgId, year, sv.ReferenceScore, []int64{month}, sv.Id, sv.Cycles) + } + dingLiangScoreGd, _ := publicmethod.DecimalNew(dingLiangScore, 2) + sumScore = sumScore + dingLiangScoreGd + // fmt.Printf("定量考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScoreGd, sv.Cycles) + } + + } + // } + } + } + var everyMonthScoreInfo everyDepartmentScore + everyMonthScoreInfo.MonthVal = month + + everyMonthScoreInfo.Score, _ = publicmethod.DecimalNew(sumScore, 2) + c.outData = append(c.outData, everyMonthScoreInfo) + syncProcessDepartTarget.Done() //结束本协程 +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 10:58:16 +@ 功能: 获取下级行政组织是否有主行政部门 +@ 参数 + + #orgId 行政组织上级ID + +@ 返回值 + + #orgList 行政组织子集列表 + +@ 方法原型 + + # +*/ +func getSunOrgList(orgId int64, field ...string) (orgList []modelshr.AdministrativeOrganization, ovErr error) { + gormDb := overall.CONSTANT_DB_HR.Where("state = 1") + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + ovErr = gormDb.Where("ispower = 1 AND superior = ?", orgId).Find(&orgList).Error + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 14:46:27 +@ 功能: 指定时间段定性考核计算 +@ 参数 + + #orgId 行政组织 + #years 年 + #targetScore 指标分值 + #months 月份 + #targetId 指标 + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func DingXingScoreCalculation(orgId, years, targetScore int64, months []int64, targetId string) (score float64, EvalDepartment []string) { + var scoreFlowList []modelskpi.ScoreFlow + err := overall.CONSTANT_DB_KPI.Model(&modelskpi.ScoreFlow{}).Select("`sf_plus_reduce_score`,`sf_score`,`sf_count`").Where("sf_reply IN ? AND sf_duty_department = ? AND sf_target_id = ? AND sf_year = ? AND sf_month IN ?", []int{2, 3}, orgId, targetId, years, months).Find(&scoreFlowList).Error + if err != nil || len(scoreFlowList) < 1 { + return float64(targetScore), []string{} + } + var minusPoints float64 = 0 //获取减分 + var extraPoints float64 = 0 //获取加分 + for _, v := range scoreFlowList { + quzhi := v.Score * int64(v.Count) + if v.PlusReduceScore == 1 { + extraPoints = extraPoints + float64(quzhi) + } else { + minusPoints = minusPoints + float64(quzhi) + } + + var minusDepartment modelshr.AdministrativeOrganization + minErr := minusDepartment.GetCont(map[string]interface{}{"id": v.EvaluationDepartment}, "name") + if minErr == nil { + if !publicmethod.IsInTrue[string](minusDepartment.Name, EvalDepartment) { + EvalDepartment = append(EvalDepartment, minusDepartment.Name) + } + } + } + score = publicmethod.DecimalEs(((float64(targetScore) + extraPoints/100) - minusPoints/100), 2) + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 15:39:59 +@ 功能: 指定时间段定量考核计算 +@ 参数 + + #orgId 行政组织 + #years 年 + #targetScore 指标分数 + #months 月份 + #targetId 指标Id + #cycles 1:班;2:天;3:周;4:月;5:季度;6:年;7:半年 + +@ 返回值 + + #score 得分 + +@ 方法原型 + + #func DingLiangScoreCalculation(orgId, years, targetScore int64, months []int64, targetId string, cycles int) (score float64) +*/ +func DingLiangScoreCalculation(orgId, years, targetScore int64, months []int64, targetId string, cycles int) (score float64, EvalDepartment []string) { + var calculateScore float64 = 0 + var passRate float64 = 0 //达成率 + var cappingPrize float64 = 1 //达成率 + for _, vs := range months { + var flowLogList []modelskpi.FlowDataLogType + err := overall.CONSTANT_DB_KPI.Where("`department` = ? AND `year` = ? AND `targetid` = ? AND `month` = ? AND fl_reply IN ?", orgId, years, targetId, vs, []int{2, 3}).Find(&flowLogList).Error + if err != nil || len(flowLogList) < 1 { + calculateScore = calculateScore + float64(targetScore) + fmt.Printf("指标分--abc->%v--->%v\n", vs, targetScore) + passRate = passRate + 1 + } else { + var sumScore float64 = 0 + //循环计算相关指标得分 + for _, v := range flowLogList { + if v.ScoringMethod == 1 { + //自动计算 + sumScoreing, passRateVal, _, _, cappingPrizeval := AnalysisReward(targetId, v.Baseline, v.Edition, float64(targetScore), float64(v.Score), orgId, v.Year, v.Quarter, v.Month, cycles) + fmt.Printf("自动计算--->%v--->%v--->%v--->%v\n", vs, sumScoreing, passRateVal, cappingPrizeval) + sumScore = sumScore + sumScoreing + passRate = passRate + passRateVal + cappingPrize = cappingPrizeval + } else { + //手动分 + sumScore = sumScore + (float64(v.ScoringScore) / 100) + passRate = passRate + 1 + // fmt.Printf("手动分值--->%v\n", (float64(v.ScoringScore) / 100)) + } + var minusDepartment modelshr.AdministrativeOrganization + minErr := minusDepartment.GetCont(map[string]interface{}{"id": v.EvaluationDepartment}, "name") + if minErr == nil { + if !publicmethod.IsInTrue[string](minusDepartment.Name, EvalDepartment) { + EvalDepartment = append(EvalDepartment, minusDepartment.Name) + } + } + } + calculateScore = calculateScore + sumScore + } + } + chushu := len(months) + if chushu != 0 { + calculateScore = publicmethod.DecimalEs(calculateScore/float64(chushu), 2) + + daChengLv := passRate / float64(chushu) + if daChengLv >= cappingPrize && cappingPrize != 0 { + calculateScore = publicmethod.DecimalEs(cappingPrize*float64(targetScore), 2) + } else { + calculateScore = publicmethod.DecimalEs(daChengLv*float64(targetScore), 2) + } + fmt.Printf("passRate:%v\nchushu:%v\ndaChengLv:%v\ncappingPrize:%v\ncalculateScore:%v\n", passRate, chushu, daChengLv, cappingPrize, calculateScore) + } + + score = calculateScore + return +} + +func DingLiangScoreCalculationOld(orgId, years, targetScore int64, months []int64, targetId string, cycles int) (score float64) { + var flowLogList []modelskpi.FlowDataLogType + err := overall.CONSTANT_DB_KPI.Where("`department` = ? AND `year` = ? AND `targetid` = ? AND `month` IN ? AND fl_reply IN ?", orgId, years, targetId, months, []int{2, 3}).Find(&flowLogList).Error + // fmt.Printf("targetId====>%v====>%v====>%v====>%v\n", targetId, err, flowLogList, len(flowLogList)) + if err != nil || len(flowLogList) < 1 { + score = float64(targetScore) + return + } + var sumScore float64 = 0 + //循环计算相关指标得分 + for _, v := range flowLogList { + if v.ScoringMethod == 1 { + //自动计算 + sumScoreing, _, _, _, _ := AnalysisReward(targetId, v.Baseline, v.Edition, float64(targetScore), float64(v.Score), orgId, v.Year, v.Quarter, v.Month, cycles) + sumScore = sumScore + sumScoreing + } else { + //手动分 + sumScore = sumScore + (float64(v.ScoringScore) / 100) + // fmt.Printf("手动分值--->%v\n", (float64(v.ScoringScore) / 100)) + } + } + if years > 2023 { + chushu := len(months) + if chushu != 0 { + sumScore = publicmethod.DecimalEs(sumScore/float64(chushu), 2) + } + } else { + pingjun := false + for _, v := range months { + if v > 6 && years == 2023 { + pingjun = true + } + } + if pingjun { + chushu := len(months) + if chushu != 0 { + sumScore = publicmethod.DecimalEs(sumScore/float64(chushu), 2) + } + } + } + + score = sumScore + // fmt.Printf("手动分值--2->%v\n", score) + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 15:59:23 +@ 功能: 计算单一定量指标得分 +@ 参数 + + #targetId 指标 + #rewardCont 上报时的全奖值,零奖值,封顶值设置 + #targetScore 指标得分 + #settlementScore 上报数值 + #planKey 指标方案 + #orgId 行政组织 + #years 发生年 + #quarter 发生季 + #month 发生月 + #cycles 1:班;2:天;3:周;4:月;5:季度;6:年;7:半年 + +@ 返回值 + + #score 得分 + #completionRate 达成率 + +@ 方法原型 + + #score 指标得分 + #completionRate 达成率 + #zeroPrize 零奖值 + #allPrize 全奖值 + #cappingPrize 封顶值 +*/ +func AnalysisReward(targetId, rewardCont, planKey string, targetScore, settlementScore float64, orgId, years, quarter, month int64, cycles int) (score, completionRate, zeroPrize, allPrize, cappingPrize float64) { + var currentTargetSeting FlowLogAllZreo + setIsTrue := true + var rewardAry []FlowLogAllZreo + jsonErr := json.Unmarshal([]byte(rewardCont), &rewardAry) + if jsonErr == nil { + //获取当前指标的全奖零奖值 + for _, v := range rewardAry { + if v.TargetId == targetId { + currentTargetSeting.Id = v.Id + currentTargetSeting.TargetId = v.TargetId //指标ID` + currentTargetSeting.Zeroprize = v.Zeroprize //零奖值"` + currentTargetSeting.Allprize = v.Allprize //全奖值"` + currentTargetSeting.Capping = v.Capping //封顶值"` + + zeroPrize = v.Zeroprize //零奖值"` + allPrize = v.Allprize //全奖值"` + cappingPrize = v.Capping //封顶值"` + + setIsTrue = false + } + } + } + isAll := false + if setIsTrue { + var setCont modelskpi.QuantitativeConfig + gormdb := overall.CONSTANT_DB_KPI.Where("`departmentid` = ? AND `target` = ? AND `year` = ?", orgId, targetId, years) + switch cycles { + case 5: //季度 + gormdb = gormdb.Where("`timecopy` = ?", quarter) + case 6: //年 + case 7: //半年 + banNian := 1 + if !publicmethod.IsInTrue[int64](month, []int64{1, 2, 3, 4, 5, 6}) { + banNian = 2 + } + gormdb = gormdb.Where("`timecopy` = ?", banNian) + default: + gormdb = gormdb.Where("`timecopy` = ?", month) + } + err := gormdb.Find(setCont).Error + if err == nil { + currentTargetSeting.Id = strconv.FormatInt(setCont.Id, 10) + currentTargetSeting.TargetId = strconv.FormatInt(setCont.Target, 10) //指标ID` + currentTargetSeting.Zeroprize = setCont.Zeroprize //零奖值"` + currentTargetSeting.Allprize = setCont.Allprize //全奖值"` + currentTargetSeting.Capping = setCont.CappingVal //封顶值"` + + zeroPrize = setCont.Zeroprize //零奖值"` + allPrize = setCont.Allprize //全奖值"` + cappingPrize = setCont.CappingVal //封顶值"` + isAll = true + } else { + isAll = false + } + } else { + isAll = true + } + if isAll { + + score, completionRate = TallyUpScore(targetScore, settlementScore, currentTargetSeting.Zeroprize, currentTargetSeting.Allprize, currentTargetSeting.Capping) + fmt.Printf("计算单一定量指标得分--->%v\n--->%v\n--->%v\n", settlementScore, score, completionRate) + } else { + completionRate = 1 + score = targetScore + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-28 10:23:33 +@ 功能: 计算定量指标得分 +@ 参数 + + #targetScore 指标分值 + #actualValue 指标实际值 + #zeroPrize 零奖值 + #allPrize 全奖值 + #cappingVal 封顶值 + +@ 返回值 + + #callBackScore 得分 + #completionRate 达成率 + +@ 方法原型 + + #func TallyUpScore(targetScore, actualValue, zeroPrize, allPrize, cappingVal float64) (callBackScore, completionRate float64) +*/ +func TallyUpScore(targetScore, actualValue, zeroPrize, allPrize, cappingVal float64) (callBackScore, completionRate float64) { + + // fmt.Printf("计算定量指标得分--->actualValue:%v\nzeroPrize:%v\nallPrize:%v\n", actualValue, zeroPrize, allPrize) + if zeroPrize == 0 && allPrize == 0 { //全奖值与零奖值都为0 那么达成率 100 和实际得分是 指标分 + completionRate = 1 + callBackScore = targetScore + } else { + if allPrize >= zeroPrize { //如果全奖值大于零奖值 执行正向操作 + //stpe 1:判断提交实际数值是否小于等于零奖值 + if actualValue <= zeroPrize { //满足此条件,那么达成率和实际得分都是0 + completionRate = 0 + callBackScore = 0 + } else { //stpe 2:判断提交实际结算值大于零奖值 + chuShu := actualValue - float64(zeroPrize) //除数 = 实际值 - 零奖值 + beiChuShu := float64(allPrize) - float64(zeroPrize) // 被除数 = 全奖值 - 零奖值 + if beiChuShu != 0 { //stpe 3:判断被除数非零 + completionRate = chuShu / beiChuShu //达成率 + if completionRate <= 0 { //stpe 4:判断达成率小于等于零时。那么达成率和实际得分都是0 + completionRate = 0 + callBackScore = 0 + } else { + //stpe 5:判断达成率是否等于大于封顶值 + // fmt.Printf("判断达成率----->%v----->%v\n", completionRate*100, cappingVal) + if completionRate*100 >= cappingVal/100 { + if cappingVal > 0 { //stpe 6:判断封顶值是否大于0 + callBackScore = (cappingVal / 10000) * targetScore + // fmt.Printf("判断达成率---1-->%v----->%v\n", callBackScore, targetScore) + } else { + callBackScore = targetScore + // fmt.Printf("判断达成率-2--->%v----->%v\n", callBackScore, targetScore) + } + } else { //stpe 6:当达成率小于封顶值 + callBackScore = completionRate * targetScore + // fmt.Printf("判断达成率--3--->%v----->%v\n", completionRate, targetScore) + } + } + } else { //被除数为零时,等式不成立。所以达成率和实际得分都是0 + completionRate = 0 + callBackScore = 0 + } + } + } else { //如果全奖值小于于零奖值 执行反向操作 + // fmt.Printf("全奖值小于零奖值--->zeroPrize:%v,allPrize:%v\n", zeroPrize, allPrize) + if (actualValue >= zeroPrize) || (actualValue == 0 && (zeroPrize != 0 || actualValue != 0)) { //如果实际数值大于等于零奖值,那么达成率和实际得分都是0 + chuShu := actualValue - float64(zeroPrize) //除数 = 实际值 - 零奖值 + beiChuShu := float64(allPrize) - float64(zeroPrize) // 被除数 = 全奖值 - 零奖值 + if beiChuShu != 0 { + completionRate = chuShu / beiChuShu //达成率 + } else { + completionRate = 0 + } + callBackScore = 0 + } else { //实际值小于零奖值 + chuShu := actualValue - float64(zeroPrize) //除数 = 实际值 - 零奖值 + beiChuShu := float64(allPrize) - float64(zeroPrize) // 被除数 = 全奖值 - 零奖值 + + // fmt.Printf("全奖值被除数--->%v\n", beiChuShu) + if beiChuShu != 0 { //判断被除数非零 + completionRate = chuShu / beiChuShu //达成率 + if completionRate <= 0 { //判断达成率小于等于零时。那么达成率和实际得分都是0 + completionRate = 0 + callBackScore = 0 + } else { + + //stpe 5:判断达成率是否等于大于封顶值 + if completionRate*100 >= cappingVal/100 { + if cappingVal > 0 { //stpe 6:判断封顶值是否大于0 + callBackScore = (cappingVal / 10000) * targetScore + } else { + callBackScore = targetScore + } + } else { //stpe 6:当达成率小于封顶值 + callBackScore = completionRate * targetScore + } + // fmt.Printf("全奖值小于零奖值--->completionRate:%v,cappingVal:%v,completionRate:%v,targetScore:%v,callBackScore:%v\n", completionRate*100, cappingVal/100, completionRate, targetScore, callBackScore) + } + } else { //被除数为零时,等式不成立。所以达成率和实际得分都是0 + completionRate = 0 + callBackScore = 0 + } + } + } + } + // callBackScore = publicmethod.DecimalEs(callBackScore, 2) + // completionRate = publicmethod.DecimalEs(completionRate, 4) + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-29 09:43:05 +@ 功能:汇总详情定量历史记录 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) 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(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) + var targetInfo modelskpi.EvaluationTarget + targetInfo.GetCont(map[string]interface{}{"et_id": requestData.TargetId}, "et_type,et_cycle") + var sendList []dingLiangKaoHe + switch targetInfo.Cycles { + case 5: //季度指标 + if publicmethod.IsInTrue[int64](monthInt, []int64{3, 6, 9, 12}) { + if publicmethod.IsInTrue[int64](monthInt, []int64{1, 2, 3}) { + for i := 1; i <= 3; i++ { + sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) + sendList = append(sendList, sendListIng...) + } + } else if publicmethod.IsInTrue[int64](monthInt, []int64{4, 5, 6}) { + for i := 4; i <= 6; i++ { + sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) + sendList = append(sendList, sendListIng...) + } + } else if publicmethod.IsInTrue[int64](monthInt, []int64{7, 8, 9}) { + for i := 7; i <= 9; i++ { + sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) + sendList = append(sendList, sendListIng...) + } + } else { + for i := 10; i <= 12; i++ { + sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) + sendList = append(sendList, sendListIng...) + } + } + chushu := len(sendList) + if chushu > 0 { + var sumScore float64 = 0 + for _, j := range sendList { + sumScore = sumScore + j.Score + } + var secondCont dingLiangKaoHe + secondCont.Score = publicmethod.DecimalEs(sumScore/float64(chushu), 2) //得分 + secondCont.MtOrAt = 1 //手动还是自动 + secondCont.Cont = "平均分" //说明 + sendList = append(sendList, secondCont) + } + + } else { + sendList, _ = GetDingLiangLog(orgId, requestData.Year, monthInt, requestData.TargetId, "") + } + + case 6: //年度指标 + for i := 1; i <= 12; i++ { + sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) + sendList = append(sendList, sendListIng...) + } + var sumScore float64 = 0 + for _, j := range sendList { + sumScore = sumScore + j.Score + } + var secondCont dingLiangKaoHe + secondCont.Score = publicmethod.DecimalEs(sumScore/12, 2) //得分 + secondCont.MtOrAt = 1 //手动还是自动 + secondCont.Cont = "平均分" //说明 + sendList = append(sendList, secondCont) + case 7: //半年指标 + 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...) + } + } else { + for i := 7; i <= 12; i++ { + sendListIng, _ := GetDingLiangLog(orgId, requestData.Year, int64(i), requestData.TargetId, fmt.Sprintf("%v月份实际分值", i)) + sendList = append(sendList, sendListIng...) + } + } + var sumScore float64 = 0 + for _, j := range sendList { + sumScore = sumScore + j.Score + } + var secondCont dingLiangKaoHe + secondCont.Score = publicmethod.DecimalEs(sumScore/6, 2) //得分 + secondCont.MtOrAt = 1 //手动还是自动 + secondCont.Cont = "平均分" //说明 + secondCont.Nature = 1 + sendList = append(sendList, secondCont) + default: + sendList, _ = GetDingLiangLog(orgId, requestData.Year, monthInt, requestData.TargetId, "") + } + response.Result(0, sendList, "查询完成!", c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-29 10:44:18 +@ 功能: 获取定量考核记录 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func GetDingLiangLog(orgId, years, monthes int64, targetId, cont string) (sendList []dingLiangKaoHe, EvalDepartment []string) { + var flowLogList []modelskpi.FlowDataLogType + err := overall.CONSTANT_DB_KPI.Where("`department` = ? AND `year` = ? AND `targetid` = ? AND `month` = ? AND fl_reply IN ?", orgId, years, targetId, monthes, []int{2, 3}).Find(&flowLogList).Error + if err != nil && len(flowLogList) < 1 { + return + } else { + for _, v := range flowLogList { + + var secondCont dingLiangKaoHe + targetScore, attribute, _ := GetTargetPlanScore(v.Edition, targetId, orgId, years, monthes) + secondCont.Score, secondCont.CompletionRate, secondCont.Zeroprize, secondCont.Allprize, secondCont.Capping = AnalysisReward(targetId, v.Baseline, v.Edition, targetScore, float64(v.Score), orgId, v.Year, v.Quarter, v.Month, attribute) + secondCont.Actual = publicmethod.DecimalEs(float64(v.Score)/100, 2) + + fmt.Printf("获取定量考核记录--->targetScore:%v\n--->attribute:%v\n--->Score:%v\n--->ScoringMethod:%v\n", targetScore, attribute, secondCont.Score, v.ScoringMethod) + if v.ScoringMethod != 1 { + secondCont.Score = publicmethod.DecimalEs(float64(v.ScoringScore)/100, 2) + } + secondCont.MtOrAt = v.ScoringMethod + secondCont.Cont = fmt.Sprintf("%v%v", v.Content, cont) + secondCont.Nature = attribute + if attribute == 3 { + secondCont.Score = targetScore + } + // fmt.Printf("获取定量考核记录--1->targetScore:%v\n--->attribute:%v\n--->Score:%v\n--->ScoringMethod:%v\n", targetScore, attribute, secondCont.Score, v.ScoringMethod) + secondCont.Score = publicmethod.DecimalEs(secondCont.Score, 2) + secondCont.Allprize = publicmethod.DecimalEs(secondCont.Allprize/100, 2) + secondCont.Zeroprize = publicmethod.DecimalEs(secondCont.Zeroprize/100, 2) + secondCont.Capping = publicmethod.DecimalEs(secondCont.Capping/100, 2) + secondCont.CompletionRate = publicmethod.DecimalEs(secondCont.CompletionRate*100, 2) + secondCont.CompletionRateAll = secondCont.CompletionRate + sendList = append(sendList, secondCont) + + var minusDepartment modelshr.AdministrativeOrganization + minErr := minusDepartment.GetCont(map[string]interface{}{"id": v.EvaluationDepartment}, "name") + if minErr == nil { + if !publicmethod.IsInTrue[string](minusDepartment.Name, EvalDepartment) { + EvalDepartment = append(EvalDepartment, minusDepartment.Name) + } + } + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-29 10:16:59 +@ 功能: 获取指标分数 +@ 参数 + + #key 方案版本 + #targetId 指标Id + #orgId 行政组织 + #years 年 + #months 月 + +@ 返回值 + + #targetScore 指标分 + #attribute 1、使用;2:禁用;3:观察 + +@ 方法原型 + + #func GetTargetPlanScore(key, targetId string, orgId, years, months int64) (targetScore float64, attribute int) +*/ +func GetTargetPlanScore(key, targetId string, orgId, years, months int64) (targetScore float64, attribute, cycles int) { + var planVersionInfo modelskpi.PlanVersio + planVersionInfo, err := publicmethod.GetPlanVresion(orgId, years, months) + // err := planVersionInfo.GetCont(map[string]interface{}{"`key`": key}) + if err != nil { + planVersionInfo.GetCont(map[string]interface{}{"`key`": key}) + } + var planVersioInfo []AddDutyNewCont + json.Unmarshal([]byte(planVersionInfo.Content), &planVersioInfo) + if len(planVersioInfo) < 1 { + return + } + for _, v := range planVersioInfo { + for _, tv := range v.Child { + if targetId == tv.Id { + targetScore = float64(tv.ReferenceScore) + attribute = tv.Status + fmt.Printf("指标分数!-->%v-->%v\n", targetScore, tv.Status) + cycles = tv.Cycles + } + } + } + + return +} diff --git a/api/version1/statistics/pcplant.go b/api/version1/statistics/pcplant.go new file mode 100644 index 0000000..e51be4f --- /dev/null +++ b/api/version1/statistics/pcplant.go @@ -0,0 +1,151 @@ +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-07-29 15:21:47 +@ 功能: 方案得分明细 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) 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 = 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 == "12" { + var statisCont detailedResultsList + 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 //部门名称 + 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 modelskpi.EvaluationTarget //指标信息 + if cv.Id != "" && cv.Id != "0" { + targetErr := evalTargetCont.GetCont(map[string]interface{}{"`et_id`": cv.Id}, "et_type") + monthInt := int64(requestData.Months) + if targetErr == nil { + if evalTargetCont.Type == 1 { + //定性指标 + statisCont.Score, statisCont.ExecutiveDepartment = DingXingScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{monthInt}, cv.Id) + + } else { + //定量指标 + var dingLiangScore float64 + var orgList []string + //定量考核 + switch cv.Cycles { + case 5: //季度指标 + quarterList := []int64{3, 6, 9, 12} + if !publicmethod.IsInTrue[int64](monthInt, quarterList) { + dingLiangScore = float64(cv.ReferenceScore) + // fmt.Printf("季度指标--->%v--->%v--->%v\n", cv.Name, cv.Id, dingLiangScore) + } else { + switch monthInt { + case 3: + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{1, 2, 3}, cv.Id, cv.Cycles) + case 6: + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{4, 5, 6}, cv.Id, cv.Cycles) + case 9: + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{7, 8, 9}, cv.Id, cv.Cycles) + case 12: + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{10, 11, 12}, cv.Id, cv.Cycles) + default: + } + } + case 6: //年度指标 + if monthInt == 12 { + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, cv.Id, cv.Cycles) + } else { + dingLiangScore = float64(cv.ReferenceScore) + // fmt.Printf("年度指标--->%v--->%v--->%v\n", cv.Name, cv.Id, dingLiangScore) + } + + case 7: //半年指标 + switch monthInt { + case 6: + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{1, 2, 3, 4, 5, 6}, cv.Id, cv.Cycles) + case 12: + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{7, 8, 9, 10, 11, 12}, cv.Id, cv.Cycles) + default: + dingLiangScore = float64(cv.ReferenceScore) + // fmt.Printf("半年指标--->%v--->%v--->%v\n", cv.Name, cv.Id, dingLiangScore) + } + default: //月度指标 + dingLiangScore, orgList = DingLiangScoreCalculation(orgId, requestData.Year, cv.ReferenceScore, []int64{monthInt}, cv.Id, cv.Cycles) + } + dingLiangScoreGd, _ := publicmethod.DecimalNew(dingLiangScore, 2) + statisCont.Score = dingLiangScoreGd + statisCont.ExecutiveDepartment = orgList + fmt.Printf("定量指标---->%v\n---->%v\n", dingLiangScoreGd, orgList) + } + } + } + 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) +} diff --git a/api/version1/statistics/type.go b/api/version1/statistics/type.go new file mode 100644 index 0000000..604b0c3 --- /dev/null +++ b/api/version1/statistics/type.go @@ -0,0 +1,229 @@ +package statistics + +import ( + "key_performance_indicators/overall/publicmethod" + "sync" + + "github.com/gin-gonic/gin" +) + +type ApiMethod struct{} + +// 携程设置 +// var syncSeting = sync.WaitGroup{} +var syncProcess = sync.WaitGroup{} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 10:11:58 +@ 功能: 统计入口 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) Index(c *gin.Context) { + outputCont := publicmethod.MapOut[string]() + outputCont["index"] = "统计入口" + publicmethod.Result(0, outputCont, c) +} + +// 绩效考核成绩表 +type TranscriptTable struct { + Group string `json:"group"` + Department string `json:"department"` + Year string `year` + Month []int `json:"month"` +} + +// 绩效考核成绩表结果 +type TranscriptTableDateList struct { + DepartmentId string `json:"departmentid"` + Department string `json:"department"` + Sort int `json:"sort"` + A float64 `json:"a"` + B float64 `json:"b"` + C float64 `json:"C"` + D float64 `json:"d"` + E float64 `json:"e"` + F float64 `json:"f"` + G float64 `json:"g"` + H float64 `json:"h"` + I float64 `json:"i"` + J float64 `json:"J"` + K float64 `json:"K"` + L float64 `json:"L"` +} + +// 计算得分性质 +type defenfenxi struct { + Title string `json:"title"` + TimeClass string `json:"timeclass"` + Month int64 `json:"month"` + Stroce float64 `json:"stroce"` + State int `json:"state"` +} + +// 成绩表 +type TranscriptTableData struct { + ScoreStatistics []TranscriptTableDateList + Defen []defenfenxi + mutext sync.RWMutex +} + +// 读取成绩表锁数据 +func (t *TranscriptTableData) readTranscriptData() []TranscriptTableDateList { + t.mutext.RLock() + defer t.mutext.RUnlock() + return t.ScoreStatistics +} + +type countEveryDepartmentMonthScore struct { + outData []everyDepartmentScore + mutext sync.RWMutex +} + +// 部门月分数 +type everyDepartmentScore struct { + MonthVal int64 `json:"monthval"` + Score float64 `json:"score"` +} + +// 读取锁数据 +func (c *countEveryDepartmentMonthScore) readMyDayData() []everyDepartmentScore { + c.mutext.RLock() + defer c.mutext.RUnlock() + return c.outData +} + +var syncProcessDepartTarget = sync.WaitGroup{} //获取指标相关参数 +// 方案回显 +type AddDutyNewCont struct { + Id string `json:"id"` //维度ID + Name string `json:"name"` + // Order int64 `json:"ordering"` + ZhiFraction int `json:"zhiFraction"` + Child []EvaluPross `json:"child"` //考核细则 +} + +// 指标 +type EvaluPross struct { + Id string `json:"id"` //维度ID + Name string `json:"name"` + Content string `json:"content"` //指标说明 + Unit string `json:"unit"` //单位"` + ReferenceScore int64 `json:"referencescore"` //标准分值"` + Cycles int `json:"cycle"` //1:班;2:天;3:周;4:月;5:季度;6:年"` + CycleAttres int `json:"cycleattr"` //辅助计数"` + State int `json:"state"` + Score int64 `json:"score"` //分数 + QualEvalId string `json:"qeid"` + Status int `json:"status"` +} + +// 定量流水全奖值、零奖值、封顶值 +type FlowLogAllZreo struct { + Id string `json:"id"` + TargetId string `json:"targetid"` //指标ID` + Zeroprize float64 `json:"zeroprize"` //零奖值"` + Allprize float64 `json:"allprize"` //全奖值"` + Capping float64 `json:"capping"` //封顶值"` +} + +// 图标维度输出 +type TranscriptTableDateListChars struct { + XLine []string `json:"xline"` + Cylindrical []string `json:"cylindrical"` + YLine []YlineData `json:"cylindricaldata"` +} + +type YlineData struct { + Name string `json:"name"` + Data []float64 `json:"data"` +} + +// 行政组织级统计 +type orgShierTongji struct { + A []float64 `json:"a"` + B []float64 `json:"b"` + C []float64 `json:"C"` + D []float64 `json:"d"` + E []float64 `json:"e"` + F []float64 `json:"f"` + G []float64 `json:"g"` + H []float64 `json:"h"` + I []float64 `json:"i"` + J []float64 `json:"J"` + K []float64 `json:"K"` + L []float64 `json:"L"` +} + +// 查询成绩表月份明细 +type detailedResults struct { + Department string `json:"department"` //部门 + Year int64 `json:"year"` //年 + Months int `json:"month"` //月份 +} + +// 查询成绩表月份明细历史 +type detailedResultsLog struct { + TargetId string `json:"targetid"` //指标ID + detailedResults +} + +// 定量考核基础参数 +type dingLiangKaoHe struct { + Zeroprize float64 `json:"zeroprize"` //零奖值"` + Allprize float64 `json:"allprize"` //全奖值"` + Capping float64 `json:"capping"` //封顶值"` + Actual float64 `json:"actual"` //实际值 + CompletionRate float64 `json:"completionrate"` //达成率 + CompletionRateAll float64 `json:"completionrateall"` //达成率 + Score float64 `json:"score"` //得分 + MtOrAt int `json:"mtorat"` //手动还是自动 + Cont string `json:"count"` //说明 + Nature int `json:"nature"` //性质 +} + +// 输出考核方案月份详情表 +type detailedResultsList struct { + GroupId string `json:"group"` //集团Id + GroupName string `json:"groupname"` //集团名称 + DepartmentId string `json:"departmentid"` //部门ID + DepartmentName string `json:"departmentname"` //部门名称 + DimensionId string `json:"dimensionid"` //维度Id + DimensionName string `json:"dimensionname"` //维度名称 + DimensionWeight int64 `json:"dimensionweight"` //维度权重 + TargetId string `json:"targetid"` //指标ID + TargetName string `json:"targetname"` //指标名称 + TargetCont string `json:"targetCont"` //指标说明 + Targetweight int64 `json:"targetweight"` //指标权重 + Type int `json:"type"` //1:定性;2:定量 + Unit string `json:"unit"` //单位 + Cycle int `json:"cycle"` //周期 + Cycleattr int `json:"cycleattr"` //辅助参数 + ExecutiveDepartment []string `json:"executivedepartment"` //执行部门 + Score float64 `json:"score"` //得分 + Versio string `json:"versio"` //版本号码 +} + +// 定量考核基础参数(新版) +type dingLiangKaoHeNew struct { + Zeroprize float64 `json:"zeroprize"` //零奖值"` + Allprize float64 `json:"allprize"` //全奖值"` + Capping float64 `json:"capping"` //封顶值"` + Actual float64 `json:"actual"` //实际值 + Score float64 `json:"score"` //手动得分 + CompletionRate float64 `json:"completionrate"` //达成率 + TargetScore float64 `json:"target_score"` //指标分 + MtOrAt int `json:"mtorat"` //手动还是自动 + Nature int `json:"nature"` //1、使用;2:禁用;3:观察 +} diff --git a/apirouter/entry.go b/apirouter/entry.go index 17fc5c6..74d5b65 100644 --- a/apirouter/entry.go +++ b/apirouter/entry.go @@ -9,6 +9,7 @@ import ( "key_performance_indicators/apirouter/v1/empowerrouter" honorsRoute "key_performance_indicators/apirouter/v1/honorsRoute" "key_performance_indicators/apirouter/v1/postseting" + "key_performance_indicators/apirouter/v1/statisticsrouter" "key_performance_indicators/apirouter/v1/systempower" "key_performance_indicators/apirouter/verifyLogin" "key_performance_indicators/apirouter/wechaturl" @@ -18,19 +19,20 @@ import ( // 路由结构 type RouterGroup struct { - EmpowerRouter empower.EmpowerApiRouter - VerifyLogin verifyLogin.ApiRouter - ShiyanApi apishiyan.ApiRouter - HonorsSouteRouter honorsRoute.ApiRouter - PostRouter postseting.ApiRouter - DepartmentRouter departmentseting.ApiRouter - BookImg bookimg.ApiRouter - SystemPowerRouter systempower.ApiRouter - Empowerouter empowerrouter.ApiRouter - WechatRouter wechaturl.ApiRouter - WorkFlowRouter workflowchart.ApiRouter - ExamineSystemApp approvalsystem.ApiRouter - MyWorkFlowRouter workflowrouter.ApiRouter + EmpowerRouter empower.EmpowerApiRouter + VerifyLogin verifyLogin.ApiRouter + ShiyanApi apishiyan.ApiRouter + HonorsSouteRouter honorsRoute.ApiRouter + PostRouter postseting.ApiRouter + DepartmentRouter departmentseting.ApiRouter + BookImg bookimg.ApiRouter + SystemPowerRouter systempower.ApiRouter + Empowerouter empowerrouter.ApiRouter + WechatRouter wechaturl.ApiRouter + WorkFlowRouter workflowchart.ApiRouter + ExamineSystemApp approvalsystem.ApiRouter + MyWorkFlowRouter workflowrouter.ApiRouter + StatisticsApiRouter statisticsrouter.ApiRouter } var RouterGroupEntry = new(RouterGroup) diff --git a/apirouter/v1/statisticsrouter/pc.go b/apirouter/v1/statisticsrouter/pc.go new file mode 100644 index 0000000..db346f7 --- /dev/null +++ b/apirouter/v1/statisticsrouter/pc.go @@ -0,0 +1,41 @@ +package statisticsrouter + +import ( + "key_performance_indicators/api/version1" + + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 10:17:05 +@ 功能: 统计路由 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { + apiRouter := router.Group("strtistics") + var statisRouter = version1.AppApiEntry.StatisticsApi + { + apiRouter.GET("", statisRouter.Index) //入口 + apiRouter.POST("", statisRouter.Index) //入口 + + apiRouter.POST("orgtranscript", statisRouter.OrgTranscript) //行政组织成绩单 + apiRouter.POST("summarydetailslianglog", statisRouter.SummaryDetailsLiangLog) //汇总详情定量历史记录 + apiRouter.POST("summarydetails", statisRouter.SummaryDetails) //方案得分明细 + + apiRouter.POST("summaryplanrecord", statisRouter.SummaryPlanRecord) //汇总方案定量指标详情历史记录(新版) + apiRouter.POST("newsummarydetails", statisRouter.NewSummaryDetails) //方案得分明细(新版) + apiRouter.POST("neworgtranscript", statisRouter.OrgTranscriptNew) //行政组织成绩单(新版) + } +} diff --git a/apirouter/v1/statisticsrouter/type.go b/apirouter/v1/statisticsrouter/type.go new file mode 100644 index 0000000..d08de9b --- /dev/null +++ b/apirouter/v1/statisticsrouter/type.go @@ -0,0 +1,14 @@ +package statisticsrouter + +/** +@ 作者: 秦东 +@ 时间: 2023-07-27 10:16:28 +@ 功能: 数据统计路由 +@ 参数 + # +@ 返回值 + # +@ 方法原型 + # +*/ +type ApiRouter struct{} diff --git a/config/configDatabase/database.yaml b/config/configDatabase/database.yaml index 0740277..77b817f 100644 --- a/config/configDatabase/database.yaml +++ b/config/configDatabase/database.yaml @@ -28,17 +28,17 @@ wechat: gorm_log: false #是否开启gorm日志 #HR数据库 hrdatabase: - url_path: '127.0.0.1' #数据库地址 - port: 3306 #数据库端口 + # url_path: '127.0.0.1' #数据库地址 + # port: 3306 #数据库端口 + # name: 'hr_new' #数据库名称 + # username: 'root' #数据库用户民 + # password: 'root' #数据库密码 + + url_path: '172.20.5.33' #数据库地址 + port: 4000 #数据库端口 name: 'hr_new' #数据库名称 username: 'root' #数据库用户民 - password: 'root' #数据库密码 - - # url_path: '120.224.6.6' #数据库地址 - # port: 6666 #数据库端口 - # name: 'hr_new' #数据库名称 - # username: 'hr_new' #数据库用户民 - # password: 'AnknKiXiXaxNrw78' #数据库密码 + password: '9z_Bu28r1*DZ3K6@+a' #数据库密码 charset: 'utf8mb4' #数据库编码方式 parseTime: 'True' #是否自动转换时间 @@ -160,12 +160,16 @@ healthReportDate: kpiDate: url_path: '127.0.0.1' #数据库地址 port: 3306 #数据库端口 + # url_path: '172.20.5.33' #数据库地址 + # port: 4000 #数据库端口 charset: 'utf8mb4' #数据库编码方式 parseTime: 'True' #是否自动转换时间 loc: 'Local' #时区 name: 'perform' #数据库名称 + # name: 'performing' #数据库名称 username: 'root' #数据库用户民 password: 'root' #数据库密码 + # password: '9z_Bu28r1*DZ3K6@+a' #数据库密码 max_idle_conns: 100 #最大空闲数量 max_open_conns: 1500 #最大打开数量 gorm_log: true #是否开启gorm日志 diff --git a/go.mod b/go.mod index 0d5caef..e619ccd 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect + github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/afero v1.8.2 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/go.sum b/go.sum index f1d8dd0..f056bb6 100644 --- a/go.sum +++ b/go.sum @@ -490,6 +490,8 @@ github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMT github.com/shirou/gopsutil/v3 v3.22.5/go.mod h1:so9G9VzeHt/hsd0YwqprnjHnfARAUktauykSbr+y2gA= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= diff --git a/initialization/route/initRoute.go b/initialization/route/initRoute.go index 6bddd06..5c6263b 100644 --- a/initialization/route/initRoute.go +++ b/initialization/route/initRoute.go @@ -74,6 +74,9 @@ func InitialRouter() *gin.Engine { // 图文信息 bookimgRouterApi := apirouter.RouterGroupEntry.BookImg bookimgRouterApi.RouterGroup(VerifyIdentity) + //统计 + statisticsApiRouter := apirouter.RouterGroupEntry.StatisticsApiRouter + statisticsApiRouter.RouterGroup(VerifyIdentity) } //验证身份接口 无需鉴权Url(主要web端使用) diff --git a/models/modelskpi/flow_data_log.go b/models/modelskpi/flow_data_log.go index af6dce2..9f1b0d2 100644 --- a/models/modelskpi/flow_data_log.go +++ b/models/modelskpi/flow_data_log.go @@ -19,6 +19,7 @@ type FlowDataLogType struct { TargetId int64 `json:"targetid" gorm:"column:targetid;type:bigint(20) unsigned;default:0;not null;comment:指标ID"` Edition string `json:"edition" gorm:"column:edition;type:longtext;comment:版本号 "` Content string `json:"content" gorm:"column:content;type:longtext;comment:评测内容 "` + Reply int `json:"reply" gorm:"column:fl_reply;type:int(2) unsigned;default:1;not null;comment:状态(0:删除;1:起草;2:审批;3:通过)"` } func (FlowDataLogType *FlowDataLogType) TableName() string { diff --git a/overall/publicmethod/formatOutput.go b/overall/publicmethod/formatOutput.go index 589b7c6..20cd13e 100644 --- a/overall/publicmethod/formatOutput.go +++ b/overall/publicmethod/formatOutput.go @@ -179,7 +179,7 @@ func DetermineUserIdentity(userKey int64) (identity outShenFen) { //角色权限范围判定 roleList := strings.Split(userCont.Role, ",") var roleVerify modelssystempermission.RoleEmpower - overall.CONSTANT_DB_System_Permission.Where("`state` = 1 AND `system` = ? AND `id` IN ? ", "kpi", roleList).Find(&roleVerify) + overall.CONSTANT_DB_System_Permission.Where("`state` = 1 AND `system` = ? AND `role_id` IN ? ", "kpi", roleList).Find(&roleVerify) //岗位权限范围判定 var postVerify modelssystempermission.Empower postVerify.GetCont(map[string]interface{}{"`post_id`": userCont.Position, "`state`": 1, "`system`": "kpi"}) diff --git a/overall/publicmethod/technique.go b/overall/publicmethod/technique.go index bfae198..16bd352 100644 --- a/overall/publicmethod/technique.go +++ b/overall/publicmethod/technique.go @@ -12,6 +12,7 @@ import ( "key_performance_indicators/middleware/grocerystore" "key_performance_indicators/middleware/snowflake" "key_performance_indicators/models/modelshr" + "key_performance_indicators/models/modelskpi" "key_performance_indicators/models/modelsschool" "key_performance_indicators/models/modelsstorage" "key_performance_indicators/models/modelssystempermission" @@ -25,6 +26,7 @@ import ( "time" "github.com/mozillazg/go-pinyin" + "github.com/shopspring/decimal" "gorm.io/gorm" ) @@ -81,6 +83,10 @@ func MapOut[T GenericityVariable]() (data map[T]interface{}) { data = make(map[T]interface{}) //必可不少,分配内存 return data } +func MapOutAny[T GenericityVariable, S GenericityVariable]() (data map[T]S) { + data = make(map[T]S) //必可不少,分配内存 + return data +} //时间搓转换成日期 /* @@ -599,22 +605,28 @@ func PageTurningSettings(gormDb *gorm.DB, page, pageSize int) *gorm.DB { @weishu 要保留的小数位数 */ func DecimalEs(value float64, weishu int) float64 { - switch weishu { - case 3: - value, _ = strconv.ParseFloat(fmt.Sprintf("%.3f", value), 64) - case 4: - value, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", value), 64) - case 5: - value, _ = strconv.ParseFloat(fmt.Sprintf("%.5f", value), 64) - case 6: - value, _ = strconv.ParseFloat(fmt.Sprintf("%.6f", value), 64) - default: - value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64) - } - + // switch weishu { + // case 3: + // value, _ = strconv.ParseFloat(fmt.Sprintf("%.3f", value), 64) + // case 4: + // value, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", value), 64) + // case 5: + // value, _ = strconv.ParseFloat(fmt.Sprintf("%.5f", value), 64) + // case 6: + // value, _ = strconv.ParseFloat(fmt.Sprintf("%.6f", value), 64) + // default: + // value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64) + // } + value, _ = DecimalNew(value, int32(weishu)) return value } +func DecimalNew(value float64, weishu int32) (val float64, isTrue bool) { + // decimal.NewFromFloatWithExponent(value,weishu).Float64() + val, isTrue = decimal.NewFromFloat(value).Round(weishu).Float64() + return +} + // 递归查找 func RecursionOrgLeve(superior int64, leve int64) (groupId int64) { if leve == 0 { @@ -648,6 +660,7 @@ func GetOrgStructurees(orgId int64) (groupId, companyId, departmentId, sunDepart if err != nil { return } + switch orgContTypeInfo.Level { case 1: groupId = orgContTypeInfo.Id @@ -1963,6 +1976,8 @@ func JudjeMaxOfMinVal(maxVal, minVal float64) (maxVals, minVals float64) { } } + maxVals = DecimalEs(maxVals, 2) + minVals = DecimalEs(minVals, 2) // fmt.Printf("ge---1-->%v----->%v\n", maxVals, minVals) return } @@ -2223,3 +2238,152 @@ func KpiMenuOperaTree(parentId string, treeCont []MenuContList) (treeList []Powe } return } + +/* +* +@ 作者: 秦东 +@ 时间: 2023-07-27 11:35:16 +@ 功能: 获取考核方案版本 +@ 参数 + + #orgId 行政组织 + #years 年 + #months 月 + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func GetPlanVresion(orgId, years, months int64) (planVersionInfo modelskpi.PlanVersio, err error) { + if years == 0 || months == 0 { + planVersionInfo, err = PublicPlanVersion(orgId, years, months) + } else { + var flowPlanKey []string + overall.CONSTANT_DB_KPI.Model(&modelskpi.DutyFlowData{}).Select("fld_planversion").Where("fl_duty_department = ? AND fld_year = ? AND fld_month = ? AND fl_reply IN ?", orgId, years, months, []int{2, 3}).Find(&flowPlanKey) + var scoreFlowPlanKey []string + overall.CONSTANT_DB_KPI.Model(&modelskpi.ScoreFlow{}).Select("sf_planversion").Where("sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_reply IN ?", orgId, years, months, []int{2, 3}).Find(&scoreFlowPlanKey) + planKeyList := MapOutAny[string, int64]() + for _, v := range flowPlanKey { + if _, isOk := planKeyList[v]; isOk { + planKeyList[v] = planKeyList[v] + 1 + } else { + planKeyList[v] = 1 + } + } + for _, v := range scoreFlowPlanKey { + if _, isOk := planKeyList[v]; isOk { + planKeyList[v] = planKeyList[v] + 1 + } else { + planKeyList[v] = 1 + } + } + var maxKey MaxValStruct[string, int64] + if len(planKeyList) > 0 { + fmt.Printf("planKeyList:%v\n", planKeyList) + for mk, mv := range planKeyList { + if mv > maxKey.Val { + maxKey.Key = mk + maxKey.Val = mv + } + } + } + if maxKey.Key != "" { + err = overall.CONSTANT_DB_KPI.Where("`key` = ?", maxKey.Key).Find(&planVersionInfo).Error + if err != nil { + planVersionInfo, err = PublicPlanVersion(orgId, years, months) + } + } else { + planVersionInfo, err = PublicPlanVersion(orgId, years, months) + } + // fmt.Printf("years:%v\nmonths:%v\nplanKeyList:%v\nmaxKeyt:%v\nplanVersionInfo:%v\n", planKeyList, years, months, maxKey, planVersionInfo) + } + return +} + +// 通用 +func PublicPlanVersion(orgId, years, months int64) (planVersionInfo modelskpi.PlanVersio, err error) { + err = overall.CONSTANT_DB_KPI.Where("state = 1 AND department = ?", orgId).Order("addtime desc").First(&planVersionInfo).Error + if err != nil { + err = overall.CONSTANT_DB_KPI.Where("state = 2 AND department = ? AND yeares = ?", orgId, years).Order("addtime desc").First(&planVersionInfo).Error + if err != nil { + err = overall.CONSTANT_DB_KPI.Where("state = 3 AND department = ? AND yeares = ?", orgId, years).Order("addtime desc").First(&planVersionInfo).Error + if err != nil { + err = overall.CONSTANT_DB_KPI.Where("state = 2 AND department = ?", orgId).Order("addtime desc").First(&planVersionInfo).Error + if err != nil { + err = overall.CONSTANT_DB_KPI.Where("state = 3 AND department = ?", orgId).Order("addtime desc").First(&planVersionInfo).Error + } + } + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-08-04 15:08:41 +@ 功能: 获取指标全奖值、零奖值、封顶值 +@ 参数 + + #targetId 指标 + #rewardCont 上报时的全奖值,零奖值,封顶值设置 + #orgId 行政组织 + #years 发生年 + #quarter 发生季 + #month 发生月 + #cycles 1:班;2:天;3:周;4:月;5:季度;6:年;7:半年 + +@ 返回值 + + #zeroPrize 零奖值 + #allPrize 全奖值 + #cappingPrize 封顶值 + +@ 方法原型 + + #func GetTargetConfig(targetId, rewardCont string, orgId, years, quarter, month int64, cycles int) (zeroPrize, allPrize, cappingPrize float64) +*/ +func GetTargetConfig(targetId, rewardCont string, orgId, years, quarter, month int64, cycles int) (zeroPrize, allPrize, cappingPrize float64) { + setIsTrue := true + var rewardAry []FlowLogAllZreo + jsonErr := json.Unmarshal([]byte(rewardCont), &rewardAry) + if jsonErr == nil { + //获取当前指标的全奖零奖值 + for _, v := range rewardAry { + if v.TargetId == targetId { + zeroPrize = v.Zeroprize //零奖值"` + allPrize = v.Allprize //全奖值"` + cappingPrize = v.Capping //封顶值"` + setIsTrue = false + } + } + } + if setIsTrue { + var setCont modelskpi.QuantitativeConfig + gormdb := overall.CONSTANT_DB_KPI.Where("`departmentid` = ? AND `target` = ? AND `year` = ?", orgId, targetId, years) + switch cycles { + case 5: //季度 + gormdb = gormdb.Where("`timecopy` = ?", quarter) + case 6: //年 + case 7: //半年 + banNian := 1 + if !IsInTrue[int64](month, []int64{1, 2, 3, 4, 5, 6}) { + banNian = 2 + } + gormdb = gormdb.Where("`timecopy` = ?", banNian) + default: + gormdb = gormdb.Where("`timecopy` = ?", month) + } + err := gormdb.Find(setCont).Error + if err == nil { + zeroPrize = setCont.Zeroprize //零奖值"` + allPrize = setCont.Allprize //全奖值"` + cappingPrize = setCont.CappingVal //封顶值"` + } + } + return +} diff --git a/overall/publicmethod/type.go b/overall/publicmethod/type.go index 3f226fd..ed62ce8 100644 --- a/overall/publicmethod/type.go +++ b/overall/publicmethod/type.go @@ -300,3 +300,18 @@ type WechatCallBack struct { type GetOrgAllSun struct { Id []int64 } + +// 最大值 +type MaxValStruct[T GenericityVariable, S GenericityVariable] struct { + Key T + Val S +} + +// 定量流水全奖值、零奖值、封顶值 +type FlowLogAllZreo struct { + Id string `json:"id"` + TargetId string `json:"targetid"` //指标ID` + Zeroprize float64 `json:"zeroprize"` //零奖值"` + Allprize float64 `json:"allprize"` //全奖值"` + Capping float64 `json:"capping"` //封顶值"` +}