作者 tangxvhui

更新

@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
@@ -12,7 +13,7 @@ import ( @@ -12,7 +13,7 @@ import (
12 13
13 // 超管直接修改考核结果分数 14 // 超管直接修改考核结果分数
14 // 修改周期考核的分数 15 // 修改周期考核的分数
15 -func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFinishScore) error { 16 +func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
16 transactionContext, err := factory.CreateTransactionContext(nil) 17 transactionContext, err := factory.CreateTransactionContext(nil)
17 if err != nil { 18 if err != nil {
18 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 19 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -60,13 +61,20 @@ func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFi @@ -60,13 +61,20 @@ func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFi
60 61
61 if len(evaluationFinishValue) == 0 { 62 if len(evaluationFinishValue) == 0 {
62 saveNewValue = true 63 saveNewValue = true
63 - 64 + evaluationFinishValue, err = srv.buildSummaryFinishValue(transactionContext, evaluationFinishData)
  65 + if err != nil {
  66 + return application.ThrowError(application.BUSINESS_ERROR, err.Error())
  67 + }
64 } 68 }
65 -  
66 - if len(evaluationFinishValue) == 0 {  
67 - //尝试获取目标人员的360评估、人资评估、自评的评估内容 69 + if saveNewValue {
  70 + // 重置评级汇总
  71 + for _, val := range evaluationFinishValue {
  72 + err = evaluationValueRepo.Save(val)
  73 + if err != nil {
  74 + return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
  75 + }
  76 + }
68 } 77 }
69 -  
70 scoreStr := fmt.Sprintf("%.2f", param.Score) 78 scoreStr := fmt.Sprintf("%.2f", param.Score)
71 evaluationFinishData.TotalScore = scoreStr 79 evaluationFinishData.TotalScore = scoreStr
72 evaluationFinishData.Status = domain.EvaluationCompleted 80 evaluationFinishData.Status = domain.EvaluationCompleted
@@ -75,14 +83,6 @@ func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFi @@ -75,14 +83,6 @@ func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFi
75 return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error()) 83 return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
76 } 84 }
77 85
78 - if saveNewValue {  
79 - for _, val := range evaluationFinishValue {  
80 - err = evaluationValueRepo.Save(val)  
81 - if err != nil {  
82 - return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())  
83 - }  
84 - }  
85 - }  
86 if err := transactionContext.CommitTransaction(); err != nil { 86 if err := transactionContext.CommitTransaction(); err != nil {
87 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 87 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
88 } 88 }
@@ -119,8 +119,9 @@ func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext @@ -119,8 +119,9 @@ func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext
119 break 119 break
120 } 120 }
121 } 121 }
122 - //使用上级评估的评估内容 122 +
123 if evaluationData != nil { 123 if evaluationData != nil {
  124 + //使用上级评估的评估内容
124 _, itemValue, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id}) 125 _, itemValue, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
125 if err != nil { 126 if err != nil {
126 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 127 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -141,40 +142,64 @@ func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext @@ -141,40 +142,64 @@ func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext
141 } 142 }
142 evaluationFinishValue = append(evaluationFinishValue, newItemValue) 143 evaluationFinishValue = append(evaluationFinishValue, newItemValue)
143 } 144 }
144 - return evaluationFinishValue, nil  
145 - }  
146 -  
147 - //使用360评估、人资评估、自评 构建考核结果的评估项内容  
148 - var itemValueBack []*domain.SummaryEvaluationValue  
149 - var summaryEvaluationId []int  
150 - for _, val := range evaluationList {  
151 - if val.Types == domain.Evaluation360 || val.Types == domain.EvaluationHrbp || val.Types == domain.EvaluationSelf {  
152 - summaryEvaluationId = append(summaryEvaluationId, val.Id) 145 + } else {
  146 + //使用360评估、人资评估、自评 构建考核结果的评估项内容
  147 + var itemValueBack []*domain.SummaryEvaluationValue
  148 + var summaryEvaluationId []int
  149 + for _, val := range evaluationList {
  150 + if val.Types == domain.Evaluation360 || val.Types == domain.EvaluationHrbp || val.Types == domain.EvaluationSelf {
  151 + summaryEvaluationId = append(summaryEvaluationId, val.Id)
  152 + }
153 } 153 }
154 - }  
155 - if len(summaryEvaluationId) > 0 {  
156 - _, itemValueBack, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": summaryEvaluationId})  
157 - if err != nil {  
158 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 154 + if len(summaryEvaluationId) > 0 {
  155 + _, itemValueBack, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": summaryEvaluationId})
  156 + if err != nil {
  157 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  158 + }
159 } 159 }
160 - }  
161 - tempSelf := map[int]*domain.SummaryEvaluationValue{}  
162 - temp360 := map[int]*domain.SummaryEvaluationValue{}  
163 - tempHRBP := map[int]*domain.SummaryEvaluationValue{}  
164 - for i := range itemValueBack {  
165 - it := itemValueBack[i]  
166 - switch it.Types {  
167 - case domain.EvaluationSelf:  
168 - tempSelf[it.EvaluationItemId] = it  
169 - case domain.Evaluation360:  
170 - temp360[it.EvaluationItemId] = it  
171 - case domain.EvaluationHrbp:  
172 - tempHRBP[it.EvaluationItemId] = it 160 + tempSelf := map[int]*domain.SummaryEvaluationValue{}
  161 + temp360 := map[int]*domain.SummaryEvaluationValue{}
  162 + tempHRBP := map[int]*domain.SummaryEvaluationValue{}
  163 + for i := range itemValueBack {
  164 + it := itemValueBack[i]
  165 + switch it.Types {
  166 + case domain.EvaluationSelf:
  167 + tempSelf[it.EvaluationItemId] = it
  168 + case domain.Evaluation360:
  169 + temp360[it.EvaluationItemId] = it
  170 + case domain.EvaluationHrbp:
  171 + tempHRBP[it.EvaluationItemId] = it
  172 + }
  173 + }
  174 + nowTime := time.Now()
  175 + for _, val := range itemUsed {
  176 + var newItemValue *domain.SummaryEvaluationValue
  177 + if val.EvaluatorId == 0 {
  178 + newItemValue = tempSelf[val.Id]
  179 + } else if val.EvaluatorId == -1 {
  180 + newItemValue = tempHRBP[val.Id]
  181 + } else {
  182 + newItemValue = temp360[val.Id]
  183 + }
  184 + if newItemValue == nil {
  185 + newItemValue = &domain.SummaryEvaluationValue{}
  186 + newItemValue.SetBlankValue(evaluationFinisih, val)
  187 + }
  188 + newItemValue.SummaryEvaluationId = 0
  189 + newItemValue.Id = 0
  190 + newItemValue.CreatedAt = nowTime
  191 + newItemValue.UpdatedAt = nowTime
  192 + evaluationFinishValue = append(evaluationFinishValue, newItemValue)
173 } 193 }
174 } 194 }
175 - for _, val := range itemUsed {  
176 - var newItemValue *domain.SummaryEvaluationValue  
177 - 195 + // 重置评级汇总
  196 + evaluationFinisih.TotalRating = nil
  197 + for i := range itemUsed {
  198 + evaluationFinisih.ResetTotalRating(itemUsed[i])
  199 + }
  200 + // 计算分数
  201 + if err := evaluationFinisih.EvaluationTotalScore(evaluationFinishValue); err != nil {
  202 + return evaluationFinishValue, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
178 } 203 }
179 return evaluationFinishValue, nil 204 return evaluationFinishValue, nil
180 } 205 }
@@ -849,55 +849,55 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu @@ -849,55 +849,55 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
849 // } 849 // }
850 850
851 // 修改周期考核的分数 851 // 修改周期考核的分数
852 -func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {  
853 - transactionContext, err := factory.CreateTransactionContext(nil)  
854 - if err != nil {  
855 - return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
856 - }  
857 - if err := transactionContext.StartTransaction(); err != nil {  
858 - return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
859 - }  
860 - defer func() {  
861 - _ = transactionContext.RollbackTransaction()  
862 - }()  
863 - // 只有超级管理员可以使用的功能  
864 - superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)  
865 - if err != nil {  
866 - return err  
867 - }  
868 - if superAdmin != domain.RoleTypeSuperAdmin {  
869 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
870 - } 852 +// func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
  853 +// transactionContext, err := factory.CreateTransactionContext(nil)
  854 +// if err != nil {
  855 +// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  856 +// }
  857 +// if err := transactionContext.StartTransaction(); err != nil {
  858 +// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  859 +// }
  860 +// defer func() {
  861 +// _ = transactionContext.RollbackTransaction()
  862 +// }()
  863 +// // 只有超级管理员可以使用的功能
  864 +// superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
  865 +// if err != nil {
  866 +// return err
  867 +// }
  868 +// if superAdmin != domain.RoleTypeSuperAdmin {
  869 +// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  870 +// }
871 871
872 - //获取周期评估任务finish  
873 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})  
874 - _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
875 - "id": []int{param.SummaryEvaluationId},  
876 - "companyId": param.CompanyId,  
877 - })  
878 - if err != nil {  
879 - return application.ThrowError(application.BUSINESS_ERROR, err.Error())  
880 - }  
881 - if len(evaluationList) == 0 {  
882 - return nil  
883 - }  
884 - evaluationData := evaluationList[0]  
885 - if evaluationData.Types != domain.EvaluationFinish {  
886 - return nil  
887 - }  
888 - scoreStr := fmt.Sprintf("%.2f", param.Score)  
889 - evaluationData.TotalScore = scoreStr  
890 - evaluationData.Status = domain.EvaluationCompleted  
891 - // evaluationData.CheckResult = domain.EvaluationCheckCompleted  
892 - err = evaluationRepo.Save(evaluationData)  
893 - if err != nil {  
894 - return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())  
895 - }  
896 - if err := transactionContext.CommitTransaction(); err != nil {  
897 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
898 - }  
899 - return nil  
900 -} 872 +// //获取周期评估任务finish
  873 +// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  874 +// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  875 +// "id": []int{param.SummaryEvaluationId},
  876 +// "companyId": param.CompanyId,
  877 +// })
  878 +// if err != nil {
  879 +// return application.ThrowError(application.BUSINESS_ERROR, err.Error())
  880 +// }
  881 +// if len(evaluationList) == 0 {
  882 +// return nil
  883 +// }
  884 +// evaluationData := evaluationList[0]
  885 +// if evaluationData.Types != domain.EvaluationFinish {
  886 +// return nil
  887 +// }
  888 +// scoreStr := fmt.Sprintf("%.2f", param.Score)
  889 +// evaluationData.TotalScore = scoreStr
  890 +// evaluationData.Status = domain.EvaluationCompleted
  891 +// // evaluationData.CheckResult = domain.EvaluationCheckCompleted
  892 +// err = evaluationRepo.Save(evaluationData)
  893 +// if err != nil {
  894 +// return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
  895 +// }
  896 +// if err := transactionContext.CommitTransaction(); err != nil {
  897 +// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  898 +// }
  899 +// return nil
  900 +// }
901 901
902 // GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表 902 // GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表
903 func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) { 903 func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) {