package statistics import ( "encoding/json" "fmt" "strconv" "time" "github.com/flipped-aurora/gin-vue-admin/server/commonus" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/flipped-aurora/gin-vue-admin/server/model/hrsystem" "github.com/gin-gonic/gin" "gorm.io/gorm" ) //计算定量考核 /* 统计分数 @group 集团 @department 部门 @dimensionId 维度 @targetId 指标 @i 步进器 @status 是否为观察数据 @scoringMethod 手动计分还是自动计分 @class 指标类型 1、定性;2:定量 @referenceScore 指标权重 @yserInt 年度 @timeClass 4:月;5:季度;6:年;7:半年 @typeClass 1:定性;2:定量;3:观察 */ func (t *tablePlanVersionStic) conditionStatisticsNew(group, department, dimensionId, targetId string, i, status, scoringMethod, class int, yserInt, referenceScore int64, timeClass, typeClass int) { t.mutext.Lock() defer t.mutext.Unlock() var fldList []assessmentmodel.FlowDataLogType var tableScoreCont TableScoreList tableScoreCont.Counter = i gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowDataLogType{}) gormDb = gormDb.Where("`targetid` = ? AND `group` = ? AND `department` = ? AND `year` = ?", targetId, group, department, yserInt) switch timeClass { case 5: gormDb = gormDb.Where("`quarte` = ?", i) case 6: case 7: if i == 1 { gormDb = gormDb.Where("`month` IN ?", []int{1, 2, 3, 4, 5, 6}) } else { gormDb = gormDb.Where("`month` IN ?", []int{7, 8, 9, 10, 11, 12}) } default: gormDb = gormDb.Where("`month` = ?", i) } gormDb = gormDb.Order("`id` ASC").Find(&fldList) jsCon, _ := json.Marshal(fldList) fmt.Printf("targetid------------->%v------------>%v---->%v\n", targetId, timeClass, string(jsCon)) var mtScore float64 = 0 var atScore float64 = 0 var lastEvalId int64 // var scoreSum float64 = 0 var shouDongFenzhi float64 = 0 var zhidongDongLiang float64 = 0 // var realScore float64 = 0 if len(fldList) > 0 { for _, v := range fldList { // fmt.Printf("Key----------------->%v\n", v.Key) if v.Key != 0 { lastEvalId = v.Key } if v.ScoringMethod == 1 { atScore = atScore + float64(v.Score) zhidongDongLiang = zhidongDongLiang + float64(v.Score) } else { atScore = atScore + float64(v.ScoringScore) shouDongFenzhi = shouDongFenzhi + float64(v.ScoringScore) } // scoreSum = scoreSum + atScore // scoreSum = scoreSum + float64(v.Score) mtScore = mtScore + v.ScoringScore if v.DutyDepartment != 0 { whereDepart := commonus.MapOut() whereDepart["id"] = v.DutyDepartment orgContDer, _ := commonus.GetNewOrgCont(whereDepart, "name") tableScoreCont.ExecutiveDepartment = append(tableScoreCont.ExecutiveDepartment, orgContDer.Name) } } } tableScoreCont.ScoreVal = commonus.Decimal(atScore / 100) targetIdInt, _ := strconv.ParseInt(targetId, 10, 64) groupId, _ := strconv.ParseInt(group, 10, 64) departmentId, _ := strconv.ParseInt(department, 10, 64) dimensionIdInt, _ := strconv.ParseInt(dimensionId, 10, 64) zeroPrize, allPrize, cappingPrize := GetAllZreoCapp(lastEvalId, groupId, departmentId, dimensionIdInt, targetIdInt, yserInt, int64(i), 0) // fmt.Printf("scoreSum--->%v------->mtScore--->%v---->zeroPrize--->%v---->allPrize--->%v---->cappingPrize--->%v---->typeClass---->%v\n", scoreSum, mtScore, zeroPrize, allPrize, cappingPrize, typeClass) tableScoreCont.ActualScore, tableScoreCont.AllPrize, tableScoreCont.ZeroPrize, tableScoreCont.CappingVal, tableScoreCont.Achievement = commonus.CalculateScore(referenceScore, atScore, allPrize, zeroPrize, cappingPrize, typeClass) // tableScoreCont.ActualScore, tableScoreCont.AllPrize, tableScoreCont.ZeroPrize, tableScoreCont.CappingVal, tableScoreCont.Achievement = commonus.CalculateScore(referenceScore, zhidongDongLiang, allPrize, zeroPrize, cappingPrize, typeClass) // fmt.Printf("达成率--13-->%v-->%v-->%v-->%v-->%v\n", tableScoreCont.ActualScore, tableScoreCont.AllPrize, tableScoreCont.ZeroPrize, tableScoreCont.CappingVal, tableScoreCont.Achievement) if status == 3 { tableScoreCont.ActualScore = float64(referenceScore) } tableScoreCont.ActualScore = tableScoreCont.ActualScore + commonus.Decimal(shouDongFenzhi/100) // tableScoreCont.ActualScore = commonus.Decimal(mtScore / 100) t.TableScore = append(t.TableScore, tableScoreCont) syncProcessDepartTarget.Done() } //获取定量数据得全奖零奖封顶值得历史数据 /* @flKey 流水KEY @group 集团 @depart 部门 @dimen 维度 @target 指标 @deaTarget 细则 @year 年份 @timecopy 辅助计数 */ func GetAllZreoCapp(flKey, group, depart, dimen, targetId, year, timecopy, deaTarget int64) (zeroPrize, allPrize, cappingPrize float64) { if flKey == 0 { return } var baseLineStr string err := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowLog{}).Select("fl_baseline").Where("fl_key = ?", flKey).First(&baseLineStr).Error if err != nil { zeroPrize, allPrize, cappingPrize = GetPassRate(group, depart, dimen, targetId, year, timecopy, deaTarget) return } var flowLogConfig []FlowLogAllZreo jsonErr := json.Unmarshal([]byte(baseLineStr), &flowLogConfig) // fmt.Printf("flKey, targetId----------------->%v--------->%v---------->%v--------->%v\n", flKey, targetId, jsonErr, baseLineStr) if jsonErr != nil { zeroPrize, allPrize, cappingPrize = GetPassRate(group, depart, dimen, targetId, year, timecopy, deaTarget) return } for _, v := range flowLogConfig { if v.TargetId == strconv.FormatInt(targetId, 10) { zeroPrize = v.Zeroprize allPrize = v.Allprize cappingPrize = v.Capping // fmt.Printf("zeroPrize----------------->%v----allPrize----->%v-----cappingPrize----->%v------TargetId--->%v\n", zeroPrize, allPrize, cappingPrize, v.TargetId) return } } return } //获取达成率配置 /*GetPassRate(group, depart, dimen, target, year, timecopy, deaTarget int64) @group 集团 @depart 部门 @dimen 维度 @target 指标 @year 年 @timecopy 辅助技术 @deaTarget 指标细则 */ func GetPassRate(group, depart, dimen, target, year, timecopy, deaTarget int64) (zeroPrize, allPrize, cappingPrize float64) { var qualConfig assessmentmodel.QuantitativeConfig gormDb := global.GVA_DB_Performanceappraisal.Where("`group` = ? AND `departmentid` = ? AND `dimension` = ? AND `target` = ? AND `year` = ?", group, depart, dimen, target, year) if deaTarget != 0 { gormDb = gormDb.Where("targetconfig = ?", deaTarget) } gormDb = gormDb.Where("timecopy = ?", timecopy) err := gormDb.First(&qualConfig).Error if err != nil { return } allPrize = qualConfig.Allprize zeroPrize = qualConfig.Zeroprize cappingPrize = qualConfig.CappingVal return } //成绩表查询 /* */ func (a *ApiGroup) DepartmentTranscript(c *gin.Context) { isTrue, userCont := commonus.ClientIdentity() if isTrue != true { response.Result(101, isTrue, "您的身份令牌已经失效!请重新登录获取身份令牌!", c) return } // fmt.Printf("userCont------------------->%v\n", userCont) var requestData TranscriptTable c.ShouldBindJSON(&requestData) var orgList []hrsystem.AdministrativeOrganization gromDb := global.GVA_DB_HrDataBase.Model(&hrsystem.AdministrativeOrganization{}).Where("state = 1") if requestData.Group != "" { gromDb = gromDb.Where("superior = ?", requestData.Group) } else { gromDb = gromDb.Where("superior = ?", userCont.Company) } if requestData.Department != "" { gromDb = gromDb.Where("`id` = ?", requestData.Department) } err := gromDb.Find(&orgList).Error if err != nil { response.Result(102, err, "没有查询到数据", c) return } countDeparNum := len(orgList) if countDeparNum <= 0 { response.Result(103, err, "没有查询到数据", c) return } var orgAry []hrsystem.AdministrativeOrganization for _, ov := range orgList { orgAry = append(orgAry, ov) // if ov.Id == 281 || ov.Id == 280 { var ovlist []hrsystem.AdministrativeOrganization ovErr := global.GVA_DB_HrDataBase.Where("state = 1").Where("ispower = 1 AND superior = ?", ov.Id).Find(&ovlist).Error if ovErr == nil { for _, ovl := range ovlist { // orgList = append(orgList, ovl) orgAry = append(orgAry, ovl) } } // } else { // orgAry = append(orgAry, ov) // } } currentYear := commonus.ComputingTime(time.Now().Unix(), 1) if requestData.Year != "" { yearInt64, _ := strconv.ParseInt(requestData.Year, 10, 64) currentYear = yearInt64 } var deaprtmenTranscript TranscriptTableData for _, v := range orgAry { syncProcess.Add(1) go deaprtmenTranscript.StatisticalResults(userCont.Company, v, currentYear) // break } syncProcess.Wait() readStatisticsData := deaprtmenTranscript.readTranscriptData() 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 commonus.IsInTrue[int](i, requestData.Month) == true && commonus.IsInTrue[string](fmt.Sprintf("%v月", i), echarsList.XLine) == false { 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 commonus.IsInTrue[int](1, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 1)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.A) } if commonus.IsInTrue[int](2, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 2)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.B) } if commonus.IsInTrue[int](3, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 3)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.C) } if commonus.IsInTrue[int](4, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 4)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.D) } if commonus.IsInTrue[int](5, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 5)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.E) } if commonus.IsInTrue[int](6, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 6)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.F) } if commonus.IsInTrue[int](7, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 7)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.G) } if commonus.IsInTrue[int](8, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 8)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.H) } if commonus.IsInTrue[int](9, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 9)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.I) } if commonus.IsInTrue[int](10, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 10)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.J) } if commonus.IsInTrue[int](11, requestData.Month) == true { // echarsList.XLine = append(echarsList.XLine, fmt.Sprintf("%v月", 11)) cyLineAry_1.Data = append(cyLineAry_1.Data, readv.K) } if commonus.IsInTrue[int](12, requestData.Month) == true { // 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) echarsList.YLine = append(echarsList.YLine, cyLineAry_1) // echarsListOrg.YLine = append(echarsListOrg.YLine, cyLineAry_2) } if jiBuQi > 0 { var pingJunFen TranscriptTableDateList pingJunFen.DepartmentId = "0" pingJunFen.Department = "平均分" pingJunFen.A = commonus.Decimal(AScore / float64(jiBuQi)) pingJunFen.B = commonus.Decimal(BScore / float64(jiBuQi)) pingJunFen.C = commonus.Decimal(CScore / float64(jiBuQi)) pingJunFen.D = commonus.Decimal(DScore / float64(jiBuQi)) pingJunFen.E = commonus.Decimal(EScore / float64(jiBuQi)) pingJunFen.F = commonus.Decimal(FScore / float64(jiBuQi)) pingJunFen.G = commonus.Decimal(GScore / float64(jiBuQi)) pingJunFen.H = commonus.Decimal(HScore / float64(jiBuQi)) pingJunFen.I = commonus.Decimal(IScore / float64(jiBuQi)) pingJunFen.J = commonus.Decimal(JScore / float64(jiBuQi)) pingJunFen.K = commonus.Decimal(KScore / float64(jiBuQi)) pingJunFen.L = commonus.Decimal(LScore / float64(jiBuQi)) 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 } 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.G 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 := commonus.MapOut() outData["readStatisticsData"] = readStatisticsData outData["echarsList"] = echarsList outData["echarsListOrg"] = echarsListOrg response.Result(0, outData, "查询完成", c) } func kjsd(name string, yZhoue []YlineData) bool { for _, v := range yZhoue { if v.Name == name { return true } } return false } //统计月度成绩 func (t *TranscriptTableData) StatisticalResults(group string, orgCont hrsystem.AdministrativeOrganization, year int64) { t.mutext.Lock() defer t.mutext.Unlock() // fmt.Printf("orgCont----------->%v\n", orgCont) // return //获取本本部门发行版考核方案 currentYear := commonus.ComputingTime(time.Now().Unix(), 1) var monthTody int64 = 12 if currentYear == year { monthTody = commonus.ComputingTime(time.Now().Unix(), 3) } var planVersion assessmentmodel.PlanVersio err := global.GVA_DB_Performanceappraisal.Where("state = 1 AND department = ?", orgCont.Id).First(&planVersion).Error if err == nil { var planVersioInfo []AddDutyNewCont jsonErr := json.Unmarshal([]byte(planVersion.Content), &planVersioInfo) if jsonErr == nil { var pingJunFen TranscriptTableDateList pingJunFen.DepartmentId = strconv.FormatInt(orgCont.Id, 10) pingJunFen.Department = orgCont.Name if currentYear >= year { if monthTody >= 1 { pingJunFen.A = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 1) } else { pingJunFen.A = -10000 } if monthTody >= 2 { pingJunFen.B = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 2) } else { pingJunFen.B = -10000 } if monthTody >= 3 { pingJunFen.C = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 3) } else { pingJunFen.C = -10000 } if monthTody >= 4 { pingJunFen.D = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 4) } else { pingJunFen.D = -10000 } if monthTody >= 5 { pingJunFen.E = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 5) } else { pingJunFen.E = -10000 } if monthTody >= 6 { pingJunFen.F = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 6) } else { pingJunFen.F = -10000 } if monthTody >= 7 { pingJunFen.G = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 7) } else { pingJunFen.G = -10000 } if monthTody >= 8 { pingJunFen.H = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 8) } else { pingJunFen.H = -10000 } if monthTody >= 9 { pingJunFen.I = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 9) } else { pingJunFen.I = -10000 } if monthTody >= 10 { pingJunFen.J = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 10) } else { pingJunFen.J = -10000 } if monthTody >= 11 { pingJunFen.K = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 11) } else { pingJunFen.K = -10000 } if monthTody >= 12 { pingJunFen.L = StatisVersionTable(group, planVersioInfo, orgCont.Id, year, 12) } else { pingJunFen.L = -10000 } } t.ScoreStatistics = append(t.ScoreStatistics, pingJunFen) } } syncProcess.Done() } //根据版本统计得分 /* @planVersionCont 部门方案版本内容 @orgId 部门ID @year 年 @month 月 */ func StatisVersionTable(group string, planVersionCont []AddDutyNewCont, orgId, year int64, month int) float64 { var sumScore float64 = 0 var sumScoreKS float64 = 0 var deScore float64 = 0 var listgg []defenfenxi for _, v := range planVersionCont { sumScore = sumScore + float64(v.ZhiFraction) for _, vc := range v.Child { // if vc.Id == "6" { var listggCont defenfenxi listggCont.Title = vc.Name sumScoreKS = sumScoreKS + float64(vc.ReferenceScore) if vc.Status == 3 { deScore = deScore + float64(vc.ReferenceScore) listggCont.Stroce = float64(vc.ReferenceScore) fmt.Printf("Score---观察------指标--%v----指标分----->%v---->结算分---->%v\n", vc.Name, float64(vc.ReferenceScore), deScore) } if vc.Status == 1 && vc.Status != 3 { var targetInfo assessmentmodel.EvaluationTarget targetInfo.GetCont(map[string]interface{}{"et_id": vc.Id}, "et_type,et_cycle,et_title") // if targetInfo.Type == 1 { // //定性考核 // gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_month` = ?", vc.Id, orgId, year, month) // deScore = deScore + calculationDingXingScore(gormDb, float64(vc.ReferenceScore)) // } else { // //定量考核 // gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowDataLogType{}).Where("`month` = ?", month) // deScore = deScore + calculationDingLiangScore(group, strconv.FormatInt(orgId, 10), v.Id, vc.Id, gormDb, vc.ReferenceScore, year, int64(month)) // } cyclsSet := vc.Cycles if cyclsSet == 0 { cyclsSet = targetInfo.Cycles } switch cyclsSet { case 5: //季度 jidu := 1 isWerint := false // var monthAry []int switch month { case 3: //monthAry = []int{1, 2, 3} isWerint = true jidu = 1 case 6: //monthAry = []int{4, 5, 6} isWerint = true jidu = 2 case 9: //monthAry = []int{7, 8, 9} isWerint = true jidu = 3 case 12: //monthAry = []int{10, 11, 12} isWerint = true jidu = 4 default: // deScore = deScore + float64(vc.ReferenceScore) isWerint = false jidu = 1 } if isWerint == true { if targetInfo.Type == 1 { //定性考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_quarter` = ?", vc.Id, orgId, year, jidu) gormDbs := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_quarter` = ?", vc.Id, orgId, year, jidu) fffff := calculationDingXingScore(gormDb, gormDbs, float64(vc.ReferenceScore)) deScore = deScore + fffff listggCont.Stroce = fffff listggCont.TimeClass = "1" // fmt.Printf("Score---季度---x----->%v\n", fffff) } else { //定量考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowDataLogType{}).Where("`quarte` = ?", jidu) fffG := calculationDingLiangScore(group, strconv.FormatInt(orgId, 10), v.Id, vc.Id, gormDb, vc.ReferenceScore, year, int64(jidu)) deScore = deScore + fffG listggCont.Stroce = fffG listggCont.TimeClass = "2" // fmt.Printf("Score---季度---l----->%v\n", fffG) } } else { deScore = deScore + float64(vc.ReferenceScore) // fmt.Printf("Score---季度---z----->%v\n", float64(vc.ReferenceScore)) } case 6: //年 if month == 12 { if targetInfo.Type == 1 { //定性考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ?", vc.Id, orgId, year) gormDbs := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ?", vc.Id, orgId, year) fffff := calculationDingXingScore(gormDb, gormDbs, float64(vc.ReferenceScore)) deScore = deScore + fffff listggCont.Stroce = fffff listggCont.TimeClass = "1" // fmt.Printf("Score---年---x----->%v\n", fffff) } else { //定量考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowDataLogType{}) fffG := calculationDingLiangScore(group, strconv.FormatInt(orgId, 10), v.Id, vc.Id, gormDb, vc.ReferenceScore, year, 1) deScore = deScore + fffG listggCont.Stroce = fffG listggCont.TimeClass = "2" // fmt.Printf("Score---年---l----->%v\n", fffG) } } else { deScore = deScore + float64(vc.ReferenceScore) // fmt.Printf("Score---年---z----->%v\n", float64(vc.ReferenceScore)) } case 7: //半年 bannian := 1 isWerint := false var monthAry []int switch month { case 6: for i := 1; i <= 6; i++ { monthAry = append(monthAry, i) } isWerint = true bannian = 1 case 7: for i := 7; i <= 12; i++ { monthAry = append(monthAry, i) } isWerint = true bannian = 2 default: // deScore = deScore + float64(vc.ReferenceScore) isWerint = false bannian = 1 } if isWerint == true { if targetInfo.Type == 1 { //定性考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_month` IN ?", vc.Id, orgId, year, monthAry) gormDbs := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_month` IN ?", vc.Id, orgId, year, monthAry) fffff := calculationDingXingScore(gormDb, gormDbs, float64(vc.ReferenceScore)) deScore = deScore + fffff listggCont.Stroce = fffff listggCont.TimeClass = "1" // fmt.Printf("Score---半年---x----->%v\n", fffff) } else { //定量考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowDataLogType{}).Where("`month` IN ?", monthAry) fffG := calculationDingLiangScore(group, strconv.FormatInt(orgId, 10), v.Id, vc.Id, gormDb, vc.ReferenceScore, year, int64(bannian)) deScore = deScore + fffG listggCont.Stroce = fffG listggCont.TimeClass = "2" // fmt.Printf("Score---半年---l----->%v\n", fffG) } } else { deScore = deScore + float64(vc.ReferenceScore) // fmt.Printf("Score---半年---z----->%v\n", float64(vc.ReferenceScore)) } default: //月 if targetInfo.Type == 1 { //定性考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_month` = ?", vc.Id, orgId, year, month) gormDbs := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.ScoreFlow{}).Where("`sf_target_id` = ? AND `sf_duty_department` = ? AND `sf_year` = ? AND `sf_month` = ?", vc.Id, orgId, year, month) fffff := calculationDingXingScore(gormDb, gormDbs, float64(vc.ReferenceScore)) deScore = deScore + fffff listggCont.Stroce = fffff listggCont.TimeClass = "1" // fmt.Printf("Score---月---x----->%v\n", fffff) } else { //定量考核 gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowDataLogType{}).Where("`month` = ?", month) fffG := calculationDingLiangScore(group, strconv.FormatInt(orgId, 10), v.Id, vc.Id, gormDb, vc.ReferenceScore, year, int64(month)) deScore = deScore + fffG listggCont.Stroce = fffG listggCont.TimeClass = "2" // fmt.Printf("Score---月---l----->%v\n", fffG) } } } // fmt.Printf("deScore--name:%v--->%v\n", vc.Name, deScore) listgg = append(listgg, listggCont) // } } } jskd, _ := json.Marshal(listgg) fmt.Printf("listgg----->%v\n", string(jskd)) // fmt.Printf("sumScore----->%v-----sumScoreKS---->%v---->deScore---->%v\n", sumScore, sumScoreKS, deScore) return commonus.Decimal(deScore) } //计算定性得分 /*MMI021201 mm8888 @gormDb 要查询得语句 @referenceScore 指标权重 */ func calculationDingXingScore(gormDbJia *gorm.DB, gormDbJian *gorm.DB, referenceScore float64) float64 { // return 0 var jiaFenAry []TongjiFenShu gormDbJia.Select("sf_score,sf_count").Where("sf_plus_reduce_score = 1").Where("sf_reply IN (2,3)").Find(&jiaFenAry) //加分 var addSumScore float64 = 0 for _, jiav := range jiaFenAry { addSumScore = addSumScore + (jiav.Score * jiav.Count) } //减分 var scoreReduction float64 = 0 var jianFenAry []TongjiFenShu gormDbJian.Select("sf_score,sf_count").Where("sf_plus_reduce_score = 2").Where("sf_reply IN (2,3)").Find(&jianFenAry) for _, jianv := range jianFenAry { scoreReduction = scoreReduction + (jianv.Score * jianv.Count) // fmt.Printf("scoreReduction----->%v------->jianv.Score----->%v------->jianv.Count-------->%v\n", scoreReduction, jianv.Score, jianv.Count) } sumScore := scoreReduction - addSumScore shijiFEn := referenceScore - commonus.Decimal(sumScore/100) // fmt.Printf("定性分值---addSumScore----->%v---->scoreReduction----->%v---->sumScore----->%v---->shijiFEn----->%v---->referenceScore-->%v\n", addSumScore, scoreReduction, sumScore, shijiFEn, referenceScore) return shijiFEn } //计算定量得分 /*func calculationDingLiangScore(group, department, dimensionId, targetId string, gormDb *gorm.DB, referenceScore, year int64, monthType int64) @group 集团 @department 部门 @dimensionId 维度 @targetId 指标 @gormDb 要查询得语句 @referenceScore 指标权重 @year 年 @monthType 辅助 */ func calculationDingLiangScore(group, department, dimensionId, targetId string, gormDb *gorm.DB, referenceScore, year int64, monthType int64) float64 { var fldList []assessmentmodel.FlowDataLogType gormDb = gormDb.Where("`targetid` = ? AND `group` = ? AND `department` = ? AND `year` = ?", targetId, group, department, year) err := gormDb.Find(&fldList).Error if err != nil { return float64(referenceScore) } var actualScore float64 = 0 targetIdInt, _ := strconv.ParseInt(targetId, 10, 64) groupId, _ := strconv.ParseInt(group, 10, 64) departmentId, _ := strconv.ParseInt(department, 10, 64) dimensionIdInt, _ := strconv.ParseInt(dimensionId, 10, 64) if len(fldList) > 0 { for _, v := range fldList { var zeroprize float64 = 0 var allprize float64 = 0 var capping float64 = 0 var baseLineAry []FlowLogAllZreo jsonErr := json.Unmarshal([]byte(v.Baseline), &baseLineAry) if jsonErr == nil { for _, tbsv := range baseLineAry { if tbsv.TargetId == targetId { zeroprize = tbsv.Zeroprize allprize = tbsv.Allprize capping = tbsv.Capping } } } else { zeroprize, allprize, capping = GetPassRate(groupId, departmentId, dimensionIdInt, targetIdInt, year, monthType, 0) } if v.ScoringMethod == 1 { actualScoreVal, _, _, _, _ := commonus.CalculateScore(referenceScore, float64(v.Score), allprize, zeroprize, capping, 2) actualScore = actualScore + actualScoreVal } else { actualScore = actualScore + (float64(v.ScoringScore) / 100) } // fmt.Printf("actualScoreVal--actualScoreVal--->%v---referenceScore-->%v---Score-->%v---allprize-->%v---zeroprize-->%v----capping->%v\n", actualScoreVal, referenceScore, float64(v.Score), allprize, zeroprize, capping) } } // zeroPrize, allPrize, cappingPrize := GetAllZreoCapp(lastEvalId, groupId, departmentId, dimensionIdInt, targetIdInt, year, monthType, 0) // actualScore, _, _, _, _ := commonus.CalculateScore(referenceScore, scoreSum, allPrize, zeroPrize, cappingPrize, 2) return actualScore // return 0 }