作者 tangxvhui

更新 考核结果的下发

@@ -15,6 +15,7 @@ import ( @@ -15,6 +15,7 @@ import (
15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
16 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 16 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
17 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 17 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
  18 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
18 ) 19 )
19 20
20 type SummaryEvaluationService struct { 21 type SummaryEvaluationService struct {
@@ -596,9 +597,17 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu @@ -596,9 +597,17 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
596 // 员工提交自评内容后, 597 // 员工提交自评内容后,
597 // 员工作为被评估人, 598 // 员工作为被评估人,
598 // 变更360评估/人资评估/的开始时间 599 // 变更360评估/人资评估/的开始时间
599 -// 或者上级评估的开始时间 600 +// 或者变更上级评估的开始时间
600 // 或者生成考核结果 601 // 或者生成考核结果
601 func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error { 602 func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {
  603 + lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
  604 + err := lock.Lock()
  605 + if err != nil {
  606 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  607 + }
  608 + defer func() {
  609 + lock.UnLock()
  610 + }()
602 transactionContext, err := factory.CreateTransactionContext(nil) 611 transactionContext, err := factory.CreateTransactionContext(nil)
603 if err != nil { 612 if err != nil {
604 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 613 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -649,11 +658,32 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain. @@ -649,11 +658,32 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
649 if err != nil { 658 if err != nil {
650 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 659 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
651 } 660 }
652 -  
653 if len(evaluationList) == 0 { 661 if len(evaluationList) == 0 {
654 //没有上级评估、360评估、hrbp 评估 662 //没有上级评估、360评估、hrbp 评估
655 - //直接生成考核结果记录  
656 - // 663 + //直接进入考核结果阶段
  664 + _, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
  665 + "targetUserId": param.TargetUser.UserId,
  666 + "typesList": []int{int(domain.EvaluationFinish)},
  667 + "cycleId": param.CycleId,
  668 + "limit": 1,
  669 + })
  670 + if err != nil {
  671 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  672 + }
  673 + if len(evaluationList) == 0 {
  674 + // 获取考核结果阶段
  675 + finishEvaluation := *param
  676 + finishEvaluation.BeginTime = time.Now()
  677 + finishEvaluation.CreatedAt = time.Now()
  678 + finishEvaluation.UpdatedAt = time.Now()
  679 + finishEvaluation.Executor = domain.StaffDesc{}
  680 + finishEvaluation.Id = 0
  681 + finishEvaluation.Types = domain.EvaluationFinish
  682 + err = evaluationRepo.Save(&finishEvaluation)
  683 + if err != nil {
  684 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
  685 + }
  686 + }
657 } 687 }
658 if err := transactionContext.CommitTransaction(); err != nil { 688 if err := transactionContext.CommitTransaction(); err != nil {
659 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 689 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -661,9 +691,18 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain. @@ -661,9 +691,18 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
661 return nil 691 return nil
662 } 692 }
663 693
664 -// 被评估员工的人资评估 或者 360 评估, 694 +// 提交员工的人资评估 或者 360 评估
665 // 变更上级评估的开始时间 695 // 变更上级评估的开始时间
  696 +// 或者生成考核结果
666 func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error { 697 func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {
  698 + lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
  699 + err := lock.Lock()
  700 + if err != nil {
  701 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  702 + }
  703 + defer func() {
  704 + lock.UnLock()
  705 + }()
667 transactionContext, err := factory.CreateTransactionContext(nil) 706 transactionContext, err := factory.CreateTransactionContext(nil)
668 if err != nil { 707 if err != nil {
669 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 708 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -701,7 +740,7 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma @@ -701,7 +740,7 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
701 "targetUserId": param.TargetUser.UserId, 740 "targetUserId": param.TargetUser.UserId,
702 "typesList": []int{int(domain.EvaluationSuper)}, 741 "typesList": []int{int(domain.EvaluationSuper)},
703 "cycleId": param.CycleId, 742 "cycleId": param.CycleId,
704 - "limit": 1000, 743 + "limit": 10,
705 }) 744 })
706 if err != nil { 745 if err != nil {
707 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 746 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -722,6 +761,91 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma @@ -722,6 +761,91 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
722 if err != nil { 761 if err != nil {
723 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 762 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
724 } 763 }
  764 + if len(evaluationList) == 0 {
  765 + //没有上级评估
  766 + //直接进入考核结果阶段
  767 + _, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
  768 + "targetUserId": param.TargetUser.UserId,
  769 + "typesList": []int{int(domain.EvaluationFinish)},
  770 + "cycleId": param.CycleId,
  771 + "limit": 1,
  772 + })
  773 + if err != nil {
  774 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  775 + }
  776 + if len(evaluationList) == 0 {
  777 + finishEvaluation := *param
  778 + finishEvaluation.BeginTime = time.Now()
  779 + finishEvaluation.CreatedAt = time.Now()
  780 + finishEvaluation.UpdatedAt = time.Now()
  781 + finishEvaluation.Executor = domain.StaffDesc{}
  782 + finishEvaluation.Id = 0
  783 + finishEvaluation.Types = domain.EvaluationFinish
  784 + finishEvaluation.TotalScore = ""
  785 + finishEvaluation.TotalRating = []domain.RatingCodeNumber{}
  786 + err = evaluationRepo.Save(&finishEvaluation)
  787 + if err != nil {
  788 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
  789 + }
  790 + }
  791 + }
  792 + if err := transactionContext.CommitTransaction(); err != nil {
  793 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  794 + }
  795 + return nil
  796 +}
  797 +
  798 +// 员工提交上级评估
  799 +// 生成考核结果
  800 +func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
  801 + lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
  802 + err := lock.Lock()
  803 + if err != nil {
  804 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  805 + }
  806 + defer func() {
  807 + lock.UnLock()
  808 + }()
  809 + transactionContext, err := factory.CreateTransactionContext(nil)
  810 + if err != nil {
  811 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  812 + }
  813 + if err := transactionContext.StartTransaction(); err != nil {
  814 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  815 + }
  816 + defer func() {
  817 + _ = transactionContext.RollbackTransaction()
  818 + }()
  819 +
  820 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
  821 + "transactionContext": transactionContext,
  822 + })
  823 + //没有上级评估
  824 + //直接进入考核结果阶段
  825 + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  826 + "targetUserId": param.TargetUser.UserId,
  827 + "typesList": []int{int(domain.EvaluationFinish)},
  828 + "cycleId": param.CycleId,
  829 + "limit": 1,
  830 + })
  831 + if err != nil {
  832 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  833 + }
  834 + if len(evaluationList) == 0 {
  835 + finishEvaluation := *param
  836 + finishEvaluation.BeginTime = time.Now()
  837 + finishEvaluation.CreatedAt = time.Now()
  838 + finishEvaluation.UpdatedAt = time.Now()
  839 + finishEvaluation.Executor = domain.StaffDesc{}
  840 + finishEvaluation.Id = 0
  841 + finishEvaluation.Types = domain.EvaluationFinish
  842 + finishEvaluation.TotalScore = ""
  843 + finishEvaluation.TotalRating = []domain.RatingCodeNumber{}
  844 + err = evaluationRepo.Save(&finishEvaluation)
  845 + if err != nil {
  846 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
  847 + }
  848 + }
725 if err := transactionContext.CommitTransaction(); err != nil { 849 if err := transactionContext.CommitTransaction(); err != nil {
726 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 850 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
727 } 851 }
@@ -1079,6 +1203,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -1079,6 +1203,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
1079 if err := transactionContext.CommitTransaction(); err != nil { 1203 if err := transactionContext.CommitTransaction(); err != nil {
1080 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1204 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1081 } 1205 }
  1206 +
  1207 + if !param.IsTemporary {
  1208 + err = srv.AfterCompletedEvaluationSuper(evaluationData)
  1209 + if err != nil {
  1210 + return nil, err
  1211 + }
  1212 + }
  1213 +
1082 itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList) 1214 itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
1083 return map[string][]adapter.EvaluationItemAdapter{ 1215 return map[string][]adapter.EvaluationItemAdapter{
1084 "EvaluationItems": itemValueAdapter, 1216 "EvaluationItems": itemValueAdapter,
@@ -42,6 +42,7 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua @@ -42,6 +42,7 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua
42 itemValue.Weight = item.Weight 42 itemValue.Weight = item.Weight
43 itemValue.CreatedAt = time.Now() 43 itemValue.CreatedAt = time.Now()
44 itemValue.UpdatedAt = time.Now() 44 itemValue.UpdatedAt = time.Now()
  45 + itemValue.Executor = evaluation.Executor
45 } 46 }
46 47
47 // 填充评估的内容 48 // 填充评估的内容
@@ -15,6 +15,7 @@ type SummaryEvaluationValue struct { @@ -15,6 +15,7 @@ type SummaryEvaluationValue struct {
15 Value string //评估填写的评分 15 Value string //评估填写的评分
16 Score string //评定得分 16 Score string //评定得分
17 Types int //评估类型 17 Types int //评估类型
  18 + Executor domain.StaffDesc //填写评估的用户,执行人
18 Weight float64 //权重 19 Weight float64 //权重
19 Rating domain.RatingLevel //评级填写值 20 Rating domain.RatingLevel //评级填写值
20 Remark string //填写的内容反馈 21 Remark string //填写的内容反馈
@@ -30,6 +30,7 @@ func (repo *SummaryEvaluationValueRepository) TransformToDomain(d *models.Summar @@ -30,6 +30,7 @@ func (repo *SummaryEvaluationValueRepository) TransformToDomain(d *models.Summar
30 Score: d.Score, 30 Score: d.Score,
31 Types: domain.EvaluationType(d.Types), 31 Types: domain.EvaluationType(d.Types),
32 Remark: d.Remark, 32 Remark: d.Remark,
  33 + Executor: d.Executor,
33 Weight: d.Weight, 34 Weight: d.Weight,
34 Rating: d.Rating, 35 Rating: d.Rating,
35 CreatedAt: d.CreatedAt, 36 CreatedAt: d.CreatedAt,
@@ -45,6 +46,7 @@ func (repo *SummaryEvaluationValueRepository) Save(param *domain.SummaryEvaluati @@ -45,6 +46,7 @@ func (repo *SummaryEvaluationValueRepository) Save(param *domain.SummaryEvaluati
45 Value: param.Value, 46 Value: param.Value,
46 Score: param.Score, 47 Score: param.Score,
47 Types: int(param.Types), 48 Types: int(param.Types),
  49 + Executor: param.Executor,
48 Weight: param.Weight, 50 Weight: param.Weight,
49 Rating: param.Rating, 51 Rating: param.Rating,
50 Remark: param.Remark, 52 Remark: param.Remark,
@@ -10,8 +10,8 @@ type LockSummaryEvaluation struct { @@ -10,8 +10,8 @@ type LockSummaryEvaluation struct {
10 m *redsync.Mutex 10 m *redsync.Mutex
11 } 11 }
12 12
13 -func NewLockSummaryEvaluation(id int) *LockSummaryEvaluation {  
14 - key := fmt.Sprintf("performance:summary_evaluation:%d", id) 13 +func NewLockSummaryEvaluation(targetUserId int) *LockSummaryEvaluation {
  14 + key := fmt.Sprintf("performance:summary_evaluation:%d", targetUserId)
15 15
16 return &LockSummaryEvaluation{ 16 return &LockSummaryEvaluation{
17 m: rsync.NewMutex(key), 17 m: rsync.NewMutex(key),