作者 tangxvhui

更改 评级数量 汇总方式

  1 +package service
  2 +
  3 +import (
  4 + "github.com/xuri/excelize/v2"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
  6 +)
  7 +
  8 +// 导出数据
  9 +// 综合管理-周期评估
  10 +func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.QueryEvaluationList) (*excelize.File, error) {
  11 + return nil, nil
  12 +}
@@ -463,11 +463,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu @@ -463,11 +463,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
463 } 463 }
464 evaluationItemMap := map[int]*domain.EvaluationItemUsed{} 464 evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
465 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 465 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
  466 + evaluationData.TotalRating = nil //清空评级数量统计
466 for _, v := range itemList { 467 for _, v := range itemList {
467 newValue := &domain.SummaryEvaluationValue{} 468 newValue := &domain.SummaryEvaluationValue{}
468 newValue.SetBlankValue(evaluationData, v) 469 newValue.SetBlankValue(evaluationData, v)
469 evaluationValueMap[v.Id] = newValue 470 evaluationValueMap[v.Id] = newValue
470 evaluationItemMap[v.Id] = v 471 evaluationItemMap[v.Id] = v
  472 + //重置计数
  473 + evaluationData.ResetTotalRating(v)
471 } 474 }
472 for _, v := range itemValueList { 475 for _, v := range itemValueList {
473 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok { 476 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
@@ -847,12 +850,15 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -847,12 +850,15 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
847 } 850 }
848 evaluationItemMap := map[int]*domain.EvaluationItemUsed{} 851 evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
849 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 852 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
  853 + evaluationData.TotalRating = nil //清空评级数量统计
850 for _, v := range itemList { 854 for _, v := range itemList {
851 newValue := &domain.SummaryEvaluationValue{} 855 newValue := &domain.SummaryEvaluationValue{}
852 //初始一个空白的value 856 //初始一个空白的value
853 newValue.SetBlankValue(evaluationData, v) 857 newValue.SetBlankValue(evaluationData, v)
854 evaluationValueMap[v.Id] = newValue 858 evaluationValueMap[v.Id] = newValue
855 evaluationItemMap[v.Id] = v 859 evaluationItemMap[v.Id] = v
  860 + //重置评级统计数量
  861 + evaluationData.ResetTotalRating(v)
856 } 862 }
857 for _, v := range itemValueList { 863 for _, v := range itemValueList {
858 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok { 864 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
@@ -2,6 +2,9 @@ package service @@ -2,6 +2,9 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strings"
  6 + "time"
  7 +
5 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 9 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
@@ -10,8 +13,6 @@ import ( @@ -10,8 +13,6 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
13 - "strings"  
14 - "time"  
15 ) 16 )
16 17
17 // Evaluation360List 获取360综评列表 18 // Evaluation360List 获取360综评列表
@@ -391,11 +392,14 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua @@ -391,11 +392,14 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
391 392
392 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 393 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
393 evaluationItemMap := map[int]*domain.EvaluationItemUsed{} 394 evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
  395 + summaryEvaluation.TotalRating = nil //清空评级数量统计
394 for i, v := range itemList { 396 for i, v := range itemList {
395 newValue := &domain.SummaryEvaluationValue{} 397 newValue := &domain.SummaryEvaluationValue{}
396 newValue.SetBlankValue(summaryEvaluation, v) 398 newValue.SetBlankValue(summaryEvaluation, v)
397 evaluationValueMap[v.Id] = newValue 399 evaluationValueMap[v.Id] = newValue
398 evaluationItemMap[v.Id] = itemList[i] 400 evaluationItemMap[v.Id] = itemList[i]
  401 + //重置计数
  402 + summaryEvaluation.ResetTotalRating(v)
399 } 403 }
400 for _, v := range itemValueList { 404 for _, v := range itemValueList {
401 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok { 405 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
@@ -739,12 +743,14 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -739,12 +743,14 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
739 743
740 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 744 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
741 evaluationItemMap := map[int]*domain.EvaluationItemUsed{} 745 evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
742 - 746 + summaryEvaluation.TotalRating = nil //清空评级数量统计
743 for i, v := range itemList { 747 for i, v := range itemList {
744 newValue := &domain.SummaryEvaluationValue{} 748 newValue := &domain.SummaryEvaluationValue{}
745 newValue.SetBlankValue(summaryEvaluation, v) 749 newValue.SetBlankValue(summaryEvaluation, v)
746 evaluationValueMap[v.Id] = newValue 750 evaluationValueMap[v.Id] = newValue
747 evaluationItemMap[v.Id] = itemList[i] 751 evaluationItemMap[v.Id] = itemList[i]
  752 + //重置计数
  753 + summaryEvaluation.ResetTotalRating(v)
748 } 754 }
749 for _, v := range itemValueList { 755 for _, v := range itemValueList {
750 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok { 756 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
@@ -7,25 +7,32 @@ import ( @@ -7,25 +7,32 @@ import (
7 7
8 // 周综合评估 8 // 周综合评估
9 type SummaryEvaluation struct { 9 type SummaryEvaluation struct {
10 - Id int  
11 - CompanyId int //公司id  
12 - EvaluationProjectId int //对应的项目id  
13 - EvaluationProjectName string //对应的项目名称  
14 - CycleId int64 //对应的周期id  
15 - CycleName string //对应的周期名称  
16 - NodeId int //  
17 - TargetUser StaffDesc //被评估的目标用户,被执行的  
18 - TargetDepartment []StaffDepartment //被评估的目标用户所在的部门  
19 - Executor StaffDesc //填写评估的用户,执行人  
20 - Types EvaluationType //评估类型  
21 - Status EvaluationStatus //评估的填写状态  
22 - CheckResult EvaluationCheckResult //被执行的人确认评估结果  
23 - BeginTime time.Time //开始时间  
24 - EndTime time.Time //截止时间  
25 - TotalScore string //最终上级评估得分.  
26 - CreatedAt time.Time //数据创建时间  
27 - UpdatedAt time.Time //数据更新时间  
28 - DeletedAt *time.Time //数据删除时间 10 + Id int `json:"id"`
  11 + CompanyId int `json:"companyId"` //公司id
  12 + EvaluationProjectId int `json:"evaluationProjectId"` //对应的项目id
  13 + EvaluationProjectName string `json:"evaluationProjectName"` //对应的项目名称
  14 + CycleId int64 `json:"cycleId"` //对应的周期id
  15 + CycleName string `json:"cycleName"` //对应的周期名称
  16 + NodeId int `json:"nodeId"` //对应的节点id
  17 + TargetUser StaffDesc `json:"targetUser"` //被评估的目标用户,被执行的
  18 + TargetDepartment []StaffDepartment `json:"targetDepartment"` //被评估的目标用户所在的部门
  19 + Executor StaffDesc `json:"executor"` //填写评估的用户,执行人
  20 + Types EvaluationType `json:"types"` //评估类型
  21 + Status EvaluationStatus `json:"status"` //评估的填写状态
  22 + CheckResult EvaluationCheckResult `json:"checkResult"` //被执行的人确认评估结果
  23 + BeginTime time.Time `json:"beginTime"` //开始时间
  24 + EndTime time.Time `json:"endTime"` //截止时间
  25 + TotalScore string `json:"totalScore"` //最终上级评估得分.
  26 + TotalRating []RatingCodeNumber `json:"totalRating"` //汇总各个评级的数量
  27 + CreatedAt time.Time `json:"createdAt"` //数据创建时间
  28 + UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
  29 + DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
  30 +}
  31 +
  32 +// 各个评级的数量
  33 +type RatingCodeNumber struct {
  34 + Code string `json:"code"`
  35 + Number int `json:"number"`
29 } 36 }
30 37
31 type EvaluationType int //综合评估类型 38 type EvaluationType int //综合评估类型
@@ -64,13 +71,52 @@ type SummaryEvaluationRepository interface { @@ -64,13 +71,52 @@ type SummaryEvaluationRepository interface {
64 func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error { 71 func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error {
65 var totalScore float64 72 var totalScore float64
66 for _, v := range valueList { 73 for _, v := range valueList {
67 - score, err := v.SumScore()  
68 - if err != nil {  
69 - return err  
70 - } 74 + if v.Weight == 0 {
  75 + evaluation.SumRatingCode(v.Rating.Code)
  76 + } else {
  77 + score, err := v.SumScore()
  78 + if err != nil {
  79 + return err
  80 + }
71 81
72 - totalScore += score 82 + totalScore += score
  83 + }
73 } 84 }
74 evaluation.TotalScore = fmt.Sprintf("%.1f", totalScore) 85 evaluation.TotalScore = fmt.Sprintf("%.1f", totalScore)
75 return nil 86 return nil
76 } 87 }
  88 +
  89 +// 重置评级统计数量
  90 +func (evaluation *SummaryEvaluation) ResetTotalRating(param *EvaluationItemUsed) {
  91 + if param.Weight > 0 {
  92 + return
  93 + }
  94 + if len(evaluation.TotalRating) == 0 {
  95 + evaluation.TotalRating = make([]RatingCodeNumber, 0)
  96 + }
  97 + for _, v := range param.Rule.Rating.Levels {
  98 + isExist := false
  99 + for i2, v2 := range evaluation.TotalRating {
  100 + if v.Code == v2.Code {
  101 + isExist = true
  102 + evaluation.TotalRating[i2].Number = 0
  103 + }
  104 + }
  105 + if !isExist {
  106 + evaluation.TotalRating = append(evaluation.TotalRating, RatingCodeNumber{
  107 + Code: v.Code,
  108 + Number: 0,
  109 + })
  110 + }
  111 + }
  112 +}
  113 +
  114 +// 增加对应评级的数量
  115 +func (evaluation *SummaryEvaluation) SumRatingCode(code string) {
  116 + for i := range evaluation.TotalRating {
  117 + if evaluation.TotalRating[i].Code == code {
  118 + evaluation.TotalRating[i].Number += 1
  119 + break
  120 + }
  121 + }
  122 +}
@@ -8,23 +8,25 @@ import ( @@ -8,23 +8,25 @@ import (
8 8
9 // 周综合评估 9 // 周综合评估
10 type SummaryEvaluation struct { 10 type SummaryEvaluation struct {
11 - tableName struct{} `comment:"周综合评估" pg:"summary_evaluation"`  
12 - Id int `pg:",pk"`  
13 - CompanyId int //公司id  
14 - EvaluationProjectId int //对应的项目id  
15 - EvaluationProjectName string //对应的项目名称  
16 - CycleId int64 //对应的周期id  
17 - CycleName string //对应的周期名称  
18 - TargetUser domain.StaffDesc //被评估的目标用户,被执行的  
19 - TargetDepartment []domain.StaffDepartment //被评估的目标用户所在的部门  
20 - Executor domain.StaffDesc //填写评估的用户,执行人  
21 - Types int //评估类型  
22 - Status string //评估的填写状态  
23 - CheckResult string //被执行的人确认评估结果  
24 - BeginTime time.Time //开始时间  
25 - EndTime time.Time //截止时间  
26 - TotalScore string //最终上级评估得分.  
27 - CreatedAt time.Time //数据创建时间  
28 - UpdatedAt time.Time //数据更新时间  
29 - DeletedAt *time.Time //数据删除时间 11 + tableName struct{} `comment:"周综合评估" pg:"summary_evaluation"`
  12 + Id int `pg:",pk"`
  13 + CompanyId int //公司id
  14 + EvaluationProjectId int //对应的项目id
  15 + EvaluationProjectName string //对应的项目名称
  16 + CycleId int64 //对应的周期id
  17 + CycleName string //对应的周期名称
  18 + NodeId int //对应的节点id
  19 + TargetUser domain.StaffDesc //被评估的目标用户,被执行的
  20 + TargetDepartment []domain.StaffDepartment //被评估的目标用户所在的部门
  21 + Executor domain.StaffDesc //填写评估的用户,执行人
  22 + Types int //评估类型
  23 + Status string //评估的填写状态
  24 + CheckResult string //被执行的人确认评估结果
  25 + BeginTime time.Time //开始时间
  26 + EndTime time.Time //截止时间
  27 + TotalScore string //最终上级评估得分.
  28 + TotalRating []domain.RatingCodeNumber //汇总评级
  29 + CreatedAt time.Time //数据创建时间
  30 + UpdatedAt time.Time //数据更新时间
  31 + DeletedAt *time.Time //数据删除时间
30 } 32 }
@@ -38,6 +38,7 @@ func (repo *SummaryEvaluationRepository) TransformToDomain(d *models.SummaryEval @@ -38,6 +38,7 @@ func (repo *SummaryEvaluationRepository) TransformToDomain(d *models.SummaryEval
38 BeginTime: d.BeginTime, 38 BeginTime: d.BeginTime,
39 EndTime: d.EndTime, 39 EndTime: d.EndTime,
40 TotalScore: d.TotalScore, 40 TotalScore: d.TotalScore,
  41 + TotalRating: d.TotalRating,
41 CreatedAt: d.CreatedAt, 42 CreatedAt: d.CreatedAt,
42 UpdatedAt: d.UpdatedAt, 43 UpdatedAt: d.UpdatedAt,
43 DeletedAt: d.DeletedAt, 44 DeletedAt: d.DeletedAt,
@@ -52,6 +53,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e @@ -52,6 +53,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e
52 EvaluationProjectName: param.EvaluationProjectName, 53 EvaluationProjectName: param.EvaluationProjectName,
53 CycleId: param.CycleId, 54 CycleId: param.CycleId,
54 CycleName: param.CycleName, 55 CycleName: param.CycleName,
  56 + NodeId: param.NodeId,
55 TargetUser: param.TargetUser, 57 TargetUser: param.TargetUser,
56 TargetDepartment: param.TargetDepartment, 58 TargetDepartment: param.TargetDepartment,
57 Executor: param.Executor, 59 Executor: param.Executor,
@@ -61,6 +63,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e @@ -61,6 +63,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e
61 BeginTime: param.BeginTime, 63 BeginTime: param.BeginTime,
62 EndTime: param.EndTime, 64 EndTime: param.EndTime,
63 TotalScore: param.TotalScore, 65 TotalScore: param.TotalScore,
  66 + TotalRating: param.TotalRating,
64 CreatedAt: param.CreatedAt, 67 CreatedAt: param.CreatedAt,
65 UpdatedAt: param.UpdatedAt, 68 UpdatedAt: param.UpdatedAt,
66 DeletedAt: param.DeletedAt, 69 DeletedAt: param.DeletedAt,