作者 tangxvhui

修改评估值的填充

@@ -461,12 +461,13 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu @@ -461,12 +461,13 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
461 if err != nil { 461 if err != nil {
462 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 462 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
463 } 463 }
464 - 464 + evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
465 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 465 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
466 for _, v := range itemList { 466 for _, v := range itemList {
467 newValue := &domain.SummaryEvaluationValue{} 467 newValue := &domain.SummaryEvaluationValue{}
468 newValue.SetBlankValue(evaluationData, v) 468 newValue.SetBlankValue(evaluationData, v)
469 evaluationValueMap[v.Id] = newValue 469 evaluationValueMap[v.Id] = newValue
  470 + evaluationItemMap[v.Id] = v
470 } 471 }
471 for _, v := range itemValueList { 472 for _, v := range itemValueList {
472 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok { 473 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
@@ -479,11 +480,13 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu @@ -479,11 +480,13 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
479 if !ok { 480 if !ok {
480 continue 481 continue
481 } 482 }
  483 + evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
  484 + if !ok {
  485 + continue
  486 + }
482 updatedData.UpdatedAt = nowTime 487 updatedData.UpdatedAt = nowTime
483 - updatedData.Value = v.Value  
484 - updatedData.Remark = v.Remark  
485 - //计算得分  
486 - err = updatedData.SummaryEvaluationScore() 488 + //填充评估填写值
  489 + err = updatedData.FillValue(evaluationItem, v.Value, v.Remark)
487 if err != nil { 490 if err != nil {
488 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 491 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
489 } 492 }
@@ -845,11 +848,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -845,11 +848,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
845 if err != nil { 848 if err != nil {
846 return nil, err 849 return nil, err
847 } 850 }
  851 + evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
848 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} 852 evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
849 for _, v := range itemList { 853 for _, v := range itemList {
850 newValue := &domain.SummaryEvaluationValue{} 854 newValue := &domain.SummaryEvaluationValue{}
  855 + //初始一个空白的value
851 newValue.SetBlankValue(evaluationData, v) 856 newValue.SetBlankValue(evaluationData, v)
852 evaluationValueMap[v.Id] = newValue 857 evaluationValueMap[v.Id] = newValue
  858 + evaluationItemMap[v.Id] = v
853 } 859 }
854 for _, v := range itemValueList { 860 for _, v := range itemValueList {
855 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok { 861 if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
@@ -862,18 +868,23 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -862,18 +868,23 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
862 if !ok { 868 if !ok {
863 continue 869 continue
864 } 870 }
  871 + evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
  872 + if !ok {
  873 + continue
  874 + }
865 if defaultValue, ok := hrbpOr360ItemValue[v.EvaluationItemId]; ok { 875 if defaultValue, ok := hrbpOr360ItemValue[v.EvaluationItemId]; ok {
866 - updatedData.Value = defaultValue.Value 876 + //填充值
  877 + err = updatedData.FillValue(evaluationItem, defaultValue.Value, v.Remark)
  878 + if err != nil {
  879 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  880 + }
867 } else { 881 } else {
868 - updatedData.Value = v.Value 882 + err = updatedData.FillValue(evaluationItem, v.Value, v.Remark)
  883 + if err != nil {
  884 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  885 + }
869 } 886 }
870 updatedData.UpdatedAt = nowTime 887 updatedData.UpdatedAt = nowTime
871 - updatedData.Remark = v.Remark  
872 - //计算得分  
873 - err = updatedData.SummaryEvaluationScore()  
874 - if err != nil {  
875 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
876 - }  
877 } 888 }
878 evaluationValueList := []*domain.SummaryEvaluationValue{} 889 evaluationValueList := []*domain.SummaryEvaluationValue{}
879 for _, v := range evaluationValueMap { 890 for _, v := range evaluationValueMap {
@@ -16,6 +16,7 @@ type SummaryEvaluationValue struct { @@ -16,6 +16,7 @@ type SummaryEvaluationValue struct {
16 Types EvaluationType `json:"types"` //评估类型 16 Types EvaluationType `json:"types"` //评估类型
17 Remark string `json:"remark"` //填写的内容反馈 17 Remark string `json:"remark"` //填写的内容反馈
18 Weight float64 `json:"weight"` //"权重" 18 Weight float64 `json:"weight"` //"权重"
  19 + Rating RatingLevel `json:"rating" ` //评级时的填写值
19 CreatedAt time.Time `json:"createdAt"` //数据创建时间 20 CreatedAt time.Time `json:"createdAt"` //数据创建时间
20 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 21 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
21 DeletedAt *time.Time `json:"deletedAt"` //数据删除时间 22 DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
@@ -45,35 +46,62 @@ func (itemValue *SummaryEvaluationValue) SumScore() (float64, error) { @@ -45,35 +46,62 @@ func (itemValue *SummaryEvaluationValue) SumScore() (float64, error) {
45 if len(itemValue.Value) == 0 { 46 if len(itemValue.Value) == 0 {
46 return 0, nil 47 return 0, nil
47 } 48 }
  49 + if itemValue.Weight == 0 {
  50 + //使用评级
  51 + return 0, nil
  52 + }
48 if itemValue.Types == EvaluationHrbp { 53 if itemValue.Types == EvaluationHrbp {
  54 + //hrbp 填写值就是得分
49 valueFloat, err := strconv.ParseFloat(itemValue.Value, 64) 55 valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
50 if err != nil { 56 if err != nil {
51 return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value) 57 return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
52 } 58 }
53 return valueFloat, nil 59 return valueFloat, nil
54 } 60 }
55 -  
56 - if itemValue.Weight == 0 {  
57 - return 0, nil  
58 - }  
59 valueFloat, err := strconv.ParseFloat(itemValue.Value, 64) 61 valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
60 if err != nil { 62 if err != nil {
61 return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value) 63 return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
62 } 64 }
63 - //计算方式 65 + //得分计算方式
64 score := itemValue.Weight * valueFloat 66 score := itemValue.Weight * valueFloat
65 return score, nil 67 return score, nil
66 } 68 }
67 69
68 // 初始化一个空的value 70 // 初始化一个空的value
69 func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) { 71 func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) {
  72 + itemValue.Types = evaluation.Types
70 itemValue.EvaluationItemId = item.Id 73 itemValue.EvaluationItemId = item.Id
71 itemValue.SummaryEvaluationId = evaluation.Id 74 itemValue.SummaryEvaluationId = evaluation.Id
72 itemValue.Value = "" 75 itemValue.Value = ""
73 itemValue.Score = "" 76 itemValue.Score = ""
74 itemValue.Remark = "" 77 itemValue.Remark = ""
75 - itemValue.Types = evaluation.Types  
76 itemValue.Weight = item.Weight 78 itemValue.Weight = item.Weight
77 itemValue.CreatedAt = time.Now() 79 itemValue.CreatedAt = time.Now()
78 itemValue.UpdatedAt = time.Now() 80 itemValue.UpdatedAt = time.Now()
79 } 81 }
  82 +
  83 +// 填充评估的内容
  84 +func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error {
  85 + itemValue.Remark = remark
  86 + itemValue.Value = value
  87 + if item.Weight == 0 {
  88 + //使用评级
  89 + if len(value) == 0 {
  90 + return nil
  91 + }
  92 + var ratingValue *RatingLevel
  93 + for _, v := range item.Rule.Rating.Levels {
  94 + if v.Code == value {
  95 + ratingValue = v
  96 + }
  97 + }
  98 + if (ratingValue == nil) && len(value) > 0 {
  99 + return fmt.Errorf("条目%d系评级值异常", itemValue.EvaluationItemId)
  100 + }
  101 + itemValue.Rating = *ratingValue
  102 + return nil
  103 + }
  104 + //使用评分的形式
  105 + err := itemValue.SummaryEvaluationScore()
  106 + return err
  107 +}
@@ -1210,7 +1210,7 @@ from staff_assess_content @@ -1210,7 +1210,7 @@ from staff_assess_content
1210 join staff_assess on staff_assess_content.staff_assess_id = staff_assess.id 1210 join staff_assess on staff_assess_content.staff_assess_id = staff_assess.id
1211 where 1=1 and staff_assess.deleted_at isnull 1211 where 1=1 and staff_assess.deleted_at isnull
1212 and target_user ->>'userId'='?' 1212 and target_user ->>'userId'='?'
1213 -and staff_assess."types" = '?' 1213 +and staff_assess."types" = ?
1214 and staff_assess_content.level_value notnull 1214 and staff_assess_content.level_value notnull
1215 and staff_assess.cycle_id =? 1215 and staff_assess.cycle_id =?
1216 group by level_value,category,"name" ` 1216 group by level_value,category,"name" `
1 package models 1 package models
2 2
3 -import "time" 3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  7 +)
4 8
5 // 周期综合评估填写的内容 9 // 周期综合评估填写的内容
6 type SummaryEvaluationValue struct { 10 type SummaryEvaluationValue struct {
7 - tableName struct{} `comment:"周期综合评估填写的内容" pg:"summary_evaluation_value"`  
8 - Id int //  
9 - EvaluationItemId int //评估条目的id  
10 - SummaryEvaluationId int //综合评估任务(SummaryEvaluation)的id  
11 - Value string //评估填写的评分  
12 - Score string //评定得分  
13 - Types int //评估类型  
14 - Remark string //填写的内容反馈  
15 - CreatedAt time.Time //数据创建时间  
16 - UpdatedAt time.Time //数据更新时间  
17 - DeletedAt *time.Time //数据删除时间 11 + tableName struct{} `comment:"周期综合评估填写的内容" pg:"summary_evaluation_value"`
  12 + Id int //
  13 + EvaluationItemId int //评估条目的id
  14 + SummaryEvaluationId int //综合评估任务(SummaryEvaluation)的id
  15 + Value string //评估填写的评分
  16 + Score string //评定得分
  17 + Types int //评估类型
  18 + Weight float64 //权重
  19 + Rating domain.RatingLevel //评级填写值
  20 + Remark string //填写的内容反馈
  21 + CreatedAt time.Time //数据创建时间
  22 + UpdatedAt time.Time //数据更新时间
  23 + DeletedAt *time.Time //数据删除时间
18 } 24 }
@@ -30,6 +30,8 @@ func (repo *SummaryEvaluationValueRepository) TransformToDomain(d *models.Summar @@ -30,6 +30,8 @@ func (repo *SummaryEvaluationValueRepository) TransformToDomain(d *models.Summar
30 Score: d.Score, 30 Score: d.Score,
31 Types: domain.EvaluationType(d.Types), 31 Types: domain.EvaluationType(d.Types),
32 Remark: d.Remark, 32 Remark: d.Remark,
  33 + Weight: d.Weight,
  34 + Rating: d.Rating,
33 CreatedAt: d.CreatedAt, 35 CreatedAt: d.CreatedAt,
34 UpdatedAt: d.UpdatedAt, 36 UpdatedAt: d.UpdatedAt,
35 DeletedAt: d.DeletedAt, 37 DeletedAt: d.DeletedAt,
@@ -44,6 +46,8 @@ func (repo *SummaryEvaluationValueRepository) Save(param *domain.SummaryEvaluati @@ -44,6 +46,8 @@ func (repo *SummaryEvaluationValueRepository) Save(param *domain.SummaryEvaluati
44 Value: param.Value, 46 Value: param.Value,
45 Score: param.Score, 47 Score: param.Score,
46 Types: int(param.Types), 48 Types: int(param.Types),
  49 + Weight: param.Weight,
  50 + Rating: param.Rating,
47 Remark: param.Remark, 51 Remark: param.Remark,
48 CreatedAt: param.CreatedAt, 52 CreatedAt: param.CreatedAt,
49 UpdatedAt: param.UpdatedAt, 53 UpdatedAt: param.UpdatedAt,