作者 tangxvhui

调整人资稽查编辑

  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
  9 +)
  10 +
  11 +//人员填写周期评估
  12 +
  13 +// 人资稽查-填写评估内容
  14 +func (srv *SummaryEvaluationService) EditEvaluationByHrCheck(param *command.EditEvaluationValue) (result interface{}, err error) {
  15 + transactionContext, err := factory.CreateTransactionContext(nil)
  16 + if err != nil {
  17 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  18 + }
  19 + if err := transactionContext.StartTransaction(); err != nil {
  20 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 + }
  22 + defer func() {
  23 + _ = transactionContext.RollbackTransaction()
  24 + }()
  25 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  26 + itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  27 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  28 + //根据 SummaryEvaluationId 查找记录
  29 + evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
  30 + "id": param.SummaryEvaluationId,
  31 + })
  32 + if err != nil {
  33 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  34 + }
  35 + if evaluationData.CompanyId != param.CompanyId {
  36 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  37 + }
  38 + //按照被评估人id ,加锁
  39 + lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
  40 + err = lock.Lock()
  41 + if err != nil {
  42 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  43 + }
  44 + defer func() {
  45 + lock.UnLock()
  46 + }()
  47 + // 人员周期对应的所有评估 360 ,人资 ,自评,上级,考核结果
  48 + _, allEvaluationList, err := evaluationRepo.Find(map[string]interface{}{"targetUserId": evaluationData.TargetUser.UserId, "cycleId": evaluationData.CycleId})
  49 + if err != nil {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  51 + }
  52 + // 评估的所有题目
  53 + _, itemUsedList, err := itemUsedRepo.Find(map[string]interface{}{
  54 + "evaluationProjectId": evaluationData.EvaluationProjectId,
  55 + "nodeType": domain.LinkNodeSelfAssessment,
  56 + })
  57 + // 上级评估
  58 + var evaluationSuper *domain.SummaryEvaluation
  59 + // 人资评估
  60 + var evalutionHrbp *domain.SummaryEvaluation
  61 + // 360评估 SummaryEvaluation.Executor.UserId => SummaryEvaluation
  62 + evaluation360Map := map[int]*domain.SummaryEvaluation{}
  63 + for _, val := range allEvaluationList {
  64 + switch val.Types {
  65 + case domain.Evaluation360:
  66 + evaluation360Map[val.Executor.UserId] = val
  67 + case domain.EvaluationSuper:
  68 + evaluationSuper = val
  69 + case domain.EvaluationHrbp:
  70 + evalutionHrbp = val
  71 + }
  72 + }
  73 + // 填写值和填写项id的映射
  74 + itemValueParam := map[int]command.UpdatedItemValue{}
  75 + for _, val := range param.EvaluationItems {
  76 + itemValueParam[val.EvaluationItemId] = val
  77 + }
  78 + //新的上级评估填写值
  79 + newSuperItemValueList := []*domain.SummaryEvaluationValue{}
  80 + //新的人资评估填写值
  81 + newHrbpItemValueList := []*domain.SummaryEvaluationValue{}
  82 + //新的360评估填写值 SummaryEvaluation.Executor.UserId => []*domain.SummaryEvaluationValue
  83 + new360ItemValueList := map[int][]*domain.SummaryEvaluationValue{}
  84 + for _, val := range itemUsedList {
  85 + if evaluationSuper != nil {
  86 + newItemValue := domain.SummaryEvaluationValue{}
  87 + newItemValue.SetBlankValue(evaluationSuper, val)
  88 + newItemValue.Remark = itemValueParam[val.Id].Remark
  89 + evaluationSuper.FillItemValue(val, &newItemValue, itemValueParam[val.Id].Value)
  90 + newSuperItemValueList = append(newSuperItemValueList, &newItemValue)
  91 + }
  92 + if evalutionHrbp != nil && val.EvaluatorId == -1 {
  93 + newItemValue := domain.SummaryEvaluationValue{}
  94 + newItemValue.SetBlankValue(evalutionHrbp, val)
  95 + newItemValue.Remark = itemValueParam[val.Id].Remark
  96 + evaluationSuper.FillItemValue(val, &newItemValue, itemValueParam[val.Id].Value)
  97 + newHrbpItemValueList = append(newHrbpItemValueList, &newItemValue)
  98 + }
  99 + if val.EvaluatorId > 0 {
  100 + evaluation360, ok := evaluation360Map[val.EvaluatorId]
  101 + if ok {
  102 + itemValue360List, ok := new360ItemValueList[evaluation360.Executor.UserId]
  103 + if !ok {
  104 + itemValue360List = make([]*domain.SummaryEvaluationValue, 0)
  105 + }
  106 + newItemValue := domain.SummaryEvaluationValue{}
  107 + newItemValue.SetBlankValue(evaluation360, val)
  108 + newItemValue.Remark = itemValueParam[val.Id].Remark
  109 + evaluationSuper.FillItemValue(val, &newItemValue, itemValueParam[val.Id].Value)
  110 + itemValue360List = append(itemValue360List, &newItemValue)
  111 + new360ItemValueList[evaluation360.Executor.UserId] = itemValue360List
  112 + }
  113 + }
  114 + }
  115 + // 处理上级评估
  116 + if evaluationSuper != nil {
  117 + evaluationSuper.EvaluationTotalScore(newSuperItemValueList)
  118 + //删除旧的填写值,使用新的填写内容
  119 + err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationSuper.Id)
  120 + if err != nil {
  121 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  122 + }
  123 + for _, val := range newSuperItemValueList {
  124 + err = itemValueRepo.Save(val)
  125 + if err != nil {
  126 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  127 + }
  128 + }
  129 + }
  130 + // 处理人资评估
  131 + if evalutionHrbp != nil {
  132 + evalutionHrbp.EvaluationTotalScore(newHrbpItemValueList)
  133 + //删除旧的填写值,使用新的填写内容
  134 + err = itemValueRepo.RemoveBySummaryEvaluationId(evalutionHrbp.Id)
  135 + if err != nil {
  136 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  137 + }
  138 + for _, val := range newHrbpItemValueList {
  139 + err = itemValueRepo.Save(val)
  140 + if err != nil {
  141 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  142 + }
  143 + }
  144 + }
  145 + // 处理360评估
  146 + for key, val := range evaluation360Map {
  147 + val.EvaluationTotalScore(new360ItemValueList[key])
  148 + //删除旧的填写值,使用新的填写内容
  149 + err = itemValueRepo.RemoveBySummaryEvaluationId(val.Id)
  150 + if err != nil {
  151 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  152 + }
  153 + for _, val := range new360ItemValueList[key] {
  154 + err = itemValueRepo.Save(val)
  155 + if err != nil {
  156 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  157 + }
  158 + }
  159 + }
  160 + if err := transactionContext.CommitTransaction(); err != nil {
  161 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  162 + }
  163 +
  164 + return nil, nil
  165 +}
@@ -123,7 +123,7 @@ import ( @@ -123,7 +123,7 @@ import (
123 // }, nil 123 // }, nil
124 // } 124 // }
125 125
126 -// EditEvaluation360 编辑提交360综评 126 +// EditEvaluation360 360评估 编辑提交360综评
127 // 填写规则变更。v2 127 // 填写规则变更。v2
128 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) {
129 transactionContext, err := factory.CreateTransactionContext(nil) 129 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -16,108 +16,108 @@ import ( @@ -16,108 +16,108 @@ import (
16 ) 16 )
17 17
18 // 编辑综合自评详情 18 // 编辑综合自评详情
19 -func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {  
20 - transactionContext, err := factory.CreateTransactionContext(nil)  
21 - if err != nil {  
22 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
23 - }  
24 - if err := transactionContext.StartTransaction(); err != nil {  
25 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
26 - }  
27 - defer func() {  
28 - _ = transactionContext.RollbackTransaction()  
29 - }()  
30 - evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{  
31 - "transactionContext": transactionContext,  
32 - })  
33 - itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{  
34 - "transactionContext": transactionContext,  
35 - }) 19 +// func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
  20 +// transactionContext, err := factory.CreateTransactionContext(nil)
  21 +// if err != nil {
  22 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  23 +// }
  24 +// if err := transactionContext.StartTransaction(); err != nil {
  25 +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  26 +// }
  27 +// defer func() {
  28 +// _ = transactionContext.RollbackTransaction()
  29 +// }()
  30 +// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
  31 +// "transactionContext": transactionContext,
  32 +// })
  33 +// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
  34 +// "transactionContext": transactionContext,
  35 +// })
36 36
37 - itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{  
38 - "transactionContext": transactionContext,  
39 - })  
40 - evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{  
41 - "id": param.SummaryEvaluationId,  
42 - })  
43 - if err != nil {  
44 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())  
45 - }  
46 - if evaluationData.Types != domain.EvaluationSelf {  
47 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
48 - } 37 +// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
  38 +// "transactionContext": transactionContext,
  39 +// })
  40 +// evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
  41 +// "id": param.SummaryEvaluationId,
  42 +// })
  43 +// if err != nil {
  44 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())
  45 +// }
  46 +// if evaluationData.Types != domain.EvaluationSelf {
  47 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  48 +// }
49 49
50 - if evaluationData.Executor.UserId != param.ExecutorId {  
51 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
52 - }  
53 - if evaluationData.CompanyId != param.CompanyId {  
54 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
55 - }  
56 - //按照 被评估人加锁  
57 - lock := xredis.NewLockSummaryEvaluation(evaluationData.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 - _, itemList, err := itemUsedRepo.Find(map[string]interface{}{  
66 - "evaluationProjectId": evaluationData.EvaluationProjectId,  
67 - "nodeType": domain.LinkNodeSelfAssessment,  
68 - })  
69 - if err != nil {  
70 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
71 - }  
72 - _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{  
73 - "summaryEvaluationId": evaluationData.Id,  
74 - }) 50 +// if evaluationData.Executor.UserId != param.ExecutorId {
  51 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  52 +// }
  53 +// if evaluationData.CompanyId != param.CompanyId {
  54 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  55 +// }
  56 +// //按照 被评估人加锁
  57 +// lock := xredis.NewLockSummaryEvaluation(evaluationData.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 +// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
  66 +// "evaluationProjectId": evaluationData.EvaluationProjectId,
  67 +// "nodeType": domain.LinkNodeSelfAssessment,
  68 +// })
  69 +// if err != nil {
  70 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  71 +// }
  72 +// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{
  73 +// "summaryEvaluationId": evaluationData.Id,
  74 +// })
75 75
76 - if err != nil {  
77 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
78 - } 76 +// if err != nil {
  77 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  78 +// }
79 79
80 - err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)  
81 - if err != nil {  
82 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
83 - } 80 +// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
  81 +// if err != nil {
  82 +// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  83 +// }
84 84
85 - if !param.IsTemporary {  
86 - evaluationData.Status = domain.EvaluationCompleted  
87 - //删除旧的填写值,使用新的填写内容  
88 - err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)  
89 - if err != nil {  
90 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
91 - }  
92 - for _, val := range itemValueList {  
93 - val.Id = 0  
94 - }  
95 - }  
96 - err = evaluationRepo.Save(evaluationData)  
97 - if err != nil {  
98 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
99 - }  
100 - //保存填写值  
101 - for _, v := range itemValueList {  
102 - err = itemValueRepo.Save(v)  
103 - if err != nil {  
104 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
105 - }  
106 - }  
107 - if !param.IsTemporary {  
108 - err = srv.AfterCompletedEvaluationSelf(transactionContext, evaluationData, itemValueList)  
109 - if err != nil {  
110 - return nil, err  
111 - }  
112 - }  
113 - if err := transactionContext.CommitTransaction(); err != nil {  
114 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
115 - }  
116 - itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)  
117 - return map[string][]adapter.EvaluationItemAdapter{  
118 - "EvaluationItems": itemValueAdapter,  
119 - }, nil  
120 -} 85 +// if !param.IsTemporary {
  86 +// evaluationData.Status = domain.EvaluationCompleted
  87 +// //删除旧的填写值,使用新的填写内容
  88 +// err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
  89 +// if err != nil {
  90 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  91 +// }
  92 +// for _, val := range itemValueList {
  93 +// val.Id = 0
  94 +// }
  95 +// }
  96 +// err = evaluationRepo.Save(evaluationData)
  97 +// if err != nil {
  98 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  99 +// }
  100 +// //保存填写值
  101 +// for _, v := range itemValueList {
  102 +// err = itemValueRepo.Save(v)
  103 +// if err != nil {
  104 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  105 +// }
  106 +// }
  107 +// if !param.IsTemporary {
  108 +// err = srv.AfterCompletedEvaluationSelf(transactionContext, evaluationData, itemValueList)
  109 +// if err != nil {
  110 +// return nil, err
  111 +// }
  112 +// }
  113 +// if err := transactionContext.CommitTransaction(); err != nil {
  114 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  115 +// }
  116 +// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
  117 +// return map[string][]adapter.EvaluationItemAdapter{
  118 +// "EvaluationItems": itemValueAdapter,
  119 +// }, nil
  120 +// }
121 121
122 // 员工提交自评内容后,员工作为被评估人, 122 // 员工提交自评内容后,员工作为被评估人,
123 // 变更360评估/人资评估/的开始时间 或者变更上级评估的开始时间 123 // 变更360评估/人资评估/的开始时间 或者变更上级评估的开始时间
@@ -344,6 +344,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval @@ -344,6 +344,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
344 "limit": 1, 344 "limit": 1,
345 }) 345 })
346 if err != nil { 346 if err != nil {
  347 + // nil
347 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 348 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
348 } 349 }
349 // 如果目标员工已经确认考核结果,就不能在进行评估编辑 350 // 如果目标员工已经确认考核结果,就不能在进行评估编辑
@@ -27,15 +27,6 @@ func (srv *SummaryEvaluationService) ListEvaluationShow1(param command.QueryEval @@ -27,15 +27,6 @@ func (srv *SummaryEvaluationService) ListEvaluationShow1(param command.QueryEval
27 _ = transactionContext.RollbackTransaction() 27 _ = transactionContext.RollbackTransaction()
28 }() 28 }()
29 29
30 - // // 必须是HRBP权限的人才能编辑操作  
31 - // hrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)  
32 - // if err != nil {  
33 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
34 - // }  
35 - // if hrbp != domain.RoleTypeSystem {  
36 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")  
37 - // }  
38 -  
39 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext}) 30 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
40 staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext}) 31 staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
41 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 32 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
@@ -35,6 +35,7 @@ func (c *SummaryEvaluationController) GetUnconfirmedScoreCycleList() { @@ -35,6 +35,7 @@ func (c *SummaryEvaluationController) GetUnconfirmedScoreCycleList() {
35 c.Response(data, err) 35 c.Response(data, err)
36 } 36 }
37 37
  38 +// 根据周期获取菜单显示
38 func (c *SummaryEvaluationController) GetMenu() { 39 func (c *SummaryEvaluationController) GetMenu() {
39 srv := service.NewSummaryEvaluationService() 40 srv := service.NewSummaryEvaluationService()
40 paramReq := &command.QueryMenu{} 41 paramReq := &command.QueryMenu{}
@@ -82,7 +83,7 @@ func (c *SummaryEvaluationController) EditEvaluationSelf() { @@ -82,7 +83,7 @@ func (c *SummaryEvaluationController) EditEvaluationSelf() {
82 userReq := middlewares.GetUser(c.Ctx) 83 userReq := middlewares.GetUser(c.Ctx)
83 paramReq.CompanyId = int(userReq.CompanyId) 84 paramReq.CompanyId = int(userReq.CompanyId)
84 paramReq.ExecutorId = int(userReq.UserId) 85 paramReq.ExecutorId = int(userReq.UserId)
85 - data, err := srv.EditEvaluationSelf(paramReq) 86 + data, err := srv.EditEvaluationSelfV2(paramReq)
86 c.Response(data, err) 87 c.Response(data, err)
87 88
88 } 89 }