作者 tangxvhui

更新评估的填写规则

1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
  5 + "strings"
  6 + "time"
  7 +
4 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
@@ -10,6 +14,117 @@ import ( @@ -10,6 +14,117 @@ import (
10 ) 14 )
11 15
12 // EditEvaluation360 编辑提交360综评 16 // EditEvaluation360 编辑提交360综评
  17 +// func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
  18 +// transactionContext, err := factory.CreateTransactionContext(nil)
  19 +// if err != nil {
  20 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 +// }
  22 +// if err := transactionContext.StartTransaction(); err != nil {
  23 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 +// }
  25 +// defer func() {
  26 +// _ = transactionContext.RollbackTransaction()
  27 +// }()
  28 +// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  29 +// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  30 +// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  31 +
  32 +// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
  33 +// if err != nil {
  34 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  35 +// }
  36 +// if summaryEvaluation.Executor.UserId != param.ExecutorId {
  37 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  38 +// }
  39 +// if summaryEvaluation.CompanyId != param.CompanyId {
  40 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  41 +// }
  42 +// // 按照 被评估人加锁
  43 +// lock := xredis.NewLockSummaryEvaluation(summaryEvaluation.TargetUser.UserId)
  44 +// err = lock.Lock()
  45 +// if err != nil {
  46 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  47 +// }
  48 +// defer func() {
  49 +// lock.UnLock()
  50 +// }()
  51 +// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  52 +// "targetUserId": summaryEvaluation.TargetUser.UserId,
  53 +// "typesList": []int{int(domain.EvaluationFinish)},
  54 +// "cycleId": summaryEvaluation.CycleId,
  55 +// "limit": 1,
  56 +// })
  57 +// if err != nil {
  58 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  59 +// }
  60 +// // 如果目标员工已经确认考核结果,就不能在进行评估编辑
  61 +// if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
  62 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
  63 +// }
  64 +
  65 +// // 自评评估内容(自评模板、筛选项目评估人)
  66 +// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
  67 +// "evaluationProjectId": summaryEvaluation.EvaluationProjectId,
  68 +// "nodeType": domain.LinkNodeSelfAssessment,
  69 +// "evaluatorId": param.ExecutorId,
  70 +// })
  71 +// if err != nil {
  72 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  73 +// }
  74 +
  75 +// // 评估内容对应的分数
  76 +// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
  77 +// if err != nil {
  78 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 +// }
  80 +
  81 +// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
  82 +// if err != nil {
  83 +// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  84 +// }
  85 +// if !param.IsTemporary {
  86 +// //变更评估状态为已填写
  87 +// summaryEvaluation.Status = domain.EvaluationCompleted
  88 +// //删除旧的填写值,使用新的填写内容
  89 +// err = itemValueRepo.RemoveBySummaryEvaluationId(summaryEvaluation.Id)
  90 +// if err != nil {
  91 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  92 +// }
  93 +// for _, val := range itemValueList {
  94 +// val.Id = 0
  95 +// }
  96 +// }
  97 +
  98 +// //保存填写值
  99 +// for _, v := range itemValueList {
  100 +// v.Id = 0
  101 +// err = itemValueRepo.Save(v)
  102 +// if err != nil {
  103 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  104 +// }
  105 +// }
  106 +// //保存填写值
  107 +// err = evaluationRepo.Save(summaryEvaluation)
  108 +// if err != nil {
  109 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  110 +// }
  111 +// if !param.IsTemporary {
  112 +// err = srv.AfterCompletedEvaluation360Hrbp(transactionContext, summaryEvaluation, itemValueList)
  113 +// if err != nil {
  114 +// return nil, err
  115 +// }
  116 +// }
  117 +// if err := transactionContext.CommitTransaction(); err != nil {
  118 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  119 +// }
  120 +// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
  121 +// return map[string][]adapter.EvaluationItemAdapter{
  122 +// "evaluationItems": itemValueAdapter,
  123 +// }, nil
  124 +// }
  125 +
  126 +// EditEvaluation360 编辑提交360综评
  127 +// 填写规则变更。v2
13 func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) { 128 func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
14 transactionContext, err := factory.CreateTransactionContext(nil) 129 transactionContext, err := factory.CreateTransactionContext(nil)
15 if err != nil { 130 if err != nil {
@@ -57,6 +172,9 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua @@ -57,6 +172,9 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
57 if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted { 172 if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
58 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!") 173 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
59 } 174 }
  175 + if ok := summaryEvaluation.EndTime.Before(time.Now()); ok {
  176 + return nil, application.ThrowError(application.BUSINESS_ERROR, "评估时间已截止")
  177 + }
60 178
61 // 自评评估内容(自评模板、筛选项目评估人) 179 // 自评评估内容(自评模板、筛选项目评估人)
62 _, itemList, err := itemUsedRepo.Find(map[string]interface{}{ 180 _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
@@ -74,10 +192,56 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua @@ -74,10 +192,56 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
74 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 192 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
75 } 193 }
76 194
77 - err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary) 195 + //更新填写值
  196 + var evaluationValueSlice []*domain.SummaryEvaluationValue // 提交的填写值
  197 + {
  198 +
  199 + evaluationItemMap := map[int]*domain.EvaluationItemUsed{} // 需要填写那些项 Id=>&domain.EvaluationItemUsed{}
  200 + evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} // 提交的填写值 EvaluationItemId=>&domain.domain.SummaryEvaluationValue{}
  201 + summaryEvaluation.TotalRating = nil // 清空评级数量统计
  202 + // 按照需要填写那些项 设置SummaryEvaluationValue的空白值
  203 + for _, v := range itemList {
  204 + newValue := &domain.SummaryEvaluationValue{}
  205 + newValue.SetBlankValue(summaryEvaluation, v)
  206 + evaluationValueMap[v.Id] = newValue
  207 + evaluationItemMap[v.Id] = v
  208 + evaluationValueSlice = append(evaluationValueSlice, newValue)
  209 + }
  210 + //如果存在旧值
  211 + //新值的id 替换为旧值id
  212 + for _, v := range itemValueList {
  213 + if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
  214 + mValue.Id = v.Id
  215 + }
  216 + }
  217 + //填入提交的更新值
  218 + for _, v := range param.EvaluationItems {
  219 + v.Value = strings.TrimSpace(v.Value)
  220 + newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
  221 + if !ok {
  222 + continue
  223 + }
  224 + evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
  225 + if !ok {
  226 + continue
  227 + }
  228 + if !param.IsTemporary {
  229 + //除了综合自评,其他的评估任务 评估项直接全部按必填项处理
  230 + if len(v.Value) == 0 {
  231 + e := fmt.Sprintf("%s-%s 未填写", evaluationItem.Category, evaluationItem.Name)
  232 + return nil, application.ThrowError(application.BUSINESS_ERROR, e)
  233 + }
  234 + }
  235 + //填充评估填写值
  236 + newItemValue.Remark = v.Remark
  237 + err := summaryEvaluation.FillItemValue(evaluationItem, newItemValue, v.Value)
78 if err != nil { 238 if err != nil {
79 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 239 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
80 } 240 }
  241 + }
  242 + summaryEvaluation.EvaluationTotalScore(evaluationValueSlice)
  243 + }
  244 +
81 if !param.IsTemporary { 245 if !param.IsTemporary {
82 //变更评估状态为已填写 246 //变更评估状态为已填写
83 summaryEvaluation.Status = domain.EvaluationCompleted 247 summaryEvaluation.Status = domain.EvaluationCompleted
@@ -86,13 +250,13 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua @@ -86,13 +250,13 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
86 if err != nil { 250 if err != nil {
87 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 251 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
88 } 252 }
89 - for _, val := range itemValueList { 253 + for _, val := range evaluationValueSlice {
90 val.Id = 0 254 val.Id = 0
91 } 255 }
92 } 256 }
93 257
94 //保存填写值 258 //保存填写值
95 - for _, v := range itemValueList { 259 + for _, v := range evaluationValueSlice {
96 v.Id = 0 260 v.Id = 0
97 err = itemValueRepo.Save(v) 261 err = itemValueRepo.Save(v)
98 if err != nil { 262 if err != nil {
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
  5 + "strings"
4 "time" 6 "time"
5 7
6 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
@@ -15,6 +17,226 @@ import ( @@ -15,6 +17,226 @@ import (
15 ) 17 )
16 18
17 // EditEvaluationHRBP 编辑提交人资综评 19 // EditEvaluationHRBP 编辑提交人资综评
  20 +// func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
  21 +// transactionContext, err := factory.CreateTransactionContext(nil)
  22 +// if err != nil {
  23 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 +// }
  25 +// if err := transactionContext.StartTransaction(); err != nil {
  26 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  27 +// }
  28 +// defer func() {
  29 +// _ = transactionContext.RollbackTransaction()
  30 +// }()
  31 +
  32 +// userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  33 +// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  34 +// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  35 +// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  36 +
  37 +// // 必须是HRBP权限的人才能编辑操作
  38 +// hrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.ExecutorId)
  39 +// if err != nil {
  40 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  41 +// }
  42 +// if hrbp != domain.RoleTypeSystem {
  43 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  44 +// }
  45 +
  46 +// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
  47 +// if err != nil {
  48 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  49 +// }
  50 +// if summaryEvaluation.Types != domain.EvaluationHrbp {
  51 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  52 +// }
  53 +// if summaryEvaluation.CompanyId != param.CompanyId {
  54 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  55 +// }
  56 +// // 按照 被评估人加锁
  57 +// lock := xredis.NewLockSummaryEvaluation(summaryEvaluation.TargetUser.UserId)
  58 +// err = lock.Lock()
  59 +// if err != nil {
  60 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  61 +// }
  62 +// defer func() {
  63 +// lock.UnLock()
  64 +// }()
  65 +// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  66 +// "targetUserId": summaryEvaluation.TargetUser.UserId,
  67 +// "typesList": []int{int(domain.EvaluationFinish)},
  68 +// "cycleId": summaryEvaluation.CycleId,
  69 +// "limit": 1,
  70 +// })
  71 +// if err != nil {
  72 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  73 +// }
  74 +// // 如果目标员工已经确认考核结果,就不能在进行评估编辑
  75 +// if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
  76 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
  77 +// }
  78 +
  79 +// // 自评评估内容(自评模板、筛选项目评估人)
  80 +// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
  81 +// "evaluationProjectId": summaryEvaluation.EvaluationProjectId,
  82 +// "nodeType": domain.LinkNodeSelfAssessment,
  83 +// "evaluatorId": -1,
  84 +// })
  85 +// if err != nil {
  86 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  87 +// }
  88 +
  89 +// // 评估内容对应的分数
  90 +// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
  91 +// if err != nil {
  92 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  93 +// }
  94 +
  95 +// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
  96 +// if err != nil {
  97 +// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  98 +// }
  99 +// if !param.IsTemporary {
  100 +// //变更评估状态为已填写
  101 +// summaryEvaluation.Status = domain.EvaluationCompleted
  102 +// //删除旧的填写值,使用新的填写内容
  103 +// err = itemValueRepo.RemoveBySummaryEvaluationId(summaryEvaluation.Id)
  104 +// if err != nil {
  105 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  106 +// }
  107 +// for _, val := range itemValueList {
  108 +// val.Id = 0
  109 +// }
  110 +// }
  111 +// //保存填写值
  112 +// for _, v := range itemValueList {
  113 +// err = itemValueRepo.Save(v)
  114 +// if err != nil {
  115 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 +// }
  117 +// }
  118 +
  119 +// // 针对HRBP类型,更新最后一次操作的HRBP人
  120 +// user, err := userRepo.FindOne(map[string]interface{}{"id": param.ExecutorId})
  121 +// if err != nil {
  122 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  123 +// }
  124 +// summaryEvaluation.Executor.UserId = param.ExecutorId
  125 +// summaryEvaluation.Executor.Account = user.Account
  126 +// summaryEvaluation.Executor.UserName = user.Name
  127 +// summaryEvaluation.Executor.CompanyName = "" // 暂时无用
  128 +// summaryEvaluation.Status = domain.EvaluationCompleted
  129 +
  130 +// //保存填写值
  131 +// err = evaluationRepo.Save(summaryEvaluation)
  132 +// if err != nil {
  133 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  134 +// }
  135 +// if !param.IsTemporary {
  136 +// err = srv.AfterCompletedEvaluation360Hrbp(transactionContext, summaryEvaluation, itemValueList)
  137 +// if err != nil {
  138 +// return nil, err
  139 +// }
  140 +// }
  141 +// if err := transactionContext.CommitTransaction(); err != nil {
  142 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  143 +// }
  144 +
  145 +// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
  146 +// return map[string][]adapter.EvaluationItemAdapter{
  147 +// "evaluationItems": itemValueAdapter,
  148 +// }, nil
  149 +// }
  150 +
  151 +// 提交员工的人资评估 或者 360 评估
  152 +// 变更上级评估的开始时间
  153 +// 或者生成考核结果
  154 +func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(
  155 + transactionContext application.TransactionContext,
  156 + evaluationData *domain.SummaryEvaluation,
  157 + evaluationValue []*domain.SummaryEvaluationValue,
  158 +) error {
  159 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
  160 + "transactionContext": transactionContext,
  161 + })
  162 + _, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{
  163 + "targetUserId": evaluationData.TargetUser.UserId,
  164 + "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
  165 + "cycleId": evaluationData.CycleId,
  166 + "limit": 500,
  167 + })
  168 + if err != nil {
  169 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  170 + }
  171 + allCompleted := true
  172 + for _, v := range evaluation360HrbList {
  173 + if v.Status == domain.EvaluationUncompleted {
  174 + allCompleted = false
  175 + break
  176 + }
  177 + }
  178 + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  179 + "targetUserId": evaluationData.TargetUser.UserId,
  180 + "typesList": []int{int(domain.EvaluationSuper)},
  181 + "cycleId": evaluationData.CycleId,
  182 + "limit": 1,
  183 + })
  184 + if err != nil {
  185 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  186 + }
  187 +
  188 + _, evaluationFinishList, err := evaluationRepo.Find(map[string]interface{}{
  189 + "targetUserId": evaluationData.TargetUser.UserId,
  190 + "typesList": []int{int(domain.EvaluationFinish)},
  191 + "cycleId": evaluationData.CycleId,
  192 + "limit": 1,
  193 + })
  194 + if err != nil {
  195 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  196 + }
  197 + if !allCompleted {
  198 + return nil
  199 + }
  200 +
  201 + nowTime := time.Now()
  202 + updatedId := []int{}
  203 + // 变更上级评估的开始时间
  204 + for _, v := range evaluationList {
  205 + if v.BeginTime.After(nowTime) {
  206 + v.BeginTime = nowTime
  207 + updatedId = append(updatedId, v.Id)
  208 + }
  209 + }
  210 + evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
  211 + "transactionContext": transactionContext,
  212 + })
  213 + err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
  214 + if err != nil {
  215 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  216 + }
  217 + if len(evaluationList) == 0 {
  218 + //没有上级评估
  219 + //直接进入考核结果阶段
  220 + if len(evaluationFinishList) > 0 {
  221 + if evaluationFinishList[0].BeginTime.After(nowTime) {
  222 + evaluationFinishList[0].BeginTime = nowTime
  223 + }
  224 + evaluationFinishList[0].Status = domain.EvaluationCompleted
  225 + err = evaluationRepo.Save(evaluationFinishList[0])
  226 + if err != nil {
  227 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
  228 + }
  229 + //添加确认绩效成绩提醒短信提醒
  230 + err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])
  231 + if err != nil {
  232 + return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
  233 + }
  234 + }
  235 + }
  236 + return nil
  237 +}
  238 +
  239 +// EditEvaluationHRBP 编辑提交人资综评
18 func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) { 240 func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
19 transactionContext, err := factory.CreateTransactionContext(nil) 241 transactionContext, err := factory.CreateTransactionContext(nil)
20 if err != nil { 242 if err != nil {
@@ -73,7 +295,9 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -73,7 +295,9 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
73 if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted { 295 if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
74 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!") 296 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
75 } 297 }
76 - 298 + if ok := summaryEvaluation.EndTime.Before(time.Now()); ok {
  299 + return nil, application.ThrowError(application.BUSINESS_ERROR, "评估时间已截止")
  300 + }
77 // 自评评估内容(自评模板、筛选项目评估人) 301 // 自评评估内容(自评模板、筛选项目评估人)
78 _, itemList, err := itemUsedRepo.Find(map[string]interface{}{ 302 _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
79 "evaluationProjectId": summaryEvaluation.EvaluationProjectId, 303 "evaluationProjectId": summaryEvaluation.EvaluationProjectId,
@@ -89,11 +313,56 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -89,11 +313,56 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
89 if err != nil { 313 if err != nil {
90 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 314 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
91 } 315 }
  316 + //更新填写值
  317 + var evaluationValueSlice []*domain.SummaryEvaluationValue // 提交的填写值
  318 + {
92 319
93 - err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary) 320 + evaluationItemMap := map[int]*domain.EvaluationItemUsed{} // 需要填写那些项 Id=>&domain.EvaluationItemUsed{}
  321 + evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} // 提交的填写值 EvaluationItemId=>&domain.domain.SummaryEvaluationValue{}
  322 + summaryEvaluation.TotalRating = nil // 清空评级数量统计
  323 + // 按照需要填写那些项 设置SummaryEvaluationValue的空白值
  324 + for _, v := range itemList {
  325 + newValue := &domain.SummaryEvaluationValue{}
  326 + newValue.SetBlankValue(summaryEvaluation, v)
  327 + evaluationValueMap[v.Id] = newValue
  328 + evaluationItemMap[v.Id] = v
  329 + evaluationValueSlice = append(evaluationValueSlice, newValue)
  330 + }
  331 + //如果存在旧值
  332 + //新值的id 替换为旧值id
  333 + for _, v := range itemValueList {
  334 + if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
  335 + mValue.Id = v.Id
  336 + }
  337 + }
  338 + //填入提交的更新值
  339 + for _, v := range param.EvaluationItems {
  340 + v.Value = strings.TrimSpace(v.Value)
  341 + newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
  342 + if !ok {
  343 + continue
  344 + }
  345 + evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
  346 + if !ok {
  347 + continue
  348 + }
  349 + if !param.IsTemporary {
  350 + //除了综合自评,其他的评估任务 评估项直接全部按必填项处理
  351 + if len(v.Value) == 0 {
  352 + e := fmt.Sprintf("%s-%s 未填写", evaluationItem.Category, evaluationItem.Name)
  353 + return nil, application.ThrowError(application.BUSINESS_ERROR, e)
  354 + }
  355 + }
  356 + //填充评估填写值
  357 + newItemValue.Remark = v.Remark
  358 + err := summaryEvaluation.FillItemValue(evaluationItem, newItemValue, v.Value)
94 if err != nil { 359 if err != nil {
95 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 360 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
96 } 361 }
  362 + }
  363 + summaryEvaluation.EvaluationTotalScore(evaluationValueSlice)
  364 + }
  365 +
97 if !param.IsTemporary { 366 if !param.IsTemporary {
98 //变更评估状态为已填写 367 //变更评估状态为已填写
99 summaryEvaluation.Status = domain.EvaluationCompleted 368 summaryEvaluation.Status = domain.EvaluationCompleted
@@ -102,12 +371,12 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -102,12 +371,12 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
102 if err != nil { 371 if err != nil {
103 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 372 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
104 } 373 }
105 - for _, val := range itemValueList { 374 + for _, val := range evaluationValueSlice {
106 val.Id = 0 375 val.Id = 0
107 } 376 }
108 } 377 }
109 //保存填写值 378 //保存填写值
110 - for _, v := range itemValueList { 379 + for _, v := range evaluationValueSlice {
111 err = itemValueRepo.Save(v) 380 err = itemValueRepo.Save(v)
112 if err != nil { 381 if err != nil {
113 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 382 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -145,113 +414,3 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -145,113 +414,3 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
145 "evaluationItems": itemValueAdapter, 414 "evaluationItems": itemValueAdapter,
146 }, nil 415 }, nil
147 } 416 }
148 -  
149 -// 提交员工的人资评估 或者 360 评估  
150 -// 变更上级评估的开始时间  
151 -// 或者生成考核结果  
152 -func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(  
153 - transactionContext application.TransactionContext,  
154 - evaluationData *domain.SummaryEvaluation,  
155 - evaluationValue []*domain.SummaryEvaluationValue,  
156 -) error {  
157 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
158 - "transactionContext": transactionContext,  
159 - })  
160 - _, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{  
161 - "targetUserId": evaluationData.TargetUser.UserId,  
162 - "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},  
163 - "cycleId": evaluationData.CycleId,  
164 - "limit": 500,  
165 - })  
166 - if err != nil {  
167 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
168 - }  
169 - allCompleted := true  
170 - for _, v := range evaluation360HrbList {  
171 - if v.Status == domain.EvaluationUncompleted {  
172 - allCompleted = false  
173 - break  
174 - }  
175 - }  
176 - _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
177 - "targetUserId": evaluationData.TargetUser.UserId,  
178 - "typesList": []int{int(domain.EvaluationSuper)},  
179 - "cycleId": evaluationData.CycleId,  
180 - "limit": 1,  
181 - })  
182 - if err != nil {  
183 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
184 - }  
185 -  
186 - //noSuper := (len(evaluationList) == 0)  
187 -  
188 - _, evaluationFinishList, err := evaluationRepo.Find(map[string]interface{}{  
189 - "targetUserId": evaluationData.TargetUser.UserId,  
190 - "typesList": []int{int(domain.EvaluationFinish)},  
191 - "cycleId": evaluationData.CycleId,  
192 - "limit": 1,  
193 - })  
194 - if err != nil {  
195 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
196 - }  
197 - if !allCompleted {  
198 - //仅同步评估内容到考核结果  
199 - // if noSuper && len(evaluationFinishList) > 0 {  
200 - // //不存在上级评估  
201 - // err = srv.syncEvaluationFinishValue(transactionContext, evaluationFinishList[0], evaluationValue)  
202 - // if err != nil {  
203 - // return err  
204 - // }  
205 - // }  
206 - return nil  
207 - }  
208 -  
209 - nowTime := time.Now()  
210 - updatedId := []int{}  
211 - // 变更上级评估的开始时间  
212 - for _, v := range evaluationList {  
213 - if v.BeginTime.After(nowTime) {  
214 - v.BeginTime = nowTime  
215 - updatedId = append(updatedId, v.Id)  
216 - }  
217 - }  
218 - evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{  
219 - "transactionContext": transactionContext,  
220 - })  
221 - err = evaluationDao.UpdateBeginTime(updatedId, nowTime)  
222 - if err != nil {  
223 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
224 - }  
225 - if len(evaluationList) == 0 {  
226 - //没有上级评估  
227 - //直接进入考核结果阶段  
228 - if len(evaluationFinishList) > 0 {  
229 - if evaluationFinishList[0].BeginTime.After(nowTime) {  
230 - evaluationFinishList[0].BeginTime = nowTime  
231 - }  
232 - evaluationFinishList[0].Status = domain.EvaluationCompleted  
233 - err = evaluationRepo.Save(evaluationFinishList[0])  
234 - if err != nil {  
235 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())  
236 - }  
237 - //添加确认绩效成绩提醒短信提醒  
238 - err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])  
239 - if err != nil {  
240 - return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())  
241 - }  
242 - }  
243 - }  
244 - // if noSuper && len(evaluationFinishList) > 0 {  
245 - //不存在上级评估  
246 - // err = srv.syncEvaluationFinishValue(transactionContext, evaluationFinishList[0], evaluationValue)  
247 - // if err != nil {  
248 - // return err  
249 - // }  
250 - // } else if len(evaluationList) == 0 && len(evaluationFinishList) > 0 {  
251 - // err = evaluationRepo.Save(evaluationFinishList[0])  
252 - // if err != nil {  
253 - // return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())  
254 - // }  
255 - // }  
256 - return nil  
257 -}  
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
  5 + "strings"
4 "time" 6 "time"
5 7
6 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
@@ -13,7 +15,275 @@ import ( @@ -13,7 +15,275 @@ import (
13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
14 ) 16 )
15 17
16 -//编辑上级周期评估 18 +// 编辑上级周期评估
  19 +// EditEvaluationSuper 更新上级评估内容
  20 +// func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
  21 +// transactionContext, err := factory.CreateTransactionContext(nil)
  22 +// if err != nil {
  23 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 +// }
  25 +// if err := transactionContext.StartTransaction(); err != nil {
  26 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  27 +// }
  28 +// defer func() {
  29 +// _ = transactionContext.RollbackTransaction()
  30 +// }()
  31 +// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
  32 +// "transactionContext": transactionContext,
  33 +// })
  34 +// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
  35 +// "transactionContext": transactionContext,
  36 +// })
  37 +
  38 +// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
  39 +// "transactionContext": transactionContext,
  40 +// })
  41 +// evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
  42 +// "id": param.SummaryEvaluationId,
  43 +// })
  44 +// if err != nil {
  45 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  46 +// }
  47 +// if evaluationData.Types != domain.EvaluationSuper {
  48 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  49 +// }
  50 +
  51 +// if evaluationData.Executor.UserId != param.ExecutorId {
  52 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  53 +// }
  54 +
  55 +// if evaluationData.CompanyId != param.CompanyId {
  56 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  57 +// }
  58 +// ok := evaluationData.EndTime.Before(time.Now())
  59 +// if ok {
  60 +// return nil, application.ThrowError(application.BUSINESS_ERROR, "评估时间已截止")
  61 +// }
  62 +// //按照被评估人id ,加锁
  63 +// lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
  64 +// err = lock.Lock()
  65 +// if err != nil {
  66 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  67 +// }
  68 +// defer func() {
  69 +// lock.UnLock()
  70 +// }()
  71 +// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  72 +// "targetUserId": evaluationData.TargetUser.UserId,
  73 +// "typesList": []int{int(domain.EvaluationFinish)},
  74 +// "cycleId": evaluationData.CycleId,
  75 +// "limit": 1,
  76 +// })
  77 +// if err != nil {
  78 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 +// }
  80 +// // 如果目标员工已经确认考核结果,就不能在进行评估编辑
  81 +// if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
  82 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
  83 +// }
  84 +
  85 +// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
  86 +// "evaluationProjectId": evaluationData.EvaluationProjectId,
  87 +// "nodeType": domain.LinkNodeSelfAssessment,
  88 +// })
  89 +// if err != nil {
  90 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  91 +// }
  92 +// //获取已填写的评估内容
  93 +// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{
  94 +// "summaryEvaluationId": evaluationData.Id,
  95 +// })
  96 +// if err != nil {
  97 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  98 +// }
  99 +// //记录人资评估或者360评估的 填写项id
  100 +// hrbpOr360ItemValue, err := srv.getEvaluationSuperDefaultValue(transactionContext, evaluationData)
  101 +// if err != nil {
  102 +// return nil, err
  103 +// }
  104 +
  105 +// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary)
  106 +// if err != nil {
  107 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  108 +// }
  109 +// if !param.IsTemporary {
  110 +// //变更评估状态为已填写
  111 +// evaluationData.Status = domain.EvaluationCompleted
  112 +// //删除旧的填写值,使用新的填写内容
  113 +// err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
  114 +// if err != nil {
  115 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 +// }
  117 +// for _, val := range itemValueList {
  118 +// val.Id = 0
  119 +// }
  120 +// }
  121 +// //保存填写值
  122 +// err = evaluationRepo.Save(evaluationData)
  123 +// if err != nil {
  124 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  125 +// }
  126 +// for _, v := range itemValueList {
  127 +// //保存填写值
  128 +// err = itemValueRepo.Save(v)
  129 +// if err != nil {
  130 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  131 +// }
  132 +// }
  133 +// if !param.IsTemporary {
  134 +// err = srv.AfterCompletedEvaluationSuper(transactionContext, evaluationData, itemValueList)
  135 +// if err != nil {
  136 +// return nil, err
  137 +// }
  138 +// }
  139 +
  140 +// if err := transactionContext.CommitTransaction(); err != nil {
  141 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  142 +// }
  143 +// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
  144 +// return map[string][]adapter.EvaluationItemAdapter{
  145 +// "EvaluationItems": itemValueAdapter,
  146 +// }, nil
  147 +// }
  148 +
  149 +// 员工提交上级评估后
  150 +// 生成考核结果
  151 +func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(
  152 + transactionContext application.TransactionContext,
  153 + evaluationData *domain.SummaryEvaluation,
  154 + evaluationValue []*domain.SummaryEvaluationValue,
  155 +) error {
  156 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
  157 + "transactionContext": transactionContext,
  158 + })
  159 + //没有上级评估
  160 + //直接进入考核结果阶段
  161 + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  162 + "targetUserId": evaluationData.TargetUser.UserId,
  163 + "typesList": []int{int(domain.EvaluationFinish)},
  164 + "cycleId": evaluationData.CycleId,
  165 + "limit": 1,
  166 + })
  167 + if err != nil {
  168 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  169 + }
  170 +
  171 + if len(evaluationList) > 0 {
  172 + //调整考核结果的开始时间
  173 + nowTime := time.Now()
  174 + if evaluationList[0].BeginTime.After(nowTime) {
  175 + evaluationList[0].BeginTime = nowTime
  176 + }
  177 + evaluationList[0].Status = domain.EvaluationCompleted
  178 + err = srv.syncEvaluationFinishValue(transactionContext, evaluationList[0], evaluationValue)
  179 + if err != nil {
  180 + return err
  181 + }
  182 + //添加确认绩效成绩提醒短信提醒
  183 + err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
  184 + if err != nil {
  185 + log.Logger.Error("添加确认绩效成绩提醒短信提醒失败:" + err.Error())
  186 + }
  187 + }
  188 + return nil
  189 +}
  190 +
  191 +// 从其他评估那边同步考核结果的评估内容
  192 +// evaluationData 考核结果评估
  193 +// updateValue 更新评估项需要的值
  194 +func (srv *SummaryEvaluationService) syncEvaluationFinishValue(
  195 + transactionContext application.TransactionContext,
  196 + evaluationData *domain.SummaryEvaluation,
  197 + updateValue []*domain.SummaryEvaluationValue,
  198 +) error {
  199 + if len(updateValue) == 0 {
  200 + return nil
  201 + }
  202 + if evaluationData.CheckResult == domain.EvaluationCheckCompleted {
  203 + return nil
  204 + }
  205 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
  206 + "transactionContext": transactionContext,
  207 + })
  208 + evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
  209 + "transactionContext": transactionContext,
  210 + })
  211 + itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
  212 + "transactionContext": transactionContext,
  213 + })
  214 + _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
  215 + "evaluationProjectId": evaluationData.EvaluationProjectId,
  216 + "nodeType": domain.LinkNodeSelfAssessment,
  217 + })
  218 + if err != nil {
  219 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  220 + }
  221 + //填写项的map EvaluationItemId =>SummaryEvaluationValue
  222 + oldEvaluationValue := map[int]*domain.SummaryEvaluationValue{}
  223 + //查询已有的考核结果评估内容
  224 + _, evaluationValueList, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
  225 + if err != nil {
  226 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  227 + }
  228 + for i, val := range evaluationValueList {
  229 + oldEvaluationValue[val.EvaluationItemId] = evaluationValueList[i]
  230 + }
  231 + // 待更新的评估填写项map EvaluationItemId =>SummaryEvaluationValue
  232 + updateValueMap := map[int]*domain.SummaryEvaluationValue{}
  233 + for i, val := range updateValue {
  234 + updateValueMap[val.EvaluationItemId] = updateValue[i]
  235 + }
  236 +
  237 + //更新考核结果
  238 + for _, val := range itemList {
  239 + oldValue, ok := oldEvaluationValue[val.Id]
  240 + if !ok {
  241 + //补全考核结果中可能缺失的评估项
  242 + newValue := &domain.SummaryEvaluationValue{}
  243 + newValue.SetBlankValue(evaluationData, val)
  244 + oldEvaluationValue[val.Id] = newValue
  245 + oldValue = oldEvaluationValue[val.Id]
  246 + }
  247 + if item, ok := updateValueMap[val.Id]; ok {
  248 + oldValue.Executor = item.Executor
  249 + oldValue.Types = item.Types
  250 + oldValue.Rating = item.Rating
  251 + oldValue.Value = item.Value
  252 + oldValue.Score = item.Score
  253 + oldValue.Remark = item.Remark
  254 + }
  255 + }
  256 + // 重置各个评级数量
  257 + evaluationData.TotalRating = nil
  258 + for i := range itemList {
  259 + evaluationData.ResetTotalRating(itemList[i])
  260 + }
  261 +
  262 + newEvaluationValue := []*domain.SummaryEvaluationValue{}
  263 + for _, val := range oldEvaluationValue {
  264 + newEvaluationValue = append(newEvaluationValue, val)
  265 + }
  266 + //计算总分
  267 + evaluationData.EvaluationTotalScore(newEvaluationValue)
  268 +
  269 + err = evaluationRepo.Save(evaluationData)
  270 + if err != nil {
  271 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
  272 + }
  273 + err = evaluationValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
  274 + if err != nil {
  275 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
  276 + }
  277 + for _, val := range newEvaluationValue {
  278 + val.Id = 0
  279 + err = evaluationValueRepo.Save(val)
  280 + if err != nil {
  281 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
  282 + }
  283 + }
  284 + return nil
  285 +
  286 +}
17 287
18 // EditEvaluationSuper 更新上级评估内容 288 // EditEvaluationSuper 更新上级评估内容
19 func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) { 289 func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
@@ -100,11 +370,72 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -100,11 +370,72 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
100 if err != nil { 370 if err != nil {
101 return nil, err 371 return nil, err
102 } 372 }
103 -  
104 - err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary) 373 + //更新填写值
  374 + var evaluationValueSlice []*domain.SummaryEvaluationValue // 提交的填写值
  375 + {
  376 + evaluationItemMap := map[int]*domain.EvaluationItemUsed{} // 需要填写那些项 Id=>&domain.EvaluationItemUsed{}
  377 + evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} // 提交的填写值 EvaluationItemId=>&domain.domain.SummaryEvaluationValue{}
  378 + evaluationData.TotalRating = nil // 清空评级数量统计
  379 + // 按照需要填写那些项 设置SummaryEvaluationValue的空白值
  380 + for _, v := range itemList {
  381 + newValue := &domain.SummaryEvaluationValue{}
  382 + newValue.SetBlankValue(evaluationData, v)
  383 + evaluationValueMap[v.Id] = newValue
  384 + evaluationItemMap[v.Id] = v
  385 + evaluationValueSlice = append(evaluationValueSlice, newValue)
  386 + }
  387 + //如果存在旧值
  388 + //新值的id 替换为旧值id
  389 + for _, v := range itemValueList {
  390 + if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
  391 + mValue.Id = v.Id
  392 + }
  393 + }
  394 + //填入提交的更新值
  395 + for _, v := range param.EvaluationItems {
  396 + v.Value = strings.TrimSpace(v.Value)
  397 + newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
  398 + if !ok {
  399 + continue
  400 + }
  401 + evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
  402 + if !ok {
  403 + continue
  404 + }
  405 + if !param.IsTemporary {
  406 + //除了综合自评,其他的评估任务 评估项直接全部按必填项处理
  407 + if len(v.Value) == 0 {
  408 + e := fmt.Sprintf("%s-%s 未填写", evaluationItem.Category, evaluationItem.Name)
  409 + return nil, application.ThrowError(application.BUSINESS_ERROR, e)
  410 + }
  411 + }
  412 + //填充评估填写值
  413 + newItemValue.Remark = v.Remark
  414 + err := evaluationData.FillItemValue(evaluationItem, newItemValue, v.Value)
105 if err != nil { 415 if err != nil {
106 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 416 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  417 + }
  418 + }
  419 + // 填入固定的默认值
  420 + for _, v := range hrbpOr360ItemValue {
  421 + newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
  422 + if !ok {
  423 + continue
  424 + }
  425 + evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
  426 + if !ok {
  427 + continue
  428 + }
  429 + //填充评估填写值
  430 + newItemValue.Remark = v.Remark
  431 + err := evaluationData.FillItemValue(evaluationItem, newItemValue, v.Value)
  432 + if err != nil {
  433 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  434 + }
107 } 435 }
  436 + evaluationData.EvaluationTotalScore(evaluationValueSlice)
  437 + }
  438 +
108 if !param.IsTemporary { 439 if !param.IsTemporary {
109 //变更评估状态为已填写 440 //变更评估状态为已填写
110 evaluationData.Status = domain.EvaluationCompleted 441 evaluationData.Status = domain.EvaluationCompleted
@@ -113,7 +444,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -113,7 +444,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
113 if err != nil { 444 if err != nil {
114 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 445 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
115 } 446 }
116 - for _, val := range itemValueList { 447 + for _, val := range evaluationValueSlice {
117 val.Id = 0 448 val.Id = 0
118 } 449 }
119 } 450 }
@@ -122,7 +453,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -122,7 +453,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
122 if err != nil { 453 if err != nil {
123 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 454 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
124 } 455 }
125 - for _, v := range itemValueList { 456 + for _, v := range evaluationValueSlice {
126 //保存填写值 457 //保存填写值
127 err = itemValueRepo.Save(v) 458 err = itemValueRepo.Save(v)
128 if err != nil { 459 if err != nil {
@@ -145,141 +476,72 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -145,141 +476,72 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
145 }, nil 476 }, nil
146 } 477 }
147 478
148 -// 员工提交上级评估后  
149 -// 生成考核结果  
150 -func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(  
151 - transactionContext application.TransactionContext,  
152 - evaluationData *domain.SummaryEvaluation,  
153 - evaluationValue []*domain.SummaryEvaluationValue,  
154 -) error { 479 +// getEvaluationSuperDefaultValue
  480 +// 按照权限设置,是否获取上级评估内容的默认值
  481 +func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
  482 + []*domain.SummaryEvaluationValue, error) {
155 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{ 483 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
156 "transactionContext": transactionContext, 484 "transactionContext": transactionContext,
157 }) 485 })
158 - //没有上级评估  
159 - //直接进入考核结果阶段  
160 - _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
161 - "targetUserId": evaluationData.TargetUser.UserId,  
162 - "typesList": []int{int(domain.EvaluationFinish)},  
163 - "cycleId": evaluationData.CycleId,  
164 - "limit": 1, 486 +
  487 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
  488 + "transactionContext": transactionContext,
165 }) 489 })
166 - if err != nil {  
167 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
168 - }  
169 490
170 - if len(evaluationList) > 0 {  
171 - //调整考核结果的开始时间  
172 - nowTime := time.Now()  
173 - if evaluationList[0].BeginTime.After(nowTime) {  
174 - evaluationList[0].BeginTime = nowTime  
175 - }  
176 - evaluationList[0].Status = domain.EvaluationCompleted  
177 - err = srv.syncEvaluationFinishValue(transactionContext, evaluationList[0], evaluationValue) 491 + permissionData, err := getPermission(int64(evaluationData.CompanyId))
178 if err != nil { 492 if err != nil {
179 - return err  
180 - }  
181 - //添加确认绩效成绩提醒短信提醒  
182 - err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])  
183 - if err != nil {  
184 - log.Logger.Error("添加确认绩效成绩提醒短信提醒失败:" + err.Error())  
185 - }  
186 - }  
187 - return nil  
188 -}  
189 -  
190 -// 从其他评估那边同步考核结果的评估内容  
191 -// evaluationData 考核结果评估  
192 -// updateValue 更新评估项需要的值  
193 -func (srv *SummaryEvaluationService) syncEvaluationFinishValue(  
194 - transactionContext application.TransactionContext,  
195 - evaluationData *domain.SummaryEvaluation,  
196 - updateValue []*domain.SummaryEvaluationValue,  
197 -) error {  
198 - if len(updateValue) == 0 {  
199 - return nil 493 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
200 } 494 }
201 - if evaluationData.CheckResult == domain.EvaluationCheckCompleted {  
202 - return nil 495 + if permissionData.OptEvalScore == domain.PermissionOn && permissionData.OptHrScore == domain.PermissionOn {
  496 + return nil, nil
203 } 497 }
204 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
205 - "transactionContext": transactionContext,  
206 - })  
207 - evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{  
208 - "transactionContext": transactionContext,  
209 - })  
210 - itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{  
211 - "transactionContext": transactionContext,  
212 - })  
213 - _, itemList, err := itemUsedRepo.Find(map[string]interface{}{  
214 - "evaluationProjectId": evaluationData.EvaluationProjectId,  
215 - "nodeType": domain.LinkNodeSelfAssessment, 498 + // 获取360评估,人资评估填写的值
  499 + _, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
  500 + "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
  501 + "targetUserId": evaluationData.TargetUser.UserId,
  502 + "cycleId": evaluationData.CycleId,
216 }) 503 })
217 if err != nil { 504 if err != nil {
218 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
219 - }  
220 - //填写项的map EvaluationItemId =>SummaryEvaluationValue  
221 - oldEvaluationValue := map[int]*domain.SummaryEvaluationValue{}  
222 - //查询已有的考核结果评估内容  
223 - _, evaluationValueList, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})  
224 - if err != nil {  
225 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 505 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
226 } 506 }
227 - for i, val := range evaluationValueList {  
228 - oldEvaluationValue[val.EvaluationItemId] = evaluationValueList[i] 507 + evaluationIds := []int{}
  508 + for _, v := range evaluationListOther {
  509 + evaluationIds = append(evaluationIds, v.Id)
229 } 510 }
230 - // 待更新的评估填写项map EvaluationItemId =>SummaryEvaluationValue  
231 - updateValueMap := map[int]*domain.SummaryEvaluationValue{}  
232 - for i, val := range updateValue {  
233 - updateValueMap[val.EvaluationItemId] = updateValue[i] 511 + if len(evaluationIds) == 0 {
  512 + return nil, nil
234 } 513 }
235 -  
236 - //更新考核结果  
237 - for _, val := range itemList {  
238 - oldValue, ok := oldEvaluationValue[val.Id]  
239 - if !ok {  
240 - //补全考核结果中可能缺失的评估项  
241 - newValue := &domain.SummaryEvaluationValue{}  
242 - newValue.SetBlankValue(evaluationData, val)  
243 - oldEvaluationValue[val.Id] = newValue  
244 - oldValue = oldEvaluationValue[val.Id] 514 + // 将360评估,人资评估填写的值 作为默认值
  515 + _, itemValuesOther, err := itemValueRepo.Find(map[string]interface{}{
  516 + "summaryEvaluationIdList": evaluationIds,
  517 + })
  518 + if err != nil {
  519 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
245 } 520 }
246 - if item, ok := updateValueMap[val.Id]; ok {  
247 - oldValue.Executor = item.Executor  
248 - oldValue.Types = item.Types  
249 - oldValue.Rating = item.Rating  
250 - oldValue.Value = item.Value  
251 - oldValue.Score = item.Score  
252 - oldValue.Remark = item.Remark 521 + // 记录人资评估或者360评估的 填写项id
  522 + hrbpOr360ItemValue := []*domain.SummaryEvaluationValue{}
  523 + if permissionData.OptEvalScore == domain.PermissionOff {
  524 + //上级是否可以修改360°综评分数
  525 + //获取360综合评分
  526 + for _, v := range itemValuesOther {
  527 + //记录人资评估或者360评估的填写值
  528 + if v.Types != domain.Evaluation360 {
  529 + continue
253 } 530 }
  531 + hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
254 } 532 }
255 - // 重置各个评级数量  
256 - evaluationData.TotalRating = nil  
257 - for i := range itemList {  
258 - evaluationData.ResetTotalRating(itemList[i])  
259 } 533 }
260 -  
261 - newEvaluationValue := []*domain.SummaryEvaluationValue{}  
262 - for _, val := range oldEvaluationValue {  
263 - newEvaluationValue = append(newEvaluationValue, val) 534 + if permissionData.OptHrScore == domain.PermissionOff {
  535 + //上级是否可以修改人资综评分数
  536 + //获取人资综合评分
  537 + for _, v := range itemValuesOther {
  538 + //记录人资评估或者360评估的填写值
  539 + if v.Types != domain.EvaluationHrbp {
  540 + continue
264 } 541 }
265 - //计算总分  
266 - evaluationData.EvaluationTotalScore(newEvaluationValue)  
267 542
268 - err = evaluationRepo.Save(evaluationData)  
269 - if err != nil {  
270 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())  
271 - }  
272 - err = evaluationValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)  
273 - if err != nil {  
274 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())  
275 - }  
276 - for _, val := range newEvaluationValue {  
277 - val.Id = 0  
278 - err = evaluationValueRepo.Save(val)  
279 - if err != nil {  
280 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error()) 543 + hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
281 } 544 }
282 } 545 }
283 - return nil  
284 - 546 + return hrbpOr360ItemValue, nil
285 } 547 }
@@ -480,375 +480,6 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app @@ -480,375 +480,6 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
480 return result 480 return result
481 } 481 }
482 482
483 -// 编辑综合自评详情  
484 -// func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {  
485 -// lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)  
486 -// err := lock.Lock()  
487 -// if err != nil {  
488 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")  
489 -// }  
490 -// defer func() {  
491 -// lock.UnLock()  
492 -// }()  
493 -// transactionContext, err := factory.CreateTransactionContext(nil)  
494 -// if err != nil {  
495 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
496 -// }  
497 -// if err := transactionContext.StartTransaction(); err != nil {  
498 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
499 -// }  
500 -// defer func() {  
501 -// _ = transactionContext.RollbackTransaction()  
502 -// }()  
503 -// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
504 -// "transactionContext": transactionContext,  
505 -// })  
506 -// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{  
507 -// "transactionContext": transactionContext,  
508 -// })  
509 -  
510 -// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{  
511 -// "transactionContext": transactionContext,  
512 -// })  
513 -// evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{  
514 -// "id": param.SummaryEvaluationId,  
515 -// })  
516 -// if err != nil {  
517 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())  
518 -// }  
519 -// if evaluationData.Types != domain.EvaluationSelf {  
520 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
521 -// }  
522 -  
523 -// if evaluationData.Executor.UserId != param.ExecutorId {  
524 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
525 -// }  
526 -  
527 -// if evaluationData.CompanyId != param.CompanyId {  
528 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
529 -// }  
530 -  
531 -// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{  
532 -// "evaluationProjectId": evaluationData.EvaluationProjectId,  
533 -// "nodeType": domain.LinkNodeSelfAssessment,  
534 -// })  
535 -// if err != nil {  
536 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
537 -// }  
538 -  
539 -// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{  
540 -// "summaryEvaluationId": evaluationData.Id,  
541 -// })  
542 -  
543 -// if err != nil {  
544 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
545 -// }  
546 -  
547 -// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)  
548 -// if err != nil {  
549 -// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
550 -// }  
551 -  
552 -// //保存填写值  
553 -// for _, v := range itemValueList {  
554 -// err = itemValueRepo.Save(v)  
555 -// if err != nil {  
556 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
557 -// }  
558 -// }  
559 -// if !param.IsTemporary {  
560 -// evaluationData.Status = domain.EvaluationCompleted  
561 -// }  
562 -// err = evaluationRepo.Save(evaluationData)  
563 -// if err != nil {  
564 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
565 -// }  
566 -// if err := transactionContext.CommitTransaction(); err != nil {  
567 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
568 -// }  
569 -// if !param.IsTemporary {  
570 -// err = srv.AfterCompletedEvaluationSelf(evaluationData)  
571 -// if err != nil {  
572 -// return nil, err  
573 -// }  
574 -// }  
575 -  
576 -// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)  
577 -// return map[string][]adapter.EvaluationItemAdapter{  
578 -// "EvaluationItems": itemValueAdapter,  
579 -// }, nil  
580 -// }  
581 -  
582 -// // 员工提交自评内容后,  
583 -// // 员工作为被评估人,  
584 -// // 变更360评估/人资评估/的开始时间  
585 -// // 或者变更上级评估的开始时间  
586 -// // 或者生成考核结果  
587 -// func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {  
588 -// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)  
589 -// err := lock.Lock()  
590 -// if err != nil {  
591 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")  
592 -// }  
593 -// defer func() {  
594 -// lock.UnLock()  
595 -// }()  
596 -// transactionContext, err := factory.CreateTransactionContext(nil)  
597 -// if err != nil {  
598 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
599 -// }  
600 -// if err := transactionContext.StartTransaction(); err != nil {  
601 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
602 -// }  
603 -// defer func() {  
604 -// _ = transactionContext.RollbackTransaction()  
605 -// }()  
606 -// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
607 -// "transactionContext": transactionContext,  
608 -// })  
609 -// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
610 -// "targetUserId": param.TargetUser.UserId,  
611 -// "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},  
612 -// "cycleId": param.CycleId,  
613 -// "limit": 1000,  
614 -// })  
615 -// if err != nil {  
616 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
617 -// }  
618 -// if len(evaluationList) == 0 {  
619 -// //如果没有360评估和hrbp 评估,查找上级评估  
620 -// _, evaluationList, err = evaluationRepo.Find(map[string]interface{}{  
621 -// "targetUserId": param.TargetUser.UserId,  
622 -// "typesList": []int{int(domain.EvaluationSuper)},  
623 -// "cycleId": param.CycleId,  
624 -// "limit": 10,  
625 -// })  
626 -// if err != nil {  
627 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
628 -// }  
629 -// }  
630 -// nowTime := time.Now()  
631 -// updatedId := []int{}  
632 -// // 变更360评估/人资评估/上级评估的开始时间  
633 -// for _, v := range evaluationList {  
634 -// if v.BeginTime.After(nowTime) {  
635 -// v.BeginTime = nowTime  
636 -// updatedId = append(updatedId, v.Id)  
637 -// }  
638 -// }  
639 -// evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{  
640 -// "transactionContext": transactionContext,  
641 -// })  
642 -// err = evaluationDao.UpdateBeginTime(updatedId, nowTime)  
643 -// if err != nil {  
644 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
645 -// }  
646 -// if len(evaluationList) == 0 {  
647 -// //没有上级评估、360评估、hrbp 评估  
648 -// //直接进入考核结果阶段  
649 -// _, evaluationFinishList, err := evaluationRepo.Find(map[string]interface{}{  
650 -// "targetUserId": param.TargetUser.UserId,  
651 -// "typesList": []int{int(domain.EvaluationFinish)},  
652 -// "cycleId": param.CycleId,  
653 -// "limit": 1,  
654 -// })  
655 -// if err != nil {  
656 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
657 -// }  
658 -// if len(evaluationFinishList) > 0 {  
659 -// //进入考核结果  
660 -// //自评的结束时间  
661 -// if evaluationFinishList[0].BeginTime.After(nowTime) {  
662 -// evaluationFinishList[0].BeginTime = nowTime  
663 -// }  
664 -// evaluationFinishList[0].Status = domain.EvaluationCompleted  
665 -// err = evaluationRepo.Save(evaluationFinishList[0])  
666 -// if err != nil {  
667 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())  
668 -// }  
669 -// //添加确认绩效成绩提醒短信提醒  
670 -// err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])  
671 -// if err != nil {  
672 -// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())  
673 -// }  
674 -// }  
675 -// }  
676 -// if err := transactionContext.CommitTransaction(); err != nil {  
677 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
678 -// }  
679 -// return nil  
680 -// }  
681 -  
682 -// 提交员工的人资评估 或者 360 评估  
683 -// 变更上级评估的开始时间  
684 -// 或者生成考核结果  
685 -// func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {  
686 -// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)  
687 -// err := lock.Lock()  
688 -// if err != nil {  
689 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")  
690 -// }  
691 -// defer func() {  
692 -// lock.UnLock()  
693 -// }()  
694 -// transactionContext, err := factory.CreateTransactionContext(nil)  
695 -// if err != nil {  
696 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
697 -// }  
698 -// if err := transactionContext.StartTransaction(); err != nil {  
699 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
700 -// }  
701 -// defer func() {  
702 -// _ = transactionContext.RollbackTransaction()  
703 -// }()  
704 -  
705 -// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
706 -// "transactionContext": transactionContext,  
707 -// })  
708 -// _, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{  
709 -// "targetUserId": param.TargetUser.UserId,  
710 -// "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},  
711 -// "cycleId": param.CycleId,  
712 -// "limit": 1000,  
713 -// })  
714 -// if err != nil {  
715 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
716 -// }  
717 -// allCompleted := true  
718 -// for _, v := range evaluation360HrbList {  
719 -// if v.Status == domain.EvaluationUncompleted {  
720 -// allCompleted = false  
721 -// break  
722 -// }  
723 -// }  
724 -// if !allCompleted {  
725 -// return nil  
726 -// }  
727 -// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
728 -// "targetUserId": param.TargetUser.UserId,  
729 -// "typesList": []int{int(domain.EvaluationSuper)},  
730 -// "cycleId": param.CycleId,  
731 -// "limit": 1,  
732 -// })  
733 -// if err != nil {  
734 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
735 -// }  
736 -// nowTime := time.Now()  
737 -// updatedId := []int{}  
738 -// // 变更上级评估的开始时间  
739 -// for _, v := range evaluationList {  
740 -// if v.BeginTime.After(nowTime) {  
741 -// v.BeginTime = nowTime  
742 -// updatedId = append(updatedId, v.Id)  
743 -// }  
744 -// }  
745 -// evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{  
746 -// "transactionContext": transactionContext,  
747 -// })  
748 -// err = evaluationDao.UpdateBeginTime(updatedId, nowTime)  
749 -// if err != nil {  
750 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
751 -// }  
752 -// if len(evaluationList) == 0 {  
753 -// //没有上级评估  
754 -// //直接进入考核结果阶段  
755 -// _, evaluationFinishList, err := evaluationRepo.Find(map[string]interface{}{  
756 -// "targetUserId": param.TargetUser.UserId,  
757 -// "typesList": []int{int(domain.EvaluationFinish)},  
758 -// "cycleId": param.CycleId,  
759 -// "limit": 1,  
760 -// })  
761 -// if err != nil {  
762 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
763 -// }  
764 -// if len(evaluationFinishList) > 0 {  
765 -// if evaluationFinishList[0].BeginTime.After(nowTime) {  
766 -// evaluationFinishList[0].BeginTime = nowTime  
767 -// }  
768 -// evaluationFinishList[0].Status = domain.EvaluationCompleted  
769 -// err = evaluationRepo.Save(evaluationFinishList[0])  
770 -// if err != nil {  
771 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())  
772 -// }  
773 -// //添加确认绩效成绩提醒短信提醒  
774 -// err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])  
775 -// if err != nil {  
776 -// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())  
777 -// }  
778 -// }  
779 -  
780 -// }  
781 -// if err := transactionContext.CommitTransaction(); err != nil {  
782 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
783 -// }  
784 -// return nil  
785 -// }  
786 -  
787 -// // 员工提交上级评估后  
788 -// // 生成考核结果  
789 -// func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {  
790 -// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)  
791 -// err := lock.Lock()  
792 -// if err != nil {  
793 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")  
794 -// }  
795 -// defer func() {  
796 -// lock.UnLock()  
797 -// }()  
798 -// transactionContext, err := factory.CreateTransactionContext(nil)  
799 -// if err != nil {  
800 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
801 -// }  
802 -// if err := transactionContext.StartTransaction(); err != nil {  
803 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
804 -// }  
805 -// defer func() {  
806 -// _ = transactionContext.RollbackTransaction()  
807 -// }()  
808 -  
809 -// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
810 -// "transactionContext": transactionContext,  
811 -// })  
812 -// //没有上级评估  
813 -// //直接进入考核结果阶段  
814 -// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
815 -// "targetUserId": param.TargetUser.UserId,  
816 -// "typesList": []int{int(domain.EvaluationFinish)},  
817 -// "cycleId": param.CycleId,  
818 -// "limit": 1,  
819 -// })  
820 -// if err != nil {  
821 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
822 -// }  
823 -  
824 -// if len(evaluationList) > 0 {  
825 -// //上级评估的结束时间  
826 -// // evaluationList[0].BeginTime = param.EndTime  
827 -// nowTime := time.Now()  
828 -// if evaluationList[0].BeginTime.After(nowTime) {  
829 -// evaluationList[0].BeginTime = nowTime  
830 -// }  
831 -// evaluationList[0].Status = domain.EvaluationCompleted  
832 -// err = evaluationRepo.Save(evaluationList[0])  
833 -// if err != nil {  
834 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())  
835 -// }  
836 -// //TODO 更新考核成绩  
837 -  
838 -// //添加确认绩效成绩提醒短信提醒  
839 -// err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])  
840 -// if err != nil {  
841 -// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())  
842 -// }  
843 -// }  
844 -  
845 -// if err := transactionContext.CommitTransaction(); err != nil {  
846 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
847 -// }  
848 -  
849 -// return nil  
850 -// }  
851 -  
852 // GetTargetUserCycleList 483 // GetTargetUserCycleList
853 // 获取周期列表,被评估的周期列表 484 // 获取周期列表,被评估的周期列表
854 func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.QueryCycleList) (map[string]interface{}, error) { 485 func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.QueryCycleList) (map[string]interface{}, error) {
@@ -1116,76 +747,6 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval @@ -1116,76 +747,6 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
1116 return &result, nil 747 return &result, nil
1117 } 748 }
1118 749
1119 -// getEvaluationSuperDefaultValue  
1120 -// 按照权限设置,是否获取上级评估内容的默认值  
1121 -func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (  
1122 - []*domain.SummaryEvaluationValue, error) {  
1123 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
1124 - "transactionContext": transactionContext,  
1125 - })  
1126 -  
1127 - itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{  
1128 - "transactionContext": transactionContext,  
1129 - })  
1130 -  
1131 - permissionData, err := getPermission(int64(evaluationData.CompanyId))  
1132 - if err != nil {  
1133 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1134 - }  
1135 - if permissionData.OptEvalScore == domain.PermissionOn && permissionData.OptHrScore == domain.PermissionOn {  
1136 - return nil, nil  
1137 - }  
1138 - // 获取360评估,人资评估填写的值  
1139 - _, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{  
1140 - "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},  
1141 - "targetUserId": evaluationData.TargetUser.UserId,  
1142 - "cycleId": evaluationData.CycleId,  
1143 - })  
1144 - if err != nil {  
1145 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1146 - }  
1147 - evaluationIds := []int{}  
1148 - for _, v := range evaluationListOther {  
1149 - evaluationIds = append(evaluationIds, v.Id)  
1150 - }  
1151 - if len(evaluationIds) == 0 {  
1152 - return nil, nil  
1153 - }  
1154 - // 将360评估,人资评估填写的值 作为默认值  
1155 - _, itemValuesOther, err := itemValueRepo.Find(map[string]interface{}{  
1156 - "summaryEvaluationIdList": evaluationIds,  
1157 - })  
1158 - if err != nil {  
1159 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1160 - }  
1161 - // 记录人资评估或者360评估的 填写项id  
1162 - hrbpOr360ItemValue := []*domain.SummaryEvaluationValue{}  
1163 - if permissionData.OptEvalScore == domain.PermissionOff {  
1164 - //上级是否可以修改360°综评分数  
1165 - //获取360综合评分  
1166 - for _, v := range itemValuesOther {  
1167 - //记录人资评估或者360评估的填写值  
1168 - if v.Types != domain.Evaluation360 {  
1169 - continue  
1170 - }  
1171 - hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)  
1172 - }  
1173 - }  
1174 - if permissionData.OptHrScore == domain.PermissionOff {  
1175 - //上级是否可以修改人资综评分数  
1176 - //获取人资综合评分  
1177 - for _, v := range itemValuesOther {  
1178 - //记录人资评估或者360评估的填写值  
1179 - if v.Types != domain.EvaluationHrbp {  
1180 - continue  
1181 - }  
1182 -  
1183 - hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)  
1184 - }  
1185 - }  
1186 - return hrbpOr360ItemValue, nil  
1187 -}  
1188 -  
1189 // 获取执行人的上级评估的列表 750 // 获取执行人的上级评估的列表
1190 func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) { 751 func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
1191 transactionContext, err := factory.CreateTransactionContext(nil) 752 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -1824,8 +1385,6 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited( @@ -1824,8 +1385,6 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
1824 evaluationValueMap[v.Id] = newValue 1385 evaluationValueMap[v.Id] = newValue
1825 evaluationItemMap[v.Id] = v 1386 evaluationItemMap[v.Id] = v
1826 evaluationValueSlice = append(evaluationValueSlice, newValue) 1387 evaluationValueSlice = append(evaluationValueSlice, newValue)
1827 - //重置计数  
1828 - evaluationData.ResetTotalRating(v)  
1829 } 1388 }
1830 //如果存在旧值 1389 //如果存在旧值
1831 //新值的id 替换为旧值id 1390 //新值的id 替换为旧值id
@@ -1858,12 +1417,12 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited( @@ -1858,12 +1417,12 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
1858 } 1417 }
1859 } 1418 }
1860 } 1419 }
  1420 + newItemValue.Remark = v.Remark
1861 //填充评估填写值 1421 //填充评估填写值
1862 - err := newItemValue.FillValue(evaluationItem, v.Value, v.Remark) 1422 + err := evaluationData.FillItemValue(evaluationItem, newItemValue, v.Value)
1863 if err != nil { 1423 if err != nil {
1864 return err 1424 return err
1865 } 1425 }
1866 - // }  
1867 } 1426 }
1868 // 填入固定的默认值 1427 // 填入固定的默认值
1869 for _, v := range defaultItemValue { 1428 for _, v := range defaultItemValue {
@@ -1875,6 +1434,7 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited( @@ -1875,6 +1434,7 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
1875 if !ok { 1434 if !ok {
1876 continue 1435 continue
1877 } 1436 }
  1437 +
1878 //填充评估填写值 1438 //填充评估填写值
1879 err := newItemValue.FillValue(evaluationItem, v.Value, newItemValue.Remark) 1439 err := newItemValue.FillValue(evaluationItem, v.Value, newItemValue.Remark)
1880 if err != nil { 1440 if err != nil {
@@ -335,110 +335,6 @@ func (srv *SummaryEvaluationService) GetEvaluation360Complete(param *command.Que @@ -335,110 +335,6 @@ func (srv *SummaryEvaluationService) GetEvaluation360Complete(param *command.Que
335 return &itemValuesAdapter, nil 335 return &itemValuesAdapter, nil
336 } 336 }
337 337
338 -// EditEvaluation360 编辑提交360综评  
339 -// func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {  
340 -// lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)  
341 -// err := lock.Lock()  
342 -// if err != nil {  
343 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")  
344 -// }  
345 -// defer func() {  
346 -// lock.UnLock()  
347 -// }()  
348 -// transactionContext, err := factory.CreateTransactionContext(nil)  
349 -// if err != nil {  
350 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
351 -// }  
352 -// if err := transactionContext.StartTransaction(); err != nil {  
353 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
354 -// }  
355 -// defer func() {  
356 -// _ = transactionContext.RollbackTransaction()  
357 -// }()  
358 -// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})  
359 -// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})  
360 -// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})  
361 -  
362 -// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})  
363 -// if err != nil {  
364 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
365 -// }  
366 -// if summaryEvaluation.Executor.UserId != param.ExecutorId {  
367 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
368 -// }  
369 -// if summaryEvaluation.CompanyId != param.CompanyId {  
370 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
371 -// }  
372 -  
373 -// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
374 -// "targetUserId": summaryEvaluation.TargetUser.UserId,  
375 -// "typesList": []int{int(domain.EvaluationFinish)},  
376 -// "cycleId": summaryEvaluation.CycleId,  
377 -// "limit": 1,  
378 -// })  
379 -// if err != nil {  
380 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
381 -// }  
382 -// // 如果目标员工已经确认考核结果,就不能在进行评估编辑  
383 -// if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {  
384 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")  
385 -// }  
386 -  
387 -// // 自评评估内容(自评模板、筛选项目评估人)  
388 -// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{  
389 -// "evaluationProjectId": summaryEvaluation.EvaluationProjectId,  
390 -// "nodeType": domain.LinkNodeSelfAssessment,  
391 -// "evaluatorId": param.ExecutorId,  
392 -// })  
393 -// if err != nil {  
394 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
395 -// }  
396 -  
397 -// // 评估内容对应的分数  
398 -// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})  
399 -// if err != nil {  
400 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
401 -// }  
402 -  
403 -// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)  
404 -// if err != nil {  
405 -// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
406 -// }  
407 -// if !param.IsTemporary {  
408 -// //变更评估状态为已填写  
409 -// summaryEvaluation.Status = domain.EvaluationCompleted  
410 -// }  
411 -  
412 -// //保存填写值  
413 -// for _, v := range itemValueList {  
414 -// err = itemValueRepo.Save(v)  
415 -// if err != nil {  
416 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
417 -// }  
418 -// }  
419 -  
420 -// //保存填写值  
421 -// err = evaluationRepo.Save(summaryEvaluation)  
422 -// if err != nil {  
423 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
424 -// }  
425 -// if err := transactionContext.CommitTransaction(); err != nil {  
426 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
427 -// }  
428 -  
429 -// if !param.IsTemporary {  
430 -// err = srv.AfterCompletedEvaluation360Hrbp(summaryEvaluation)  
431 -// if err != nil {  
432 -// return nil, err  
433 -// }  
434 -// }  
435 -  
436 -// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)  
437 -// return map[string][]adapter.EvaluationItemAdapter{  
438 -// "evaluationItems": itemValueAdapter,  
439 -// }, nil  
440 -// }  
441 -  
442 // EvaluationHRBPList 获取人资综评列表 338 // EvaluationHRBPList 获取人资综评列表
443 func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEvaluationHRList) (map[string]interface{}, error) { 339 func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEvaluationHRList) (map[string]interface{}, error) {
444 transactionContext, err := factory.ValidateStartTransaction(param) 340 transactionContext, err := factory.ValidateStartTransaction(param)
@@ -724,145 +620,6 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu @@ -724,145 +620,6 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
724 return &itemValuesAdapter, nil 620 return &itemValuesAdapter, nil
725 } 621 }
726 622
727 -// ModifyFinishScore 修改周期考核的分数  
728 -// func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {  
729 -// transactionContext, err := factory.CreateTransactionContext(nil)  
730 -// if err != nil {  
731 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
732 -// }  
733 -// if err := transactionContext.StartTransaction(); err != nil {  
734 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
735 -// }  
736 -// defer func() {  
737 -// _ = transactionContext.RollbackTransaction()  
738 -// }()  
739 -// // 只有超级管理员可以使用的功能  
740 -// superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)  
741 -// if err != nil {  
742 -// return err  
743 -// }  
744 -// if superAdmin != domain.RoleTypeSuperAdmin {  
745 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
746 -// }  
747 -  
748 -// // 获取周期评估任务finish  
749 -// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})  
750 -// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})  
751 -  
752 -// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{"id": []int{param.SummaryEvaluationId}, "companyId": param.CompanyId})  
753 -// if err != nil {  
754 -// return application.ThrowError(application.BUSINESS_ERROR, err.Error())  
755 -// }  
756 -// if len(evaluationList) == 0 {  
757 -// return nil  
758 -// }  
759 -// result := evaluationList[0]  
760 -// if result.Types != domain.EvaluationFinish {  
761 -// return nil  
762 -// }  
763 -  
764 -// // 获取考核结果评分  
765 -// _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})  
766 -// if err != nil {  
767 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
768 -// }  
769 -// // 如果已经存在考核结果分数,只更新分数(反之先默认生成考核结果,再更新分数)  
770 -// if len(itemValues) > 0 {  
771 -// // do nothing...  
772 -// } else {  
773 -// evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})  
774 -  
775 -// // 周期内所有评估类型  
776 -// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{  
777 -// "companyId": result.CompanyId,  
778 -// "cycleId": result.CycleId,  
779 -// "targetUserId": result.TargetUser.UserId,  
780 -// })  
781 -// if err != nil {  
782 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
783 -// }  
784 -  
785 -// var super *domain.SummaryEvaluation // 上级评估  
786 -// for i := range evaluationList {  
787 -// it := evaluationList[i]  
788 -// if it.Types == domain.EvaluationSuper {  
789 -// super = it  
790 -// break  
791 -// }  
792 -// }  
793 -  
794 -// // 获取自评模板  
795 -// _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})  
796 -// if err != nil {  
797 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
798 -// }  
799 -  
800 -// if super != nil {  
801 -// _, superValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容  
802 -// if err != nil {  
803 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
804 -// }  
805 -// // 更新填写值  
806 -// itemValues, err = srv.updateItemValuePriority(result, itemList, superValues, true)  
807 -// if err != nil {  
808 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
809 -// }  
810 -// } else {  
811 -// // 评估项ID(除考核结果和上级)  
812 -// var evaluationIds = make([]int, 0)  
813 -// for i := range evaluationList {  
814 -// it := evaluationList[i]  
815 -// if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {  
816 -// evaluationIds = append(evaluationIds, it.Id)  
817 -// }  
818 -// }  
819 -// if len(evaluationIds) > 0 {  
820 -// // 已填写的评估内容  
821 -// _, otherValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})  
822 -// if err != nil {  
823 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
824 -// }  
825 -  
826 -// // 更新填写值  
827 -// itemValues, err = srv.updateItemValuePriority(result, itemList, otherValues, false)  
828 -// if err != nil {  
829 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
830 -// }  
831 -// }  
832 -// }  
833 -// err = itemValueRepo.RemoveBySummaryEvaluationId(result.Id)  
834 -// if err != nil {  
835 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
836 -// }  
837 -// for i := range itemValues {  
838 -// if err := itemValueRepo.Save(itemValues[i]); err != nil {  
839 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
840 -// }  
841 -// }  
842 -// // 重置评级汇总  
843 -// result.TotalRating = nil  
844 -// for i := range itemList {  
845 -// result.ResetTotalRating(itemList[i])  
846 -// }  
847 -// //// 计算分数  
848 -// //if err := result.EvaluationTotalScore(itemValues); err != nil {  
849 -// // return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
850 -// //}  
851 -// }  
852 -  
853 -// scoreStr := fmt.Sprintf("%.2f", param.Score)  
854 -// result.TotalScore = scoreStr  
855 -// result.Status = domain.EvaluationCompleted  
856 -// err = evaluationRepo.Save(result)  
857 -// if err != nil {  
858 -// return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())  
859 -// }  
860 -// if err := transactionContext.CommitTransaction(); err != nil {  
861 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
862 -// }  
863 -// return nil  
864 -// }  
865 -  
866 // GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表 623 // GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表
867 func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) { 624 func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) {
868 transactionContext, err := factory.StartTransaction() 625 transactionContext, err := factory.StartTransaction()
@@ -25,6 +25,7 @@ type SummaryEvaluation struct { @@ -25,6 +25,7 @@ type SummaryEvaluation struct {
25 EndTime time.Time `json:"endTime"` //截止时间 25 EndTime time.Time `json:"endTime"` //截止时间
26 TotalScore string `json:"totalScore"` //最终上级评估得分. 26 TotalScore string `json:"totalScore"` //最终上级评估得分.
27 TotalRating []RatingCodeNumber `json:"totalRating"` //汇总各个评级的数量 27 TotalRating []RatingCodeNumber `json:"totalRating"` //汇总各个评级的数量
  28 + Version string `json:"version"` //填写评估值的规则版本 v1,v2
28 CreatedAt time.Time `json:"createdAt"` //数据创建时间 29 CreatedAt time.Time `json:"createdAt"` //数据创建时间
29 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 30 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
30 DeletedAt *time.Time `json:"deletedAt"` //数据删除时间 31 DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
@@ -135,3 +136,23 @@ func (evaluation *SummaryEvaluation) SumRatingCode(code string) { @@ -135,3 +136,23 @@ func (evaluation *SummaryEvaluation) SumRatingCode(code string) {
135 }) 136 })
136 } 137 }
137 } 138 }
  139 +
  140 +// 更新填写的评估值
  141 +func (evaluation *SummaryEvaluation) FillItemValue(item *EvaluationItemUsed, itemValue *SummaryEvaluationValue, value string) error {
  142 + evaluation.ResetTotalRating(item) //重置计数
  143 + //自评
  144 + if evaluation.Types == EvaluationSelf {
  145 + return itemValue.FillValue(item, value, "")
  146 + }
  147 + // 非自评的情况
  148 + // 按照版本使用不同的填写规则
  149 + switch evaluation.Version {
  150 + case "v1":
  151 + itemValue.FillValue(item, value, "")
  152 + case "v2":
  153 + itemValue.FillValueV2(item, value)
  154 + default:
  155 + itemValue.FillValue(item, value, "")
  156 + }
  157 + return nil
  158 +}
@@ -22,6 +22,7 @@ type SummaryEvaluationValue struct { @@ -22,6 +22,7 @@ type SummaryEvaluationValue struct {
22 Rating RatingLevel `json:"rating"` //评级时的填写值 22 Rating RatingLevel `json:"rating"` //评级时的填写值
23 CreatedAt time.Time `json:"createdAt"` //数据创建时间 23 CreatedAt time.Time `json:"createdAt"` //数据创建时间
24 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 24 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
  25 + Version string `json:"version"`
25 } 26 }
26 27
27 type SummaryEvaluationValueRepository interface { 28 type SummaryEvaluationValueRepository interface {
@@ -46,7 +47,7 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua @@ -46,7 +47,7 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua
46 itemValue.Executor = evaluation.Executor 47 itemValue.Executor = evaluation.Executor
47 } 48 }
48 49
49 -// 填充评估的内容 50 +// 自评 填充评估的内容的规则
50 func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error { 51 func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error {
51 itemValue.Remark = remark 52 itemValue.Remark = remark
52 if item.Weight == 0 { 53 if item.Weight == 0 {
@@ -115,3 +116,35 @@ func (itemValue *SummaryEvaluationValue) valueTypeScore(item *EvaluationItemUsed @@ -115,3 +116,35 @@ func (itemValue *SummaryEvaluationValue) valueTypeScore(item *EvaluationItemUsed
115 } 116 }
116 return nil 117 return nil
117 } 118 }
  119 +
  120 +// 360评估,上级评估 ,人资评估 填写评估值的规则
  121 +func (itemValue *SummaryEvaluationValue) FillValueV2(item *EvaluationItemUsed, value string) error {
  122 + value = strings.TrimSpace(value)
  123 + itemValue.Value = value
  124 + //处理空值
  125 + if len(value) == 0 {
  126 + itemValue.Score = "0"
  127 + return nil
  128 + }
  129 + valueNumber, err := strconv.ParseFloat(value, 64)
  130 + if err != nil {
  131 + return fmt.Errorf("条目%d:%s-%s评分值异常", item.Id, item.Category, item.Name)
  132 + }
  133 + if item.Weight <= 0 {
  134 + //无权重的情况
  135 + itemValue.Score = value
  136 + return nil
  137 + }
  138 + // 有权重的情况
  139 + if item.EvaluatorId < 0 {
  140 + //hrbp 的评分方式
  141 + itemValue.Score = value
  142 + return nil
  143 + } else {
  144 + // 非hrbp的评分方式 分值=评分*权重
  145 + // 分数保留2位小数
  146 + score := valueNumber * item.Weight
  147 + itemValue.Score = fmt.Sprintf("%.2f", score)
  148 + }
  149 + return nil
  150 +}
@@ -25,6 +25,7 @@ type SummaryEvaluation struct { @@ -25,6 +25,7 @@ type SummaryEvaluation struct {
25 BeginTime time.Time //开始时间 25 BeginTime time.Time //开始时间
26 EndTime time.Time //截止时间 26 EndTime time.Time //截止时间
27 TotalScore string //最终上级评估得分. 27 TotalScore string //最终上级评估得分.
  28 + Version string //填写评估值的规则版本 v1,v2
28 TotalRating []domain.RatingCodeNumber //汇总评级 29 TotalRating []domain.RatingCodeNumber //汇总评级
29 CreatedAt time.Time //数据创建时间 30 CreatedAt time.Time //数据创建时间
30 UpdatedAt time.Time //数据更新时间 31 UpdatedAt time.Time //数据更新时间
@@ -36,6 +36,7 @@ func (repo *SummaryEvaluationRepository) TransformToDomain(d *models.SummaryEval @@ -36,6 +36,7 @@ func (repo *SummaryEvaluationRepository) TransformToDomain(d *models.SummaryEval
36 Types: domain.EvaluationType(d.Types), 36 Types: domain.EvaluationType(d.Types),
37 Status: domain.EvaluationStatus(d.Status), 37 Status: domain.EvaluationStatus(d.Status),
38 CheckResult: domain.EvaluationCheckResult(d.CheckResult), 38 CheckResult: domain.EvaluationCheckResult(d.CheckResult),
  39 + Version: d.Version,
39 BeginTime: d.BeginTime, 40 BeginTime: d.BeginTime,
40 EndTime: d.EndTime, 41 EndTime: d.EndTime,
41 TotalScore: d.TotalScore, 42 TotalScore: d.TotalScore,
@@ -61,6 +62,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e @@ -61,6 +62,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e
61 Types: int(param.Types), 62 Types: int(param.Types),
62 Status: string(param.Status), 63 Status: string(param.Status),
63 CheckResult: string(param.CheckResult), 64 CheckResult: string(param.CheckResult),
  65 + Version: param.Version,
64 BeginTime: param.BeginTime, 66 BeginTime: param.BeginTime,
65 EndTime: param.EndTime, 67 EndTime: param.EndTime,
66 TotalScore: param.TotalScore, 68 TotalScore: param.TotalScore,
@@ -25,7 +25,7 @@ func init() { @@ -25,7 +25,7 @@ func init() {
25 web.NSCtrlPost("/evaluation-hrAll", (*controllers.SummaryEvaluationController).GetEvaluationHRBPComplete), 25 web.NSCtrlPost("/evaluation-hrAll", (*controllers.SummaryEvaluationController).GetEvaluationHRBPComplete),
26 web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP), 26 web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
27 web.NSCtrlPost("/evaluation-hr/list", (*controllers.SummaryEvaluationController).EvaluationHRBPList), 27 web.NSCtrlPost("/evaluation-hr/list", (*controllers.SummaryEvaluationController).EvaluationHRBPList),
28 - web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel), 28 + // web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
29 web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper), 29 web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper),
30 web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper), 30 web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper),
31 web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSuper), 31 web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSuper),